Resize/scale a video
Scales a video to a target width while ffmpeg computes a height that's always an even number, which video encoders like libx264 require.
Last updated
ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4
How it works
scale=1280:-2 sets the output width to 1280px and tells ffmpeg to work out the height itself, preserving the source's aspect ratio. The -2 (rather than -1) specifically guarantees the computed dimension comes out EVEN, because libx264 and most other video codecs require both width and height to be divisible by 2 for their chroma subsampling — -1 does the same aspect-preserving math but doesn't round to guarantee evenness, which can fail on some source ratios.
Only one dimension is given a fixed number on purpose: hardcoding both width and height stretches or squashes the picture unless they already match the source's exact ratio, which is rarely what you want for a simple resize.
Watch out for
- →For a meaningful downscale (say, 4K to 720p), add a scaling algorithm to the filter — scale=1280:-2:flags=lanczos — since the default bilinear scaler softens detail more than necessary on large size reductions.
- →Upscaling with this filter just stretches existing pixels; it doesn't add real detail, so a big upscale (e.g. 480p to 4K) will look soft no matter which scaling flag you choose.
- →If you need an EXACT width and height regardless of aspect ratio (say, to match a fixed player size), specify both numbers directly and accept the letterboxing/distortion, or add a crop/pad filter alongside scale instead.
Part by part
- scale=1280:-2
- Width fixed at 1280, height derived from the aspect ratio and rounded to an even number. The -2 rather than -1 is the whole point of this recipe.
- -vf
- The video filter chain. Filters run in the order written, which matters as soon as you add more than one.
Common mistakes
ffmpeg -i input.mp4 -vf "scale=1280:-1" output.mp4-1 preserves the ratio exactly, which can produce an odd height such as 721. H.264 requires even dimensions with common pixel formats, so the encode fails with an error that does not obviously point at the scale filter.
ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4ffmpeg -i input.mp4 -s 1280x720 output.mp4Forcing both dimensions ignores the source aspect ratio, so anything that is not already 16:9 comes out stretched. The scale filter with one derived dimension cannot do that.
ffmpeg -i input.mp4 -vf "scale=1280:-2" -c copy output.mp4Copying the video stream and filtering it are contradictory instructions — a filter requires decoding and re-encoding. ffmpeg will refuse or silently ignore one of them.
Questions
Why does -2 matter?
It rounds the derived dimension to the nearest even number. Most H.264 pixel formats subsample chroma by two in each direction, so an odd width or height has no valid representation and the encoder rejects it.
How do I scale down without upscaling small inputs?
Use an expression that takes the minimum: scale='min(1280,iw)':-2 leaves anything already narrower untouched. Upscaling never adds detail, so guarding against it is worth the extra syntax.
Does resizing reduce the file size?
Substantially, since encoding cost scales roughly with pixel count — halving both dimensions is a quarter of the pixels. Pair it with a CRF setting rather than relying on resolution alone.
Can I pad to a fixed size instead of stretching?
Yes: scale to fit, then pad. Chaining scale=1280:720:force_original_aspect_ratio=decrease with pad=1280:720:(ow-iw)/2:(oh-ih)/2 centres the result in a fixed frame with bars rather than distortion.