FFmpeg Overlay Transparent PNG on Video at Coordinates

This guide demonstrates how to use FFmpeg’s powerful overlay filter to superimpose a transparent PNG image onto a video at precise coordinate locations. You will learn the exact command-line syntax, understand how the coordinate system works, and see practical examples for positioning your image anywhere on the video frame.

To overlay a transparent PNG onto a video, you use FFmpeg’s -filter_complex option. The basic command structure is as follows:

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=x:y" -c:a copy output.mp4

Understanding the Command Parameters

How Coordinates Work

The coordinate system starts at the top-left corner of the video screen, which is represented by (0,0). The x coordinate represents the horizontal axis (moving right), and the y coordinate represents the vertical axis (moving down).

FFmpeg provides built-in variables to make positioning easier: * main_w (or W): Width of the background video. * main_h (or H): Height of the background video. * overlay_w (or w): Width of the PNG overlay. * overlay_h (or h): Height of the PNG overlay.

Common Positioning Examples

Using these variables, you can mathematically position the PNG anywhere on the screen:

1. Exact Pixel Coordinates (e.g., X=150, Y=80)

To place the top-left corner of the image exactly 150 pixels from the left and 80 pixels from the top of the video:

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=150:80" -c:a copy output.mp4

2. Top-Right Corner

To place the image in the top-right corner, subtract the image’s width from the video’s width:

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=W-w:0" -c:a copy output.mp4

3. Bottom-Right Corner

To place the image in the bottom-right corner, subtract both the width and height of the image from the video dimensions:

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=W-w:H-h" -c:a copy output.mp4

4. Dead Center

To perfectly center the PNG on your video:

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=(W-w)/2:(H-h)/2" -c:a copy output.mp4

5. Bottom-Left with padding (e.g., 20px padding)

To place the image in the bottom-left corner with a 20-pixel gap from the edges:

ffmpeg -i input.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=20:H-h-20" -c:a copy output.mp4

FFmpeg automatically respects the alpha channel (transparency) of your PNG image, meaning you do not need to apply extra transparency settings to make the background of your image transparent.