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.
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.
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]