How to add a transparent watermark to the center of a video using ffmpeg?

I am currently using the following 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 the center of the video watermark?

+51
ffmpeg
Jun 06 '12 at 17:12
source share
1 answer

Video overlay / watermark examples:

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 reduced overlay options:

 overlay=(Ww)/2:(Hh)/2 

Top left

This is not easy, because by default, if you do not provide any options for overlaying, you need to place the image in the upper left corner.

This example adds 5 pixels of padding, so the image does not touch the edges:

 overlay=5:5 

In the upper right corner

With 5 fill pixels:

 overlay=main_w-overlay_w-5:5 

or with abbreviated parameters:

 overlay=Ww-5:5 

Bottom right

With 5 fill pixels:

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

or with abbreviated parameters:

 overlay=Ww-5:Hh-5 

Bottom left

With 5 fill pixels:

 overlay=5:main_h-overlay_h 

or with abbreviated parameters:

 overlay=5:Hh-5 



Notes

  • The sound is simply stream copied (remixed) in this example with -codec:a copy instead of re-encoding. You may need to transcode depending on the format of your output container.

  • See the overlay documentation for more details and examples.

  • For more information on getting good quality, see the FFmpeg H.264 Video Encoding Guide .

  • If your image overlays, it is an RGB color space (for example, most PNG images), you can see the visual improvement by adding format=rbg to your overlay. Please note that if you do this and if you output H.264, you will need to add format=yuv420p (this is another file filter - another that is similarly named parameter in the overlay filter). It might look like this:

     overlay=5:Hh-5:format=rgb,format=yuv420p 
+102
Jun 06 '12 at 19:29
source share



All Articles