Crop a video with FFmpeg
The crop filter keeps a window of the frame and throws the rest away. Below: an explicit window, a centered square, a percentage-based crop, a 9:16 window and cropdetect for letterboxed sources, each checked with ffprobe.
Verified with FFmpeg 9.0.1 on 26 August 2026. Search intent: ffmpeg crop video.
ffmpeg -i input.mp4 -vf "crop=640:360:320:180" -c:v libx264 -crf 23 -preset medium -c:a copy cropped.mp4Keeps a 640x360 window whose top-left corner sits at x=320, y=180, which is the exact centre of a 1280x720 frame. The video is re-encoded (cropping changes pixels, so stream copy is impossible), the audio is copied. Output: 640x360, 360 frames, 1.6 MB from a 4.9 MB source.
Flags, explained
- crop=w:h:x:y
- Output width and height, then the top-left corner of the window in the source. x and y default to the centre when omitted.
- iw, ih
- Input width and height, usable in any of the four expressions (also in_w and in_h).
- cropdetect=limit=24:round=2
- Treat pixels darker than 24 as black and round the suggestion to a multiple of 2 so the result stays encodable.
- -f null -
- Decode and filter but write nothing, which is all cropdetect needs.
- -c:v libx264 -crf 23 -preset medium
- Re-encode the cropped frames at x264 defaults. Cropping always re-encodes.
- -c:a copy
- Audio is untouched by a crop, so copy it.
Variants
Centered square (1:1) without giving x and y
ffmpeg -i input.mp4 -vf "crop=720:720" -c:v libx264 -crf 23 -preset medium -c:a copy square.mp4When x and y are omitted the window is centered. On a 1280x720 source the full height is kept and 280 px are removed on each side. Output: 720x720, 3.1 MB.
Crop by percentage with iw and ih
ffmpeg -i input.mp4 -vf "crop=iw:ih*0.8:0:ih*0.1" -c:v libx264 -crf 23 -preset medium -c:a copy banner.mp4Keeps the full width and the middle 80 % of the height, removing 10 % top and bottom. Expressions make the command reusable on any source size. Output: 1280x576.
Vertical 9:16 window from the centre
ffmpeg -i input.mp4 -vf "crop=406:720" -c:v libx264 -crf 23 -preset medium -c:a copy vertical.mp4720 x 9/16 is 405, an odd number the encoder cannot take with yuv420p, so ask for 406. Output: 406x720. For a proper 1080x1920 deliverable scale first, see the vertical page.
Find black bars with cropdetect
ffmpeg -i letterboxed.mp4 -t 2 -vf "cropdetect=limit=24:round=2" -f null -Analyses two seconds and prints the crop it recommends on every frame. On a 1280x900 test file with 90 px black bars it printed crop=1280:720:0:90 for 59 frames in a row. Paste that value into the crop filter and encode.
Pitfalls we hit
- Odd sizes are corrected silently: crop=405:720 produced a 404x720 file with no warning at -v error. Ask for even numbers when the output is yuv420p H.264.
- A window larger than the frame or an x/y that pushes it outside is an error, not a clamp. Read the source size with ffprobe first (or use iw and ih expressions).
- crop then scale and scale then crop give different pictures. To fill 1080x1920 from a 16:9 source, scale up first and crop second, or you crop a tiny window and upscale it.
- cropdetect only sees the frames you feed it. A fade-in at the start reads as "all black"; skip a few seconds with -ss or sample the middle of the file.
How we verified it
Run with FFmpeg 9.0.1 on 26 August 2026 against a 12 s, 1280x720, 30 fps H.264/AAC file (4,896,094 bytes). Primary command: 640x360, 360 frames, 12.000 s, 1,588,227 bytes. crop=720:720: 720x720, 3,058,512 bytes. crop=iw:ih*0.8:0:ih*0.1: 1280x576, 4,129,942 bytes. crop=405:720 silently gave 404x720; crop=406:720 gave 406x720, 1,288,232 bytes. cropdetect on a 1280x900 letterboxed clip reported crop=1280:720:0:90 on 59 frames.
The same edit as a typed operation
crop_video takes a target ratio (9:16, 1:1, 4:5, 16:9) and a focus point, probes the source and computes an even-sized window that never exceeds the frame. The pixel maths and the encoder settings are decided for you, and the result comes back as a signed URL.
{
"inputs": [{ "id": "main", "url": "https://example.com/video.mp4" }],
"options": { "aspect_ratio": "4:5", "focus": "top" }
}FAQ
Does cropping a video reduce quality?
The kept pixels are re-encoded once, so a small generation loss applies, kept negligible at -crf 18 to 23. There is no way to crop with stream copy because the compressed frames describe the whole picture.
How do I crop to a 1:1 square with FFmpeg?
Use crop=H:H where H is the source height, for example crop=720:720 on a 1280x720 file. Without x and y the window is centered. Add scale=1080:1080 afterwards if a platform wants a fixed size.
How do I remove black bars automatically?
Run cropdetect on a few seconds of the file with -f null -, read the crop=... value it prints, then run a second command with that value in the crop filter. FFmpeg does not apply the detection by itself.
Why does FFmpeg say the crop size is invalid?
The window must fit inside the frame: w + x cannot exceed the source width and h + y cannot exceed the height. Check the source dimensions with ffprobe and use iw and ih expressions to stay inside.
Related commands
- ffmpeg resize videoResize a video with FFmpegRead
- ffmpeg 9:16 vertical videoMake a video vertical (9:16) with FFmpegRead
- ffmpeg trim videoTrim a video with FFmpegRead