Originally published at ffmpeg-micro.com
You have got a 4:3 video that needs to be 16:9. Or a landscape clip that needs to fit a 9:16 vertical frame. Scaling alone either distorts the image or leaves the wrong dimensions. FFmpeg’s pad filter adds bars (black or any color) to fill the gap without touching a single pixel of your actual video.
Quick Answer: Pad to a Target Aspect Ratio
Letterbox a 4:3 video into a 16:9 frame with centered black bars:
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black" output.mp4
Enter fullscreen mode Exit fullscreen mode
This first scales the video to fit inside 1920×1080 without distortion, then pads the remaining space with black. Two filters, one command.
How the pad Filter Works
The pad filter syntax:
pad=width:height:x:y:color
Enter fullscreen mode Exit fullscreen mode
- width and height set the total canvas size
- x and y position the video on that canvas
- color fills the empty space (default is black)
Dynamic Centering with Expressions
Instead of hardcoding pixel values, use FFmpeg built-in variables:
ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black" output.mp4
Enter fullscreen mode Exit fullscreen mode
-
ow= output width,oh= output height -
iw= input width,ih= input height
This centers any input resolution on the target canvas.
Social Media Aspect Ratio Recipes
YouTube / landscape (16:9):
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black" output.mp4
Enter fullscreen mode Exit fullscreen mode
Instagram Reels / TikTok / Shorts (9:16):
ffmpeg -i input.mp4 -vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black" output.mp4
Enter fullscreen mode Exit fullscreen mode
Instagram square (1:1):
ffmpeg -i input.mp4 -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:black" output.mp4
Enter fullscreen mode Exit fullscreen mode
Custom Bar Colors
# White bars
ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:white" output.mp4
# Hex color (dark blue)
ffmpeg -i input.mp4 -vf "pad=1920:1080:(ow-iw)/2:(oh-ih)/2:0x1a1a2e" output.mp4
Enter fullscreen mode Exit fullscreen mode
Pad via the FFmpeg Micro API
If you are automating video processing in a pipeline, you can run the same pad filter through an API call:
curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "inputs": [{"url": "https://example.com/video.mp4"}], "outputFormat": "mp4", "options": [{"option": "-vf", "argument": "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black"}] }'
Enter fullscreen mode Exit fullscreen mode
Get a free API key at ffmpeg-micro.com to try it.
Common Pitfalls
- Padding without scaling first causes errors if input is larger than pad dimensions
- Odd dimensions break H.264/H.265 encoding
- Using pad when you need crop: pad adds space, crop removes it
답글 남기기