Scale width while keeping aspect ratio (and avoiding H.264 dimension errors)
Hardcoding both width and height stretches the source if its aspect ratio does not match. The scale filter accepts -1 to mean "compute this dimension from the source's aspect ratio." Using -1 is the right default for "scale to this width, keep aspect."
The command
ffmpeg -i input.mp4 -vf "scale=1280:-1" -c:a copy output.mp4What it does
FFmpeg decodes each frame, resizes to 1280 pixels wide, and computes the height to preserve the source's aspect ratio (rounded to the nearest even integer to keep H.264 happy). The output is 1280x720 for 16:9 sources, 1280x960 for 4:3, and so on.
When to use it
Any time you want to resize by a single dimension. The most common case is preparing video for the web: 1280px wide is the right ceiling for most browsers and mobile, and -1 handles portrait, landscape, and square sources without per-aspect math.
Video and audio requirements
Any decodable video. The output height is rounded to even pixels because H.264 requires even dimensions. If you really need an odd height, scale to even first and crop.
Things to avoid
- Assuming
-1works for both dimensions. You must give at least one real number;scale=-1:-1is undefined and the scaler may error or produce a 0x0 frame. - Forgetting the even-pixel rule. Some sources have odd heights (a 1080p source is fine, but a 1081-line source is not);
scale=W:-1rounds the height to even. If you see an "odd height" error, scale explicitly withtrunc(iw/2)*2in the expression. - Combining with letterboxing.
scale=1280:-1alone preserves the source's aspect but may not produce a 16:9 frame. For a guaranteed 16:9, addpad=1280:720:(ow-iw)/2:(oh-ih)/2after. - Upscaling low-res content. The same caveats as hardcoded scaling apply.