Linux – FFMPEG: how to add watermark to video


My Platform: Ubuntu 10.10 + FFMPEG 0.5.3(I installed ffmpeg from source)

I try to add Watermark to a .MOV video with FFMPEG 0.5.3 (Please note FFMPEG 0.6+ dont support, so I use ffmpeg 0.5.3)

Here is my code:

ffmpeg -sameq -i -vhook '/usr/local/lib/vhook/ -x 0 -y 0 -i /var/www/files/watermark.png'

Here is the output:

FFmpeg version 0.5.3, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-avfilter --enable-filter=movie --enable-avfilter-lavf
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  built on Jul  3 2011 12:05:08, gcc: 4.4.5

Seems stream 1 codec frame rate differs from container frame rate: 59.94 (5994/100) -> 29.97 (30000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '':
  Duration: 00:03:14.06, start: 0.000000, bitrate: 3350 kb/s
    Stream #0.0(eng): Audio: aac, 48000 Hz, stereo, s16
    Stream #0.1(eng): Video: h264, yuv420p, 1150x647, 29.97 tbr, 29.97 tbn, 59.94 tbc
Output #0, mov, to '':
    Stream #0.0(eng): Video: mpeg4, yuv420p, 1150x647, q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
    Stream #0.1(eng): Audio: 0x0000, 48000 Hz, stereo, s16, 64 kb/s
Stream mapping:
  Stream #0.1 -> #0.0
  Stream #0.0 -> #0.1
Unsupported codec for output stream #0.1

What could be the possible problem? Is that AAC or H264 that is not supported?

I installed libavcodec-extra-52, linfaac, libfaad and etc. but the error is the same.

Do I have to install following this instruction? HOWTO: Install and use the latest FFmpeg and x264 or there is a simpler solution?

Best Answer

The correct way to do this with recent ffmpeg is to use the overlay filter. The following command will place watermark.png on top of input.mp4, with the upper-left corner of the watermark fifteen pixels to the right and ten pixels down from the upper-left corner of the main video:

ffmpeg -i input.mp4 -i watermark.png -filter_complex \
'[0:v][1:v]overlay=15:10[outv]' -map [outv] -map [0:a] \
-c:a copy -c:v libx264 -crf 22 -preset veryfast output.mp4

Obviously, change 15 or 10 to whatever values you want.

There are also a few constants you may find useful, if you're putting watermarks on multiple videos with separate resolutions:

  • W and H are the width and height of the main video (input.mp4)
  • w and h are the width and height of the overlay video (watermark.png)

These can come in handy many times. For example, to place the watermark over the centre of the video, you could use:


Similarly, to centre the watermark over the upper-left sixth of the video:


For the lower-left sixth of the video:


You can pretty much do whatever you need to.

See the overlay filter documentation for more information.