Finally, something actually useful on this blog……
If you need to apply a watermark, or Digital Onscreen Graphic (DOG), to a file during the transcode process, the only way to currently achieve this with FFmpeg is to use the vhook watermark.c filter. Unfortunately, vhooks no longer work with the latest SVN snapshots of FFmpeg, as everyone is supposed to be writing new filters for the AVFilter framework.
Unfortunately, again, there’s not always time to write brand new filters in C from scratch. Sometimes, a quicker solution is required. At the major UK media content distribution company that I work for, we needed to transcode approximately 5,000 VC-1 5Mbps files to 2-pass H.264 at 1.5Mbps and 500kbps, within 6 weeks. We decided to find all the spare PCs we could get out hands on, install Debian Lenny and FFmpeg, then start transcoding. However, we also needed to apply a DOG to each and every file. How to do this with FFmpeg….. use the watermark.c vhook, which fortunately does still work with the 0.5 release of FFmpeg. Great news. Well, almost.
To achieve a really nice looking DOG, we wanted to use a PNG file with Alpha Channels. The existing watermark.c code did not support this. Therefore, we’ve written a patch.
This patch means watermark.c now obeys the alpha channel in a PNG file. The -m option is the mode, this must be 2 for alpha blending. The watermark image is applied to the input video and then scaled with the input video to the output video’s dimensions. So best to make an image the same dimensions as the input video, otherwise you’ll get horrible scaling effects.
ffmpeg … -vhook ‘/usr/local/lib/vhook/watermark.so -m 2 path/to/image.png’ …
(replace /usr/local/lib/vhook with wherever your watermark.so is.)
Patch is available here – watermark.patch
(Maybe see links below for files on Github instead)
Example screen grab: View image
We’ve also posted back to the FFmpeg Devel mailing list.
Actual credit for this patch goes to my colleague Tim MacFarlane - http://refractalize.blogspot.com/
Tim has also now added the files to Github:
Just the patch here.
The whole of watermark.c with patch applied here.