How to Pad a Video with an Image Using FFmpeg
Padding a video with a custom background image is a highly effective way to adapt vertical smartphone videos for widescreen displays without losing quality. This guide provides the exact FFmpeg command required to overlay your video onto a custom image background, along with a clear breakdown of how the command works so you can customize it for your projects.
To pad a video with a custom image, you will use FFmpeg’s
overlay filter. This method treats the custom image as the
background layer and places the video on top of it.
Here is the standard command to center a video over a background image:
ffmpeg -i background.png -i input.mp4 -filter_complex "[0:v][1:v]overlay=(W-w)/2:(H-h)/2:shortest=1[v]" -map "[v]" -map 1:a? -c:a copy output.mp4How the Command Works
-i background.png: Specifies your custom background image as the first input ([0:v]). Ensure this image matches your desired final output resolution (e.g., 1920x1080).-i input.mp4: Specifies your source video as the second input ([1:v]).-filter_complex: Tells FFmpeg to use complex filtering because we are combining multiple inputs.[0:v][1:v]overlay=(W-w)/2:(H-h)/2: This is the core instruction. It takes the background image ([0:v]) and overlays the video ([1:v]) directly onto it. The math formula(W-w)/2and(H-h)/2dynamically calculates the exact coordinates to center the video on the background.shortest=1: Since a static image has an infinite duration, this parameter is crucial. It tells FFmpeg to stop encoding as soon as the video file ends.-map "[v]": Maps the visual output of the filter chain to the final video file.-map 1:a? -c:a copy: Maps the audio from the original video file and copies it directly to the output file without re-encoding, preserving audio quality and saving processing time. The?prevents the command from failing if the input video has no audio.