96

I am currently using these commands:

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

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

Bottom left corner
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]" outputvideo.flv

Bottom right corner
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=(main_w-overlay_w-10)/2:(main_h-overlay_h-10)/2 [out]" outputvideo.flv

How to place watermark center of the video ?

3
  • 2
    Bottom right corner is infact: ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" outputvideo.flv
    – Hidden
    Commented Aug 20, 2014 at 4:30
  • @mirza Could you please tell me, where have you placed you watemarklogo.png file, as I am getting no such file or directory error
    – B.shruti
    Commented Jan 29, 2021 at 6:07
  • should be in the same directory as you execute the command from. @B.shruti
    – mirza
    Commented Jan 29, 2021 at 12:15

1 Answer 1

243

Examples to add a watermark / logo image on video using the overlay filter.

Centered

enter image description here

ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.mp4

or with the shortened overlay options:

overlay=(W-w)/2:(H-h)/2

Top left

This is the easy one because the default, if you provide no options to overlay, is to place the image in the top left.

This example adds 5 pixels of padding so the image is not touching the edges:

overlay=5:5

Top right

With 5 pixels of padding:

overlay=main_w-overlay_w-5:5

or with the shortened options:

overlay=W-w-5:5

Bottom right

With 5 pixels of padding:

overlay=main_w-overlay_w-5:main_h-overlay_h-5

or with the shortened options:

overlay=W-w-5:H-h-5

Bottom left

With 5 pixels of padding:

overlay=5:main_h-overlay_h

or with the shortened options:

overlay=5:H-h-5

Transparency / opacity / alpha

Example to make watermark 50% transparent using the format and colorchannelmixer filters:

ffmpeg -i input.mp4 -i watermark.jpg -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.5[logo];[0][logo]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p" -c:a copy output.mp4

Improved quality

Using the format=auto option in the overlay filter can make PNG watermarks look better:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=5:H-h-5:format=auto,format=yuv420p" -c:a copy output.mp4

Note the addition of the format filter (yes, same name as the option, but a standalone filter) to reset it to YUV 4:2:0 which is needed for MP4 output. Remove ,format=yuv420p if you are not outputting MP4.

Scale watermark in relation to main video

Use the scale2ref filter:

Example to make logo 10% (1/10) the size of the main video:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5" -c:a copy output.mp4
27
  • 5
    how can we scale the watermark to be 2/3 of the video width and keep the ratio of the watermark can u help please
    – Diaa Saada
    Commented Aug 6, 2015 at 16:27
  • 2
    I'm trying to run this on Android using FFMPEG version n2.4.2 and I get the error message: No such filter: '"overlay', any ideas? Commented Apr 4, 2016 at 19:28
  • 3
    @LordNeckbeard what happened to the donkey picture :D
    – mirza
    Commented Feb 1, 2017 at 10:17
  • 1
    @AarifAli I am unable to help if you do not provide the actual errors.
    – llogan
    Commented Jul 25, 2020 at 19:46
  • 2
    @HashimAziz ffmpeg tries to preserve color data so it will try to use the most "advanced" pixel format supported by the selected encoder for chroma subsampling. Default encoder for MP4 is usually libx264. libx264 supports many pixel formats (see ffmpeg -h encoder=libx264). However, most players can only support the lowest level which is YUV 4:2:0. So the format filter is added in the answer to ensure YUV 4:2:0 chroma subsampling for compatibility.
    – llogan
    Commented Oct 5, 2021 at 16:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.