Multiple video filters in FFmpeg

2

I want to add a PNG watermark and then scale my video. I may add more filters. This is my FFmpeg command.

sweb@sweb-laptop:/tmp$ ffmpeg -i Wildlife.wmv -sn -acodec libvorbis -vcodec libvpx -b:a 128k -ar 44100 -b:v 384k -r 25 -vf "movie=/tmp/icon.png [watermark]; [in][watermark] overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2 [out], scale=480:-1" video.webm

… but it gave me an error:

Simple filtergraph 'movie=/tmp/icon.png [watermark]; [in][watermark] overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2 [out], scale=480:-1' does not have exactly one input and output.
Error opening filters!

sweb

Posted 2013-02-05T18:24:53.460

Reputation: 679

Answers

5

[in][watermark] overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2 [out], scale=480:-1"

..has [out] in the wrong place, which renders the filtergraph meaningless. It should be:

[in][watermark] overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2, scale=480:-1[out]"

Personally I dislike the movie filter, for purely aesthetic reasons (I think it makes the command-line look less clear). I would do this using filter_complex instead:

ffmpeg -i Wildlife.wmv -i /tmp/icon.png \
-filter_complex '[0:v][1]overlay=W/2-w/2:H/2-h/2,scale=480:-1[outv]' \
-map [outv] -map 0:a -c:a libvorbis -b:a 128k -c:v libvpx -b:v 384k output.webm

Note that filter_complex is incompatible with [in], since by its nature it takes multiple inputs.

I've removed -ar 44100 and -r 25, since you probably don't need them - if your input source has a frame rate of 25fps and an audio rate of 44100, the output will inherit those settings by default. And if it doesn't, you probably won't gain anything by changing them.


To scale the video first, and then add a watermark, you could use something like this:

-vf 'movie=/tmp/icon.png[wm];[in]scale=480:-1[int];[int][wm]overlay=W/2-w/2:H/2-h/2[out]'

I'm not actually sure if that would work; personally, I'd use filter_complex, as above:

ffmpeg -i Wildlife.wmv -i /tmp/icon.png \
-filter_complex '[0:v]scale=480:-1[int];[int][1]overlay=W/2-w/2:H/2-h/2[outv]' \
-map [outv] -map 0:a -c:a libvorbis -b:a 128k -c:v libvpx -b:v 384k output.webm

evilsoup

Posted 2013-02-05T18:24:53.460

Reputation: 10 085

if i wanna first scale and then add water mark what must i do? [in][watermark] scale=480:-1,overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2[out] did not work. – sweb – 2013-02-05T19:16:42.840

can you aid me to solve it ? – sweb – 2013-02-05T19:24:04.590

1@sweb I've appended instructions on how to do that onto the answer – evilsoup – 2013-02-05T19:44:15.073

ty again for great aid man. – sweb – 2013-02-05T19:50:11.577