Using FFmpeg to add and watermark / overlay on a video

Using FFmpeg to add and watermark / overlay on a video

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 (http://www.tortall.net/projects/yasm/wiki/Download)
faac (http://www.audiocoding.com/)
lame (http://lame.sourceforge.net/download.php)
x264 (http://www.videolan.org/developers/x264.html)

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 (http://www.omino.com/sw/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://svn.ffmpeg.org/soc/libavfilter

Next, cd into libavfilter and run checkout.sh

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 input.mov video.mov

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

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 video.mov -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 video.mov -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:http://www.corbellconsulting.com/wp-content/uploads/2010/07/out.mp4 640 360]

6 Comments

  1. Did they remove a bunch of the filters from libavfilter? movie and overlay don’t seem to be included anymore… I am on FFmpeg version SVN-r24735 and keep getting ‘”No such filter: ‘movie'” when running movie=0:png:preview.png [wm];[in][wm] overlay=0:0:1 [out]

  2. Cameron: Make sure to build ffmpeg with –enable-movie.

  3. Eh – actually:

    The ffmpeg change log says the following — so I guess this whole how-to isn’t right. :-)

    commit 2268cf99feee1c1af824204ea55434f80e8c4c51
    Author: stefano
    Date: Wed Jul 28 08:56:49 2010 +0000

    Remove reference to the unexisting movie filter and the corresponding
    useless –enable-avfilter-lavf option.

    git-svn-id: file:///var/local/repositories/ffmpeg/trunk@24569 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

  4. Thanks for posting this up! It was a huge help, especially since there’s not a ton of info on libavfilter out there, and especially not from an OS X standpoint.

    I used the latest SVN for libavfilter, x264, and ffmpeg. The only thing I had to change from your instructions was to remove the “-lavf” from the “–enable-avfilter-lavf” build parameter. Not sure what the difference is, but the overlay filter seems to work regardless.

    Thanks again!

  5. FYI. On the most recent version of OSX 10.6.5 and the latest version of Xcode along with XCode 4 you will need to run this before you configure…

    export CFLAGS=”-arch x86_64 -Wconversion -Wformat -Wshorten-64-to-32 -mmacosx-version-min=10.5″

    After a week of banging my head against a brick wall I managed to compile it succesfully

  6. How about a Windows binary with the watermarking? If someone has it, please send me a link at noahsw AT gmail.com.

    Thanks in advance!

Trackbacks/Pingbacks

  1. Need Step By Step Tutorial For FFMPEG Hardcoded Watermark - BuyScripts Forums - [...] below.... **FIRST BACKUP YOUR FILES** install FFmpeg 0.6 ( I used Google and found this site Using …

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>