Resize a video with FFmpeg

Scales to a target width while computing a height that stays even, which H.264 requires.

ffmpeg -i https://cdn.rendobar.com/assets/examples/sample.mp4 -vf scale=640:-2 -c:v libx264 -crf 23 -t 5 out.mp4
Encode
481 ms
Output
269.0 KB
Cost
$0.0020
Result
640x360

job_ece789351fe7440d

The part everyone gets wrong

Use -2, never -1. Both preserve the aspect ratio, but -2 rounds to an even number and -1 does not. H.264 with yuv420p needs both dimensions even, so -1 produces an encoder failure on roughly half of all source aspect ratios.

What the common version does

An odd width with -1 can compute an odd height, and libx264 refuses to encode odd dimensions.

ffmpeg -i https://cdn.rendobar.com/assets/examples/sample.mp4 -vf scale=641:-1 -c:v libx264 -crf 23 -t 5 out.mp4
It errors

This one fails outright, which is the good case. You find out immediately.

job_ec395f0805e245a6

Frequently asked questions

How do I resize video ffmpeg?

Scales to a target width while computing a height that stays even, which H.264 requires.

What goes wrong most often?

Use -2, never -1. Both preserve the aspect ratio, but -2 rounds to an even number and -1 does not. H.264 with yuv420p needs both dimensions even, so -1 produces an encoder failure on roughly half of all source aspect ratios.

What happens if I get it wrong?

We ran the naive version too. This one fails outright, which is the good case. You find out immediately.

Do I need FFmpeg installed?

Not with Rendobar. The command on this page ran through the API against a URL, with no local FFmpeg and no server. The job id below it is the job that produced these numbers.

Run this without installing FFmpeg

This exact command ran through the API against a URL.