Configure FFmpeg Overlay Coordinates and Display Time

The FFmpeg overlay filter is a powerful tool for superimposing images, logos, or secondary videos onto a main video stream. This guide explains how to precisely position your overlay using X and Y coordinates and control its visibility over time using timeline editing parameters.

Position Overlay with Coordinates

The overlay filter positions the top-left corner of the overlay source (the second input) onto the main video source (the first input) using x and y coordinates.

FFmpeg provides shorthand variables to calculate these positions dynamically: * main_w or W: Width of the main video. * main_h or H: Height of the main video. * overlay_w or w: Width of the overlay source. * overlay_h or h: Height of the overlay source.

Common Positioning Formulas

Command Example

To place a logo in the top-right corner with a 10-pixel padding:

ffmpeg -i main.mp4 -i logo.png -filter_complex "overlay=x=W-w-10:y=10" output.mp4

Control Overlay Timing

To make the overlay appear and disappear at specific times, use the enable option. This option utilizes FFmpeg’s timeline editing feature, where the variable t represents the current time in seconds.

Common Timing Functions

Command Example

To display the overlay only from second 5 to second 15 of the video:

ffmpeg -i main.mp4 -i logo.png -filter_complex "overlay=enable='between(t,5,15)'" output.mp4

Combining Coordinates and Timing

To configure both the location and the active duration of the overlay, combine the parameters inside the overlay filter by separating them with a colon (:).

Command Example

To position an overlay in the bottom-right corner (with 15px padding) and have it display only between seconds 10 and 20:

ffmpeg -i main.mp4 -i logo.png -filter_complex "overlay=x=W-w-15:y=H-h-15:enable='between(t,10,20)'" output.mp4