CommandFFmpeg

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

Commandffmpeg
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.

Related in Commands