Watermark Video in FFMPEG without vhook

It has always been that with ffmpeg, if you want to watermark a video, you needed vhook. vhook as we all know is old and not very useful to windows users and in the newer ffmpeg builds has been replaced with video filters, or –vf.

One of the filters in the new –vf format is a watermark filter, allowing you to watermark your videos during the transcoding procedure.

An example would be: –vf “overlay:10:10” which would tell the overlay to position 10 pixels from the top of the main video, and 10 pixels from the left.

But what if we want to position from the right? Or from the bottom? Or centre the overlay? This is where main_w (main video width), main_h (main video height), overlay_w (overlay video width) and overlay_h  (overlay video height) comes in. You can use these variables to represent the certain set sizes of the video and the overlay.

So what if we wanted to position 10 pixels from the right and 10 pixels from the bottom? We would the use: –vf “overlay:main_w-overlay_w-10:main_h-overlay_h-10”.

So how do we specify the overlay? What we do is use the “movie” video filter which would take our png or jpg and convert that into a movie which is then overlaid on top of our existing movie.

See example below:

ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" outputvideo.flv

Or if you are planing to use your video with a newer version of flash that supports h264 encoded videos, you could use:

ffmpeg.exe -i input.avi -sameq -vcodec libx264 -acodec libfaac -vf "movie=logo.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:main_h-overlay_h-10 [out]" -threads 0 "output-slow.mp4"

qt-faststart.exe output-slow.mp4 output-fast.mp4

Thus giving you a watermarked MPEG4 h264 + AAC file capable of streaming with a flash player.

Write a comment