FFMPEG:结合使用视频过滤器和复杂过滤器
我正在使用 fluent-ffmpeg
Node.js库对视频文件执行批处理.裁剪16:9输入的视频过滤器,添加填充并将字幕刻录到填充中.
I'm using the fluent-ffmpeg
Node.js library to perform batch manipulations on video files. The video filter which crops a 16:9 input, adds padding and burns subtitles into the padding.
在下一步中,我想使用复杂的滤镜将图像叠加为水印.
In the next step, I would like to use a complex filter to overlay an image as a watermark.
ff.input(video.mp4)
ff.input(watermark.png)
ff.videoFilter([
'crop=in_w-2*150:in_h',
'pad=980:980:x=0:y=0:color=black',
'subtitles=subtitles.ass'
])
ff.complexFilter([
'overlay=0:0'
])
ff.output(output.mp4)
但是,运行此命令时,出现以下错误:
However, running this, I get the following error:
Filtergraph 'crop=in_w-2*150:in_h,pad=980:980:x=0:y=0:color=black,subtitles=subtitles.ass' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a comple.
-vf/-af/-filter and -filter_complex cannot be used together for the same stream.
据我了解,视频过滤器和复杂的过滤器选项不能一起使用.如何解决这个问题?
From what I understand the video filter and complex filter options can't be used together. How does one get around this?
通过学习有关过滤器图的一些基础知识来解决此问题.这是完整的ffmpeg命令.当逐行写出过滤器字符串时,我发现它们更易于阅读.
Solved this by learning some basics about filter graphs. Here's the full ffmpeg command. I find the filter strings easier to read when they are written out line-by-line.
ffmpeg \
-i video.mp4 \
-i watermark.png \
-filter_complex " \
[0]crop = \
w = in_w-2*150 : \
h = in_h \
[a] ;
[a]pad = \
width = 980 : \
height = 980 : \
x = 0 :
y = 0 :
color = black
[b] ;
[b]subtitles =
filename = subtitles.ass
[c] ;
[c][1]overlay = \
x = 0 :
y = 0
" \
output.mp4
说明:
[0] crop = ... [a];
=>首先将裁剪滤镜应用于视频输入 0
.将结果命名为 a
.
[0]crop=...[a];
=> Begin by applying crop filter to video input 0
. Name the result a
.
[a] pad = ... [b];
=>将填充过滤器应用于 a
流.将结果命名为 b
.
[a]pad=...[b];
=> Apply the pad filter to the a
stream. Name the result b
.
[b] subtitles = ... [c]
=>将字幕过滤器应用于 b
流.将结果命名为 c
.
[b]subtitles=...[c]
=> Apply the subtitles filter to the b
stream. Name the result c
.
[c] [1] overlay ...
=>使用输入 1
(png文件)将叠加层滤镜应用于流 c
).
[c][1]overlay...
=> Apply the overlay filter to stream c
using input 1
(the png file).
希望这可以帮助那些在过滤器图表上苦苦挣扎的人.
Hope this helps someone struggling with filter graphs.