Multiple video filters in FFmpeg

8,379
[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
Share:
8,379

Related videos on Youtube

Happy
Author by

Happy

Updated on September 18, 2022

Comments

  • Happy
    Happy almost 2 years

    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!
    
  • Happy
    Happy over 11 years
    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.
  • Happy
    Happy over 11 years
    can you aid me to solve it ?
  • evilsoup
    evilsoup over 11 years
    @sweb I've appended instructions on how to do that onto the answer
  • Happy
    Happy over 11 years
    ty again for great aid man.