What You Will Learn
- Basic syntax of the
scalefilter - How to resize while automatically preserving aspect ratio (
-1/-2syntax) - How to apply relative size changes using
iw/ihvariables - How to cap output at a maximum resolution
- How to add letterbox (black bars) with the
padfilter - How to specify the output pixel format
Tested version: Verified with FFmpeg 6.1 (ubuntu-latest / CI-validated) Target OS: Windows / macOS / Linux
Basic Syntax of the scale Filter
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
| Part | Description |
|---|---|
-vf | Option to specify a video filter (same as -filter:v) |
scale=width:height | Output width and height in pixels |
When both width and height are specified explicitly, the video will be stretched if the aspect ratio differs. In most cases it is recommended to use the aspect ratio preservation options described below.
Automatic Aspect Ratio Preservation
Difference Between -1 and -2
With the scale filter, setting one dimension to -1 or -2 automatically calculates the other dimension to preserve the aspect ratio.
| Value | Behavior |
|---|---|
-1 | Calculates automatically to preserve aspect ratio. May result in an odd number. |
-2 | Preserves aspect ratio while rounding to a multiple of 2 (required for H.264 encoding). |
Because H.264 errors on odd pixel dimensions, using -2 is recommended.
Fix Width, Auto-Calculate Height
ffmpeg -i input.mp4 -vf scale=1280:-2 output.mp4
Fix Height, Auto-Calculate Width
ffmpeg -i input.mp4 -vf scale=-2:720 output.mp4
Relative Resizing (iw / ih Variables)
Using iw (input width) and ih (input height), you can resize relative to the original dimensions.
Scale Down to Half Size
ffmpeg -i input.mp4 -vf scale=iw/2:ih/2 output.mp4
Scale Up to 1.5x
ffmpeg -i input.mp4 -vf scale=iw*1.5:ih*1.5 output.mp4
Halve Width While Preserving Aspect Ratio
ffmpeg -i input.mp4 -vf scale=iw/2:-2 output.mp4
The iw/ih variables are handy for writing generic scripts without needing to know the original resolution.
Capping Maximum Resolution
Useful when you want to constrain output to no larger than a certain size — for example, limiting 4K source to a maximum of Full HD (1920px). Use the min() function to pick the smaller of the input resolution or the upper limit.
ffmpeg -i input.mp4 -vf "scale='min(1920,iw)':-2" output.mp4
This command keeps the width as-is if it is under 1920, or scales it down to 1920 if it is 1920 or wider. The height is auto-calculated with -2 to preserve the aspect ratio.
Wrap filters that contain expressions in quotes to protect shell special characters (
',,).
Adding Letterbox with the pad Filter
To fit a video of a different aspect ratio into a fixed frame (e.g., output a 16:9 video at 1920×1080 with black bars), combine scale and pad.
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output.mp4
| Part | Description |
|---|---|
scale=1920:1080:force_original_aspect_ratio=decrease | Scale down to fit within 1920×1080 while preserving aspect ratio |
pad=1920:1080:(ow-iw)/2:(oh-ih)/2 | Pad to 1920×1080 with center alignment |
The default padding color is black. To change it, specify pad=...:color=white or another color.
Specifying the Output Pixel Format
When encoding to H.264, explicitly specifying yuv420p improves compatibility with a wide range of players.
ffmpeg -i input.mp4 -vf scale=1280:-2 -pix_fmt yuv420p output.mp4
You can also add a format filter as part of a chain:
ffmpeg -i input.mp4 -vf "scale=1280:-2,format=yuv420p" output.mp4
Quick Reference Commands
ffmpeg -i input.mp4 -vf scale=1920:1080 output.mp4
ffmpeg -i input.mp4 -vf scale=1280:-2 output.mp4
ffmpeg -i input.mp4 -vf scale=-2:720 output.mp4
ffmpeg -i input.mp4 -vf scale=iw/2:ih/2 output.mp4
Frequently Asked Questions
height not divisible by 2 Error
Occurs when using -1 results in an odd pixel count. Change to -2.
ffmpeg -i input.mp4 -vf scale=1280:-2 output.mp4
Image Looks Blurry After Upscaling
The default algorithm for the scale filter (bilinear) produces slight blurring when upscaling. To improve quality, try adding -sws_flags lanczos.
ffmpeg -i input.mp4 -vf scale=3840:-2 -sws_flags lanczos output.mp4
Related Articles
Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner) Primary sources: ffmpeg.org/ffmpeg-filters.html / ffmpeg.org/ffmpeg.html / trac.ffmpeg.org/wiki/Scaling