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?
-vf is used for simple filtergraphs (one input, one output), and -filter_complex is used for complex filtergraphs (one or more inputs, one or more outputs). Using -filter_complex will allow you omit the movie multimedia source filter and have a shorter command.
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
Explanation:
[0]crop=...[a];
=> Begin by applying crop filter to video input 0
. Name the result a
.
[a]pad=...[b];
=> Apply the pad filter to the a
stream. Name the result b
.
[b]subtitles=...[c]
=> Apply the subtitles filter to the b
stream. Name the result 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With