ffmpeg error : -vf/-af/-filter and -filter_complex cannot be used together
I am trying to run the following cmd, which should add a watermark to the video and also upscale it.
ffmpeg -i "in.avi" -i "\logo.png" -vf scale=854:-1 -preset
veryfast -crf 20 -filter_complex overlay=5:5 "ou.mkv"
I receive the following error.
Filtergraph 'scale=854:-1' was specified through the
-vf/-af/-filter option for output stream 0:0, which is fed from
a complex filtergraph. -vf/-af/-filter and -filter_complex
cannot be used together for the same stream.
Before I tried to upscale (without the -vf scale=854:-1) the cmd worked to watermark.
How can I acheive both?
What I have tried?
- Moving the -vf parameter before the input, after the input etc.
You can use one filtergraph to do all filtering:
ffmpeg -i input.avi -i logo.png -filter_complex \
"[0:v]scale=854:-2[scaled]; \
[scaled][1:v]overlay=5:5[out]" \
-map "[out]" -map 0:a -c:v libx264 -c:a copy output.mkv
[0:v]
refers to the video stream(s) of the first input (input.avi
in this example).[1:v]
is the video from the second input (logo.png
in this example).Audio is steam copied in this example instead of being re-encoded; assuming your first input has audio.
Best practice is to manually name the filter input and outputs, such as in this example, instead of relying on defaults which may result in improper stream selections.
-2
in the scale video filter is used instead of-1
because x264 requires the output to be divisible by 2 when outputting to 4:2:0 chroma subsampling:
If one of the values is -n with n > 1, the scale filter will also use a value that maintains the aspect ratio of the input image, calculated from the other specified dimension. After that it will, however, make sure that the calculated dimension is divisible by n and adjust the value if necessary.