FFMPEG Watermark video without vhook solution

So recently ive been playing around with ffmpeg, ive found it quite a useful tool for converting video types, encoding / compressing for online use.

I had quite a challenge on getting it all setup on centos with CPANEL, using the latest SVN versions and libraries.

One of the reasons i went from using an older somewhat functioning version,was that version seemed to fail when converting any avi to flv. Other formats worked fine.

So after upgrading to the latest SVN; and being able to convert avi’s i was nearly floored when i found they removed ffmpeg vhook support for adding watermarks and didnt really leave a viable solution open. Their thought process was to encourage the development of libavfilter and its various filters, they would disable and remove the fucntionality of vhooks in the lead up to Googles Summer of coding – in the hope a solution gets developed.

Currently libavfilter is unfinished and very much undocumented – which from my reading online has impacted many many users.

I searched for days and didnt find a single solution to using libavfilter to overlay the image watermark correctly. I did find a possible vf_logo.c patch that could add some functionality but it needed to be further developed and wasnt a supported patch.

Well i was lucky enough to stumble accross an entry in the SOC conversation  (thankyou google for having the find pages in the last 7 days option). Seems the libavfilter SOC SVN just got a fresh patch to libavfilter overlay that allows it to work.

So i downloaded the libavfilter from the SOC SVN, installed and recompiled FFMPEG from the libavfilter source.


I was then able to issue the command.

ffmpeg -y -i sample.avi -vfilters “movie=0:png:watermark.png [wm];[in][wm] overlay=10:mainH-overlayH-10:1 [out]” -b 100k -ar 44100 -ab 24k -f flv -s 320×240 -acodec libmp3lame -ac 1 samplewithwater.flv

Which converted from AVI to FLV and added my watermark.

ive included a couple of examples below for just adding the watermark.

Example 1 – insert transparent PNG watermark in bottom left corner of the video:
-vfilters “movie=0:png:logo.png [wm];[in][wm] overlay=10:mainH-overlayH-10:1 [out]”

Notice the last parameter to overlay “:1” – this enables alpha blending.

Example 2 – insert 2 different transparent PNG watermarks (second watermark on bottom right corner):
-vfilters “movie=0:png:logo.png [wm];movie=0:png:logo2.png [awm];[in][wm] overlay=10:mainH-overlayH-10:1 [int];[int][awm] overlay=mainW-overlayW-10:mainH-overlayH-10:1 [out]”

You could chain and add more overlays this way but the efficiency of such approach is yet to be tested.

 Feel free to comment, post any tips and tricks or even issues you are having!

Im just happy to now have FFMPEG compiled with the latest SVN Source with libavfilters watermarking solution on a CPANEL centos server!!! and not be using an ancient buggy version. just for reference.

FFmpeg version SVN-r23004, Copyright (c) 2000-2010 the FFmpeg developers

  libavutil     50.15. 0 / 50.15. 0
  libavcodec    52.66. 0 / 52.66. 0
  libavformat   52.62. 0 / 52.62. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.10. 0 /  0.10. 0
aspect           Set the frame aspect ratio.
crop             Crop the input video to x:y:width:height.
drawbox          (null)
fifo             (null)
format           Convert the input video to one of the specified pixel formats.
fps              (null)
hflip            (null)
negate           (null)
noformat         Force libavfilter not to use any of the specified pixel formats for the input to the next filter.
null             Pass the source unchanged to the output.
overlay          Overlay a video source on top of the input.
pad              Add pads to the input image.
pixelaspect      Set the pixel aspect ratio.
rotate           (null)
scale            Scale the input video to width:height size and/or convert the image format.
setpts           (null)
slicify          Pass the images of input video on to next video filter as multiple slices.
split            (null)
transpose        (null)
unsharp          Sharpen or blur the input video.
vflip            Flip the input video vertically.
buffer           (null)
movie            (null)
nullsrc          Null video source, never return images.
nullsink         Do absolutely nothing with the input video.

So in summary, to get watermarks in ffmpeg without using vhooks you need the following

  1. libavfilter from the SOC repository (it has the latest filters) – checkout.sh , install it
  2. compile ffmpeg from the ffmpeg source in the libavfilter you just downloaded.

The libavfilter SVN is – svn://svn.ffmpeg.org/soc/libavfilter

it doesnt seem so complicated anymore oO

Rating: 4.33/5. From 6 votes.
Please wait...

17 thoughts on “FFMPEG Watermark video without vhook solution”

  1. Hi,

    Great article! I followed the same steps as you, but ffmpeg seems not able to read pngs

    How did you do it?


    No votes yet.
    Please wait...
  2. Please, tell me what is your x264 version?
    I cant compile my ffmpeg with x264.

    No votes yet.
    Please wait...
  3. Thanks dear… it really work for me.

    No votes yet.
    Please wait...
  4. ffmpeg is cool. but pain in butt to config/install -vhook etc/ libraries/dependencies
    i like the -vf “hflip” options and -vframe 4 -image2 %d.jpg
    for flipping the frames horizontal and extracting images.

    No votes yet.
    Please wait...
  5. plz tell me how to add watermark in a specific position of a video file……i mean a specific run time like 00:01:00 to 00:03:00 of a 5 minutes video

    No votes yet.
    Please wait...
  6. btw, your article is very helpful ,thanx 4 the share………

    No votes yet.
    Please wait...
  7. won’t work for me:
    Unable to find a suitable output format for ‘[wm]’
    -jailshell: [in][wm]: command not found

    can you help me?
    thanks a lot

    No votes yet.
    Please wait...
  8. Regrettably the latest libavfilter checkout ffmpeg does not support the configure option of –enable-avfilter-lavf, which from all reading suggests that the method above cannot work with the latest code – bugger!

    So I am reverting to 0.5 ffmpeg as I’d rather ffmpeg to take care of all the processing rather than hook in transcode or similar etc.

    Any ideas on eta re: watermarking with 0.6 ffmpeg???

    No votes yet.
    Please wait...
  9. I AM INCORRECT ABOVE SORRY – You don’t need the –enable-avfilter-lavf options & the movie option will work. I did have an issue with the dimension values but I can hard code these!
    So very happy now!

    No votes yet.
    Please wait...
  10. Thanks for the very useful tip, the only comment – with the recent ffmpeg (r25741), use -vf instead of -vfilters.

    No votes yet.
    Please wait...
  11. I keep getting

    [movie @ 0x302fb00] movie_init() Failed to av_open_input_file ‘logo.png’
    Error initializing filter ‘movie’ with args ‘0:png:logo.png’

    when trying to test this out. anyone have a fix?

    No votes yet.
    Please wait...
  12. Hey, Thanks a million for this! Saved me a bunch of time and (finally) able to watermark videos again!

    If anybody getting a vfilters not recognized option, try -vf instead of -vfilters in the command line!

    No votes yet.
    Please wait...
  13. Hello!

    Watermark etc works fine, I have latest SVN & stuff installed.
    How ever, if I convert avi files to h264/aac mp4 and try to play (from stream) it on Android tablet (MID 1.1) replay looks like a diashow and sound
    & video are out of sync. Playing from PC (mplayer/vlc)
    everything looks normal and audio&video are in sync.

    If I compile latest SVN ffmpeg without patched libavfilter
    videos are working also in Android tablet and other mobile

    I stream mp4s thru Wowza streaming server to a mobile

    No votes yet.
    Please wait...
  14. I wanted to watermark my movies in the bottom-right corner, and eventually found there’s a new syntax to the filter. It should go thus :

    -vf “movie=image.png:f=png [img]; [in] [img] overlay=W-w-10:H-h-10:1 [movie]; [movie] setdar=16:9”

    Try this if you keep getting errors. Keep in mind though it won’t work for just any FFmpeg version.

    No votes yet.
    Please wait...
  15. Hey – great article.

    I tried following along with latest but couldn’t get it to work on my Windows environment. Do you happen to have a windows binary already working with png alpha transparency overlay that you could send along? (or put in a safe place to download)?

    – Mike

    No votes yet.
    Please wait...
  16. I would love a Windows binary version of this as well. If someone has it, please send to noahsw AT gmail.com.

    Thanks in advance!

    No votes yet.
    Please wait...
  17. The vhook option is deprecated in new releases.

    No votes yet.
    Please wait...

Leave a Comment

Your email address will not be published. Required fields are marked *