ffmpeg error : -vf/-af/-filter and -filter_complex cannot be used together

5

2

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.

cecilli0n

Posted 2014-07-11T14:22:24.047

Reputation: 159

Are you trying to upscale in.avi, logo.png, or the output from the overlay filter? You should use one filtergraph for all of your filtering.

– llogan – 2014-07-11T15:54:49.673

@LordNeckbeard I wish to just upscale in.avi, I tried to move the -vf scale just after in.avi and also just before in the command but it did not work. Going to read about filtergraph now Thanks! – cecilli0n – 2014-07-11T16:24:06.047

@LongNeckbeard filtergraph worked -filter_complex "scale=854:-1,overlay=5:5". If you would like to post that as an answer I will happily mark as accepted. Thanks! – cecilli0n – 2014-07-11T17:49:09.760

Answers

11

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.

llogan

Posted 2014-07-11T14:22:24.047

Reputation: 31 929