Using FFmpeg to add and watermark / overlay on a video - Corbell Consulting, LLC


: 3

By on Jul 22, 2010 in Corbell Consulting, News | 6 comments

Since moving to version 0.6 in June 2010 vhooks are no longer available in FFmpeg. It seems like a lot of people are having trouble getting watermarks working properly with the new libavfilter method. I’ll lay out here the steps that I took to get it working properly on Mac OS X. I’ve tested this on 10.6.4 and 10.5.8 with great results.

First off, there are a number of add-ons you’ll likely want to load. For each of these just download the latest source. I was able to simply run ./configure, make, make install for each of these with no hiccups.

I’d recommend that you start by creating a folder in your home directory called Source. Uncompress all of these to that Source folder and keep all your work in there.

yasm (
faac (
lame (
x264 (

If you’re going to be dealing with ProRes files, you can use these qt_tools to convert them to a format that FFmpeg can work with. Worth downloading and installing.

qt_tools (

Finally, you’ll want to get the latest version of libavfilter. Open the Terminal and cd into your Source directory.

svn co svn://

Next, cd into libavfilter and run

Then, cd into the ffmpeg directory and run ./configure to prepare your build. On Leopard I used this command:

./configure --enable-avfilter --enable-libmp3lame --enable-shared --disable-mmx \
 --arch=x86_32 --enable-libfaac --enable-nonfree --enable-filter=movie --enable-avfilter-lavf \
 --enable-libx264 --enable-gpl

On Snow Leoapard I ran this. The only difference being 64 bit support:

./configure --enable-avfilter --enable-libmp3lame --enable-shared --disable-mmx \
--arch=x86_64 --enable-libfaac --enable-nonfree --enable-filter=movie --enable-avfilter-lavf \
--enable-libx264 --enable-gpl

Assuming you are still error-free, you can now run `make` and when that finishes, `make install`.

Whew, the scary stuff is done. Now you have qt_tools which will let you get out of ProRes format and the latest greatest version of FFmpeg with support for AAC audio, MP3 Audio, h.264 video encoding and watermarking.

To use qt_export you have to create a settings file which it will use to decode your video. In the terminal type `qt_export –dodialog –savesettings=mySettings.qts` This will open the Quicktime export dialog box. You can go ahead and select all the settings you want to use. When you click OK it will create a file called mySettings.qts or whatever you put in the terminal command. You only have to do this once. The next command is what you use to process a video file.

qt_export --loadsettings=mySettings.qts

So that will take, convert it to whatever settings you saved in the mySettings.qts file and spit out

Finally, this command is what you use to overlay your watermark. In this example, the watermark file is the same frame size as the video. I’m using a PNG file with transparency. You’ll want to go through and setup your ffmpeg parameters for whatever your application may be. I’m outputting a 15Mbit MP4 file, 720p with 256kbit AAC audio.

ffmpeg -i -f mp4  -b 15M -acodec libfaac -ab 256k  \
-vf "movie=0:png:preview.png [wm];[in][wm] overlay=0:0:1 [out]" out.mp4

That should do it!

Here’s a sample video I encoded using the following command. It’s a nice, crappy, very compressed file.

ffmpeg -i -s 640x360 -f mp4  -b 800k -acodec libfaac \
-ab 64k  -vf "movie=0:png:watermark-half.png [wm];[in][wm] overlay=0:0:1 [out]" out.mp4

[qt: 640 360]