Gow to set coordinates of a logo to be added with ffmpeg

ffmpeg

I couldn't figure out how to set the coordinates of a logo to be added on a video.

On the Internet I found the following commands:

1) Add logo to the "Bottom left corner"

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

2) Add logo to the "Bottom right corner"

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

Could you please help me understand the overlay settings?

Best Answer

Could you please help me to understand the overlay settings?

The overlay filter takes two arguments: the x and y position of the top left corner of the image.

In this command:

overlay=10:main_h-overlay_h-10

The top left x position is 10, and the top left y position is determined by the “outer” / main image's height main_h and the height of the overlaid image (overlay_h), then additionally subtracting 10 pixels to add a little space from the edge.

If you're unsure what these coordinates mean or how to determine them, perhaps you need to draw them on a sheet of paper.

How to set the height and width of the logo?

You can use the scale filter:

ffmpeg -i inputvideo.mp4 -i watermarklogo.png -filter_complex "\
[1:v]scale=200:100[v1];[0:v][v1]overlay[outv]
\" -map "[outv]" output.mp4

Here, the second input video (1:v) is scaled to 200⨉100 pixels and then labeled as 1v. It's then used in the overlay filter.

How to find the coordinates of the location where to launch the logo? By trying/guessing? Is there a way to find them?

That depends on your application, but generally you need to know your input video size and the size of the logo. FFmpeg cannot guess where to place the logo for you. If you want to place it somewhere in the corner, the given examples should however suffice, assuming that the logo is not too big.

Related Question