I have an ffmpeg command using -vf to deinterlace videos and produce pixel format with 4:2:0 chroma subsampling:

ffmpeg -i input.mp4 -vf yadif,format=yuv420p \ 
-force_key_frames expr:gte(t\,n_forced/2) \
-c:v libx264 -crf 23 output.mp4

Also I have another ffmpeg command to put on my watermark:

ffmpeg -i input.mp4 -i logo.png \
-filter_complex "[1][0]scale2ref=iw/5:ow*450/450[wm][vid];[vid][wm]overlay=W-w-W*3/100:H-h-H*1/100:enable='gt(t,30)'" \
-c:v libx264 -crf 23 output.mp4

I tried to put them together and got this error:

-vf/-af/-filter and -filter_complex cannot be used together for the same stream

I read that -filter_complex can be used for simple filters, and we can chain the filters together, separated by commas, so I created a new command without -vf:

ffmpeg -i input.mp4 -i logo.png \
filter_complex "[1][0]scale2ref=iw/5:ow*450/450[wm][vid];[vid][wm]overlay=W-w-W*3/100:H-h-H*1/100:enable='gt(t,30)',yadif,format=yuv420p" -force_key_frames expr:gte(t\,n_forced/2) -c:v libx264 -crf 23 output.mp4

Is this the right way to combine these two filters?

The console doesn't show the above error but a new error:

Missing ')' or too many args in 'gte(t\,n_forced/2)'
Invalid force_key_frames expression 'gte(t\,n_forced/2)'
Error initializing output stream 0:0 --
[aac @ 0000022fbe6eacc0] Qavg: 118.000
[aac @ 0000022fbe6eacc0] 2 frames left in the queue on closing
Conversion failed!

Please help!

  • The working answer has been posted below! – David Tran Dec 13 '19 at 6:08


ffmpeg -i input.mp4 -i logo.png \
-filter_complex "[0]yadif,format=yuv420p[main];[1][main]scale2ref=iw/5:ow*450/450[wm][vid];[vid][wm]overlay=W-w-W*3/100:H-h-H*1/100:enable='gt(t,30)'" \
-force_key_frames "expr:gte(t,n_forced/2)" -c:v libx264 -crf 23 -c:a copy output.mp4
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.