Resize a video with FFmpeg

Use -vf scale=1280:-2. FFmpeg sets the width to 1280 and picks the height that keeps the shape, rounded to an even number so H.264 accepts it. For an exact frame size like 1280x720, scale to fit inside it and pad the rest with black.

Keep shape Re-encode

You want a smaller (or larger) copy and the height can be whatever fits.

ffmpeg -i in.mp4 -vf scale=1280:-2 -c:a copy out.mp4

1280x546. The exact height would be 545.33, and -2 rounds it to the nearest even number. Audio copied untouched.

Size out
1280x546
Shape
2.35:1, same as the input
Run time
1.2 s
Output
3.7 MB
Exact box Re-encode

The player, platform or template needs one exact frame size.

ffmpeg -i in.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -c:a copy out.mp4

1280x720. The picture is 1280x545 in the middle, with black bars above and below. Nothing stretched, nothing cut.

Size out
1280x720
Picture
1280x545, bars top and bottom
Run time
1.2 s
Output
3.5 MB

Proof

One 1920x818 clip into a 1280x720 frame

The input is wider than 16:9. Each command below asked for 1280x720 and handled the extra width differently. The last two pictures zoom 4x into the same frame to compare scaling algorithms.
force_original_aspect_ratio=decrease, pad Whole picture, bars added
Sintel close-up resized to 1280x720 with black bars above and below the full picture
1280x720 The picture scales to 1280x545 and pad centres it in the 720-high frame. Every pixel of the original shot is still there.
force_original_aspect_ratio=increase, crop Fills the frame, sides cut
Sintel close-up resized to fill 1280x720, the left and right edges cut off
1280x720 The picture scales to 1690x720 and crop keeps the middle 1280. No bars, but 205 px of the shot are gone on each side.
scale=1280:720,setsar=1 Squeezed
Sintel close-up squeezed into 1280x720, the face visibly taller and narrower
1280x720 Both sizes forced and the pixel shape reset. The face is 24% narrower than it should be.
scale=1280:-2 (bicubic, the default)
4x zoom on the girl's eyes after a default bicubic downscale to 1280 wide
3.7 MB Frame 48 of the 1280x546 output, a 240x102 area blown up 4x with no smoothing.
scale=1280:-2:flags=lanczos
4x zoom on the girl's eyes after a lanczos downscale to 1280 wide
3.8 MB Same frame, same area. Lash lines and hair strands hold slightly crisper edges. The file came out 2.1% bigger at the same CRF.

Footage: Sintel, © Blender Foundation, CC BY 3.0.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.mp4": "https://cdn.rendobar.com/examples/resize-video/in.mp4",
},
params: {
command: "ffmpeg -i in.mp4 -vf scale=1280:-2 -c:a copy out.mp4",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.mp4": "https://cdn.rendobar.com/examples/resize-video/in.mp4"
},
"params": {
"command": "ffmpeg -i in.mp4 -vf scale=1280:-2 -c:a copy out.mp4"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Resize to 720 high, keep the shape

    Re-encode
    ffmpeg -i in.mp4 -vf scale=-2:720 -c:a copy out.mp4

    1690x720. Put -2 on the side you do not care about.

    1.7 s run 6.0 MB 10.00 s long

  2. Make it half the size

    Re-encode
    ffmpeg -i in.mp4 -vf scale=iw/2:-2 -c:a copy out.mp4

    960x410. iw/2:ih/2 would ask for 960x409 and fail, because 818 / 2 is odd.

    752 ms run 2.0 MB 10.00 s long

  3. Fill 1280x720 and crop the overflow

    Re-encode
    ffmpeg -i in.mp4 -vf "scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720" -c:a copy out.mp4

    1280x720, no bars. The picture scales to 1690x720 and loses 205 px on each side.

    1.4 s run 4.4 MB 10.00 s long

  4. Fit inside 1280x720 without bars

    Re-encode
    ffmpeg -i in.mp4 -vf scale=1280:720:force_original_aspect_ratio=decrease:force_divisible_by=2 -c:a copy out.mp4

    1280x546, byte for byte the same file as scale=1280:-2. Without force_divisible_by=2 it asks for 1280x545 and libx264 refuses.

    1.2 s run 3.7 MB 10.00 s long

  5. Shrink only if wider than 1280

    Re-encode
    ffmpeg -i in.mp4 -vf "scale='min(1280,iw)':-2" -c:a copy out.mp4

    1280x546 from the 1920 input. With min(2560,iw) the same command left it at 1920x818, so small videos are never blown up.

    1.2 s run 3.7 MB 10.00 s long

  6. Resize with a sharper scaler

    Re-encode
    ffmpeg -i in.mp4 -vf scale=1280:-2:flags=lanczos -c:a copy out.mp4

    1280x546, 2.1% bigger than the default bicubic at the same CRF, with slightly sharper edges in the 4x zoom.

    1.2 s run 3.8 MB 10.00 s long

Gotchas

Where it goes wrong

Why do I get "height not divisible by 2"?

H.264 and HEVC store colour at half resolution in both directions, so they need even widths and heights. -1 keeps the shape exactly and does not round to an even number:

ffmpeg -i in.mp4 -vf scale=1280:-1 out.mp4

Fails: [libx264] height not divisible by 2 (1280x545), then Conversion failed!. libx265 fails the same way with its own message. A WebM with VP9 accepted the odd height.

Use -2 instead of -1. It keeps the shape and rounds to the nearest even number: 545.33 became 546. Any -n works the same way, so -4 or -16 gives a height divisible by 4 or 16.

When you size with force_original_aspect_ratio, there is no -2 to write. Add force_divisible_by=2 to the same filter.

Why does my 1280x720 video still play wide?

Because scale protects the shape on its own. With both sizes forced, it writes a pixel aspect ratio that makes players show the old shape again:

ffmpeg -i in.mp4 -vf scale=1280:720 out.mp4

1280x720 stored, with a sample aspect ratio of 540:409. Chrome reported the video as 1690x720 and drew it 2.35:1, not 16:9.

Tools that ignore the pixel aspect ratio show the same file squeezed. If you really want 1280x720 square pixels, add setsar=1 and accept the distortion in the proof above. If you want it to look right, use the box or fill command.

Which scaling algorithm should I use?

The default is bicubic. flags=lanczos keeps a little more fine detail when you shrink, which the 4x crops above show on the lashes and hair. It cost 2.1% more bytes at the same CRF on this clip, so for footage people watch closely it is worth adding.

lanczos vs bicubic and the other scaling flags compares their file size and encode time on a 720p to 480p downscale.

Related: Crop a video, Compress a video, Rotate a video.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.