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.
(NOTE the FFMPEG SVN DOESNT HAVE THE LATEST FILES AND SUPPORT FOR THE LATEST LIBAVFILTER – YOU NEED TO DOWNLOAD THE INCLUDED FFMPEG FROM THE LIBAVFILTER SOC SVN AND COMPILE FROM THAT)
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.
format Convert the input video to one of the specified pixel formats.
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.
scale Scale the input video to width:height size and/or convert the image format.
slicify Pass the images of input video on to next video filter as multiple slices.
unsharp Sharpen or blur the input video.
vflip Flip the input video vertically.
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
- libavfilter from the SOC repository (it has the latest filters) – checkout.sh , install it
- 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