H.264 and HEVC require both width and height to be even numbers. Many video sources meet this; some do not (a 1081-line vertical video, a 4K source with width 3841, screen recordings of odd resolutions). The scale filter with -2 in one dimension rounds the other to the nearest even integer.

The command

ffmpeg -i input.mp4 -vf "scale=-2:720" output.mp4

What it does

FFmpeg scales the source to 720 pixels tall and computes the width to keep the source's aspect ratio, rounded down to the nearest even integer. The -2 means "compute this from the other dimension, rounded to even." The result is a 720p frame with even width, suitable for H.264 or HEVC encoding.

When to use it

When the source has odd dimensions and the target encoder requires even. Most encoders will error on odd dimensions; some silently produce a broken file. The -2 form is safer than -1 because it guarantees the output is even.

Video and audio requirements

Any decodable video. For sources that are already an even multiple of 720, scale=-2:720 is a no-op. For sources that are slightly off (a 1081-line vertical, a 1440x899), the filter adjusts the other dimension to keep the output even.

Things to avoid

  • Combining with a hard width that produces an odd height. scale=1920:1081 errors; scale=1920:-2 produces 1080 instead.
  • Expecting the output to be exactly the requested dimension. -2 rounds down, so a 1280x899 source scaled to height 720 with -2 width produces 1024x720 (1024 is the largest even integer at the right aspect for 720 height), not 1280x720. To force a specific dimension, use a real number, not -2.
  • Forgetting that -2 only rounds down. If you need to round up, use the expression form: scale=trunc(iw/2)*2:trunc(ih/2)*2 or scale='if(gt(iw,ih),min(1920,iw),-2)':-2 with an expression for round-to-nearest.
  • Using this on sources that are not odd. If the source is 1920x1080 already, the filter is a no-op and adds CPU cost. Run a probe first.