FFmpeg Pad Video with Transparent Borders
This article explains how to use FFmpeg to add transparent borders to a video using the video padding filter. You will learn the exact command syntax, how to configure the padding dimensions, how to define the transparent background color, and which output formats to use to properly preserve the alpha channel transparency.
To pad a video with transparent borders, you must use the
pad filter, specify a transparent color, and export the
file using a video codec that supports an alpha channel (transparency).
Standard formats like H.264 MP4 do not support transparency, so you must
use formats like WebM (VP9) or QuickTime (MOV).
The FFmpeg Command
Here is the standard command to add a transparent border to a video and export it as a WebM file:
ffmpeg -i input.mp4 -vf "pad=iw+100:ih+100:50:50:color=black@0,format=yuva420p" -c:v libvpx-vp9 output.webmCommand Breakdown
-i input.mp4: Specifies the input video file.-vf: Introduces the video filtergraph.pad=iw+100:ih+100:50:50:color=black@0: This is the padding filter:iw+100: Sets the output width (Input Width + 100 pixels).ih+100: Sets the output height (Input Height + 100 pixels).50(first instance): The X-coordinate offset where the input video is placed (shifts the video 50 pixels to the right).50(second instance): The Y-coordinate offset where the input video is placed (shifts the video 50 pixels down).color=black@0: Sets the background color. The@0represents the alpha channel value, where0is completely transparent and1is completely opaque.
format=yuva420p: Forces the pixel format to include an alpha channel (ainyuvarepresents alpha).-c:v libvpx-vp9: Uses the VP9 codec, which natively supports alpha channel transparency.
Alternative: Exporting to QuickTime MOV (ProRes)
If you need a high-quality intermediate file for video editing
software like Adobe Premiere or DaVinci Resolve, you should output to a
QuickTime .mov file using the ProRes codec:
ffmpeg -i input.mp4 -vf "pad=iw+120:ih+120:60:60:color=black@0,format=yuva444p10le" -c:v prores_ks -profile:v 4 output.mov-profile:v 4: Selects the ProRes 4444 profile, which is required to support transparency.format=yuva444p10le: Ensures the high-quality 10-bit pixel format with alpha is preserved.
Centering the Video Automatically
If you want to pad a video to a specific resolution (for example, placing a 1280x720 video inside a 1920x1080 canvas) and keep the video perfectly centered, use mathematical expressions for the offset:
ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=black@0,format=yuva420p" -c:v libvpx-vp9 output.webmow: Output Width (1920).iw: Input Width.(ow-iw)/2: Centers the video horizontally.(oh-ih)/2: Centers the video vertically.