Aspect Ratio Padding & Matte Calculator
Calculate exact pixel padding (letterbox or pillarbox), scaled video dimensions, and FFmpeg pad filter parameters when fitting footage into any canvas.
Source & Destination Canvas Dimensions
--
How Letterboxing and Pillarboxing Work
When placing video footage into a canvas with a different aspect ratio without cropping or anamorphic stretching, black bars (mattes) are added to preserve the original geometry:
- Letterboxing: Added above and below the video when the source is wider than the target frame (e.g. 16:9 video placed into a 9:16 vertical TikTok canvas or 2.39:1 scope into 16:9).
- Pillarboxing: Added to the left and right sides when the source is narrower than the target frame (e.g. classic 4:3 video placed into a 16:9 widescreen canvas).
Mathematical Derivation
Given source dimensions W_s, H_s and target canvas W_c, H_c:
- Source Aspect Ratio:
R_s = W_s / H_s; Canvas Aspect Ratio:R_c = W_c / H_c. - If
R_s > R_c: Fit to width. Scaled width isW' = W_c; Scaled height isH' = round(W_c / R_s). Total vertical padding isP_v = H_c - H'. Top pad isfloor(P_v / 2); bottom pad isP_v - Top pad. - If
R_s < R_c: Fit to height. Scaled height isH' = H_c; Scaled width isW' = round(H_c × R_s). Total horizontal padding isP_h = W_c - W'. Left pad isfloor(P_h / 2); right pad isP_h - Left pad.
Frequently Asked Questions
Why should scaled dimensions always be even numbers?
Most video codecs (H.264, HEVC, VP9, AV1) use 4:2:0 chroma subsampling, which stores color data across 2x2 pixel blocks. Odd pixel dimensions will cause encoding failures or color distortion in video pipelines.
How do I use this in FFmpeg?
The generated filter string can be passed directly to the -vf parameter, for example: ffmpeg -i input.mp4 -vf "scale=1080:608,pad=1080:1920:0:656:black" output.mp4.
What is windowboxing?
Windowboxing occurs when a video simultaneously has letterbox bars on top/bottom and pillarbox bars on the sides, typically caused by re-encoding a previously letterboxed video into a pillarboxed canvas.