94

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 ?

one noa
  • 345
  • 1
  • 3
  • 10
mirza
  • 5,685
  • 10
  • 43
  • 73
  • 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 – Sebastian Patten Aug 20 '14 at 04: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 Jan 29 '21 at 06:07
  • should be in the same directory as you execute the command from. @B.shruti – mirza Jan 29 '21 at 12:15

1 Answers1

237

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
llogan
  • 121,796
  • 28
  • 232
  • 243
  • @HarishKumar Replace flv with mp4. – llogan Jan 05 '15 at 18:42
  • i have tried replacing flv to .mp4 but that didn't worked for me – Harish Kumar Jan 06 '15 at 06:00
  • .mp4 files have a restricted set of allowed codecs and profiles. Please make sure that you are requesting a the correct combination of stream codecs and codec parameters to produce a valid result. – Michael J. Evans Mar 26 '15 at 07:48
  • 4
    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 Aug 06 '15 at 16:27
  • I did http://superuser.com/questions/951879/how-scale-and-center-watermark-on-video-using-ffmpeg – Diaa Saada Aug 06 '15 at 17:25
  • 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? – The Hungry Androider Apr 04 '16 at 19:28
  • @LordNeckbeard i am trying this command with 10 sec video and it takes about five mins and with preset ultrafast it takes 1 min. – Developer Sep 27 '16 at 10:56
  • @SyedJoharHussain You need to provide your full command and the complete console output. You can dump it to a pastebin site and provide a link here. – llogan Sep 27 '16 at 16:34
  • @LordNeckbeard [Here](http://pastebin.com/N8WBxacR) is my command and logs. Original video info: size**20 MB**, Resolution **1080x1920**. – Developer Sep 28 '16 at 05:43
  • @SyedJoharHussain From your output: `using cpu capabilities: none!` It should have something like `ARMv7 NEON`. You should investigate why x264 was compiled with no cpu capabilities. Otherwise you can downscale which should be faster to encoder. – llogan Sep 28 '16 at 06:21
  • 3
    @LordNeckbeard what happened to the donkey picture :D – mirza Feb 01 '17 at 10:17
  • @motto Good memory, but I thought I should replace it with an example that has transparency (alpha channel). Maybe someday I'll replace the log with a new donkey that has an alpha channel. – llogan Feb 01 '17 at 17:45
  • I found No such filter: " invalid argument in android. anyone have idea for same ? – Chintan Khetiya Mar 01 '17 at 10:38
  • @ChintanKhetiya Probably a quoting or escaping issue which is very common with Android users. Use a pastebin site to show your full `ffmpeg` command and the complete console output then provide the link in a comment. – llogan Mar 01 '17 at 18:39
  • For others, to reduce opacity of my overlay watermark, I just edited the .png, reduced it to 50% opacity, re-saved it as a .png and used that. Worked great – Joshua Pinter Nov 15 '17 at 06:11
  • @LordNeckbeard I noticed you are an expert for `FFmpeg` library I have an issue with trying run command for creating watermark in Android. I'm really beginner in using `FFmpeg` could you take a look maybe you could know what I'm doing wrong: https://stackoverflow.com/questions/50529513/command-for-putting-watermark-on-video Thanks anyway. – Yupi May 25 '18 at 23:17
  • @Yupi I'll take a look but I know nothing about Android or any of these wrapper things. – llogan May 25 '18 at 23:46
  • // String cmd = "-y -i " + iPath +" -c copy -map 0 -movflags faststart "+oPath; // String cmd = "-y -i "+ iPath + " -i "+lPath+ " -filter_complex overlay=W-w-5:H-h-5 -codec:a copy -preset faststart -async 1 "+oPath; // String cmd = "ffmpeg -i birds.mp4 -i watermark.png -filter_complex "overlay=10:10"; // String cmd = "-i "+iPath+" -i "+lPath+" -filter_complex overlay=10:10 "+oPath; i will try all command but not work – Aarif Ali Jul 25 '20 at 11:43
  • 1
    @AarifAli I am unable to help if you do not provide the actual errors. – llogan Jul 25 '20 at 19:46
  • @llogan Finally i was found a alternate solution. – Aarif Ali Jul 26 '20 at 12:21
  • Not really related to the question, but what's the reason that `format=yuv420p` is needed for MP4? I can't say I've noticed anything leaving it out, but maybe that's because I wasn't even aware of what to look for. – Hashim Aziz Oct 05 '21 at 15:59
  • 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 Oct 05 '21 at 16:03
  • Me again, thanks for a great answer that I find myself constantly coming back to on the topic of watermark overlays. A clarification on overlay transparency/opacity: I've been using a simpler filter to do this in the form of `lut=a=val*0.5` without needing to set the alpha channel separately with `format` - how does this compare quality-wise to the `colorchannelmixer` solution you outlined? Are they equivalent or are there particular pros/cons for each? – Hashim Aziz Oct 16 '21 at 02:20
  • 1
    @HashimAziz Your input must already have alpha if you didn't need the format filter. With the format filter and a JPG to be overlaid, visually the results of colorchannelmixer vs lut look the same to me. lut was significantly faster (and you don't have to type as much). There are so many filters that often there are multiple methods. You'll have to take a look at the source code for each filter (`libavfilter/vf_lut.c` for example) for more than my lazy observations. – llogan Oct 16 '21 at 16:49
  • @llogan That's more than enough for me, thank you. If you get the time I'd appreciate your input to [this question](https://superuser.com/questions/1682093/automating-fade-in-out-for-watermark-overlay). – Hashim Aziz Oct 16 '21 at 16:51
  • For anyone having problems with 'No such filter: Overlay' - removing the quotation marks idd indeed fix it for me when using ffmpegWASM - i.e. this worked: await ffmpeg.run('-i', 'videoInputFile', '-i', 'imageFileInput', '-filter_complex', 'overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2', '-codec:a', 'copy', 'outputVideo.mp4'); – Mick Jan 07 '23 at 22:11