Center Image Watermark on Video Using FFmpeg

This article provides a quick, step-by-step guide on how to position an image watermark precisely in the center of a video using FFmpeg’s overlay filter. You will learn the exact command-line syntax and the mathematical formulas required to achieve a perfectly centered overlay, regardless of the video or image resolution.

To place an image watermark in the exact center of a video, you must calculate the horizontal and vertical offset by subtracting the watermark’s dimensions from the video’s dimensions and dividing the result by two.

The FFmpeg Command

Use the following basic command structure to center your watermark:

ffmpeg -i input_video.mp4 -i watermark.png -filter_complex "overlay=(W-w)/2:(H-h)/2" output_video.mp4

How the Formula Works

The overlay filter uses specific variables to calculate the positioning coordinates (x and y):

By setting x=(W-w)/2, FFmpeg subtracts the watermark’s width from the video’s width and halves the remaining space, centering the image horizontally.

By setting y=(H-h)/2, FFmpeg does the same with the heights, centering the image vertically.

Handling Video Encoding Options

To ensure high-quality output and fast encoding, you can specify a video codec (like H.264) and audio copy settings:

ffmpeg -i input_video.mp4 -i watermark.png -filter_complex "overlay=(W-w)/2:(H-h)/2" -c:v libx264 -crf 23 -c:a copy output_video.mp4