Overlay a Logo onto a Video with FFmpeg

This article provides a quick overview and step-by-step guide on how to overlay an image logo onto a video file using FFmpeg on Linux. You will learn the core command structure, how to position the logo in different corners of the video using predefined variables, and how to adjust the logo’s size. By the end of this guide, you will be able to apply a professional watermark to your videos directly from the command line.

The Basic Command Structure

To overlay an image onto a video, FFmpeg uses the overlay video filter. This filter takes two inputs: the main video (the background) and the image logo (the foreground).

Here is the foundational command to place a logo in the top-left corner:

ffmpeg -i input_video.mp4 -i logo.png -filter_complex "overlay=0:0" output_video.mp4

Advanced Positioning Using Variables

Hardcoding pixel values can be inefficient if you want to place the logo in other corners. Fortunately, FFmpeg provides built-in variables to calculate positions dynamically based on the dimensions of the video and the logo:

Using these variables, you can position your logo anywhere while adding a 10-pixel padding from the edges:

ffmpeg -i input_video.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-10:10" output_video.mp4
ffmpeg -i input_video.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-10:main_h-overlay_h-10" output_video.mp4
ffmpeg -i input_video.mp4 -i logo.png -filter_complex "overlay=10:main_h-overlay_h-10" output_video.mp4
ffmpeg -i input_video.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" output_video.mp4

Resizing the Logo on the Fly

If your logo image is too large for the video resolution, you can scale it down within the same command before overlaying it. This requires chaining the scale filter and the overlay filter together:

ffmpeg -i input_video.mp4 -i logo.png -filter_complex "[1:v]scale=200:-1[logo];[0:v][logo]overlay=main_w-overlay_w-10:main_h-overlay_h-10" output_video.mp4

In this command, [1:v]scale=200:-1[logo] takes the second input (the logo), resizes its width to 200 pixels, and automatically calculates the height (-1) to maintain the original aspect ratio. The resulting scaled image is saved into a temporary label named [logo], which is then passed into the overlay filter against the main video [0:v].