Skip to content

How to Crop and Scale Video with FFmpeg

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Crop and Scale Video with FFmpeg. We cover key concepts, practical examples, and best practices.

The Problem

Your FFmpeg crop or scale command produces stretched video, wrong aspect ratio, black bars, or fails with Requested rectangle is not inside the input. Resizing and cropping video requires understanding aspect ratios, dimension parity, and filter syntax.

Quick Fix

Fix 1: Scale to Exact Dimensions (May Stretch)

WRONG β€” forcing exact dimensions without aspect ratio:

ffmpeg -i input.mp4 -vf "scale=1920:1080" output.mp4
# (stretches if the source is not 16:9)

RIGHT β€” preserve aspect ratio with force_original_aspect_ratio:

# Scale to fit within 1280x720, add black bars:
ffmpeg -i input.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output.mp4

# Scale to fill 1280x720, crop excess:
ffmpeg -i input.mp4 -vf "scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720" output.mp4

Fix 2: Scale Using Expressions (Width-Based)

# Scale width to 640, height proportional:
ffmpeg -i input.mp4 -vf "scale=640:-1" output.mp4
# (sometimes fails with "not even" error for certain codecs)

RIGHT β€” use -2 for even dimensions:

# Scale width to 640, height proportional and even:
ffmpeg -i input.mp4 -vf "scale=640:-2" output.mp4
# (-2 automatically rounds to the nearest even number)

Fix 3: Crop From Center

WRONG β€” specifying crop dimensions without position:

ffmpeg -i input.mp4 -vf "crop=640:480" output.mp4
# (crops from top-left corner)

RIGHT β€” crop from center:

# Crop 640x480 from the center:
ffmpeg -i input.mp4 -vf "crop=640:480:in_w/2-out_w/2:in_h/2-out_h/2" output.mp4

Or use the (iw-cw)/2:(ih-ch)/2 expression:

ffmpeg -i input.mp4 -vf "crop=640:480" output.mp4
# (same as above when not specifying position β€” centers by default)

Fix 4: Crop with Exact Position

# Crop from (100, 50) with size 640x480:
ffmpeg -i input.mp4 -vf "crop=640:480:100:50" output.mp4

WRONG β€” crop rectangle outside the frame:

ffmpeg -i input.mp4 -vf "crop=640:480:1500:50"
# [error] Requested rectangle is not inside the input

Fix 5: Chain Crop and Scale Together

# Crop then scale:
ffmpeg -i input.mp4 -vf "crop=1920:1080:0:0,scale=1280:720" output.mp4

Fix 6: Aspect Ratio Detection

ffprobe -v error -show_entries stream=width,height,display_aspect_ratio input.mp4
# width=1920
# height=1080
# display_aspect_ratio=16:9

Fix 7: Maintain Aspect Ratio for Thumbnails

ffmpeg -i input.mp4 -vf "scale=320:320:force_original_aspect_ratio=decrease,pad=320:320:(ow-iw)/2:(oh-ih)/2,setsar=1" -vframes 1 thumbnail.jpg

Use DodaTech's Video Frame Analyzer to measure source dimensions and preview crop/scale regions before running full conversions.

Prevention

  • Always use -2 for proportional height to ensure even dimensions.
  • Add pad or crop when force_original_aspect_ratio is used.
  • Check source dimensions with ffprobe before cropping.
  • Use -vframes 100 to test on a short sample first.
  • Verify the output aspect ratio with ffprobe.

Common Mistakes with crop scale

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world FFMPEG code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my scaled video show "not even" errors?

Many codecs require even dimensions for both width and height. Use -2 instead of -1: scale=640:-2. This rounds the computed height to the nearest even number. FFmpeg's -2 and -4 handle this automatically.

What is the difference between force_original_aspect_ratio=decrease and increase?

decrease scales the video to fit within the target dimensions (adds black bars). increase scales to fill the target dimensions (crops the excess). Use decrease when you want the entire visible area, increase when you want to fill the frame.

How do I crop a video to a specific aspect ratio?

First decide a reference dimension. For 16:9 with height 720: crop=in_w:720:(in_w-720*16/9)/2:0. For 4:3 with width 640: crop=640:in_h:0:(in_h-640*3/4)/2. The expression keeps the aspect ratio constant.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro