MpegFlowBlogBack to home
← Recipes·Crop video·video operations

Crop video with FFmpeg: aspect ratio conversion, letterbox removal, ROI extraction

Crop video to a specific region — change aspect ratios (16:9 → 9:16 for mobile), remove letterboxes from old broadcasts, extract regions of interest for analysis pipelines.

ByMpegFlow Engineering Team·FFmpeg recipe
·3 variants·May 9, 2026

When to use this

You crop video to change aspect ratio (typically 16:9 → 9:16 for mobile/social, or 16:9 → 1:1 for square placements), remove letterboxes from old broadcasts that were padded to fit non-native displays, or extract specific regions for ML / analysis pipelines (face detection, object tracking, scoreboard extraction in sports). The crop is a video filter; audio passes through unchanged.

Command variants

Crop to specific dimensions and offset
ffmpeg -i input.mp4 \
  -vf "crop=1080:1920:420:0" \
  -c:v libx264 -preset medium -crf 21 \
  -c:a copy \
  output.mp4

crop=W:H:X:Y. 1080×1920 region starting 420px from left, 0 from top. Centered horizontally on a 1920-wide source = (1920-1080)/2 = 420.

Auto-crop letterboxes (cropdetect + crop)
# First, detect black bars:
ffmpeg -i input.mp4 -vf cropdetect -f null - 2>&1 | grep -o "crop=[^ ]*" | tail -1

# Then apply detected crop:
ffmpeg -i input.mp4 \
  -vf "crop=1920:818:0:131" \
  -c:v libx264 -preset medium -crf 21 \
  -c:a copy \
  output.mp4

cropdetect filter analyzes the source and outputs the crop parameters. Common pattern for processing old broadcast archives with hard-coded letterboxes.

16:9 → 9:16 (mobile portrait)
ffmpeg -i input.mp4 \
  -vf "crop=ih*9/16:ih:iw/2-(ih*9/16)/2:0" \
  -c:v libx264 -preset medium -crf 22 \
  -c:a copy \
  output_portrait.mp4

Crops a 9:16 region centered horizontally from a 16:9 source. ih and iw are input height/width.

What each parameter does

  • crop=W:H:X:Y

    Output width × height starting at offset (X, Y) from top-left. All four values are in pixels.

  • iw / ih

    Input width / input height. Use these for proportional crops that adapt to source resolution.

  • cropdetect

    Filter that detects black bars and outputs suggested crop parameters. Run as a probing pass before applying the crop.

What this outputs

A cropped video file. Resolution = the crop dimensions you specified. Audio passes through unchanged. Re-encoding is required (crop is a video filter).

Pitfalls

  1. Cropping changes aspect ratio. Players may letterbox on display if the new aspect ratio doesn't match common standards (16:9, 9:16, 1:1, 4:5).
  2. cropdetect with very-dark scenes (night-time content, fade-outs) sometimes detects false black bars in the actual content. Use a longer detection window: -vf "cropdetect=24:16:1000".
  3. Cropping preserves the metadata's display-aspect-ratio (DAR) tag, which can confuse some players. Use -aspect to set the new DAR explicitly if needed.
  4. Sub-pixel offsets (X or Y not divisible by 2) cause encoder warnings or errors with chroma sub-sampled formats (yuv420p). Round to even pixels.
  5. Cropping to extreme aspect ratios (e.g., 21:9 → 1:1) loses significant content. Confirm with preview before committing batch processing.

At production scale

Cropping at libx264 is roughly equivalent to scaling in compute cost. Cropdetect adds ~30-50% to processing time as a probing pass. For petabyte-scale legacy archive migration with letterboxes, run cropdetect once per asset and cache the parameters; never re-detect on every encode pass.

How MpegFlow handles this

MpegFlow models cropping as a per-rendition parameter — different renditions can have different crops (mobile-specific 9:16 alongside desktop 16:9). The cropdetect probing pass runs once per source and caches results in the audit log.

Topics
  • FFmpeg
  • crop
  • aspect-ratio
  • video-operations
See also
  • Recipe
    Resize Scale Video
  • Architecture
    Broadcast Grade Vod Transcoding
Running this at scale?

Get the orchestration layer for free.

The crop video command above is the easy part. The queue, retries, audit trail, encoder-version pinning, and multi-tenant security around it are what every video team rebuilds from scratch. We did the rebuild — design partners run it free during beta.

Apply More recipes
© 2026 MpegFlow, Inc. · Trust & complianceAll systems nominal·StatusPrivacy