FFmpeg crop video: crop=w:h:x:y, centre, and 9:16

Crop a video with FFmpeg's crop filter: -vf crop=w:h:x:y keeps a w×h area whose top-left corner is at x,y; leave out x and y to crop the centre.

5 min readSume
All posts

To crop a video with FFmpeg, use the crop filter: ffmpeg -i input.mp4 -vf crop=w:h:x:y -c:a copy output.mp4 keeps a rectangle w pixels wide and h high whose top-left corner sits at x,y. Leave out x and y and FFmpeg centres the rectangle. crop=ih*9/16:ih cuts a centred vertical 9:16 frame out of a landscape clip.

The FFmpeg behavior below is quoted from the FFmpeg filters documentation and the ffmpeg documentation, and the Sume facts come from the Video filter docs, all read on 2026-09-29. The commands were run on a 1920×1080 test clip.

What do w, h, x and y mean in crop?

w and h are the output width and height; both default to the input size (iw, ih). x and y place the left and top edges of the kept area in the input, and default to (in_w-out_w)/2 and (in_h-out_h)/2, the centre. Each value is an expression, so it can use the input size (in_w/iw, in_h/ih), the output size (out_w/ow, out_h/oh), or even the frame number n and timestamp t for x and y.

From the crop filter examples in the FFmpeg filters documentation, read 2026-09-29.
FilterKeeps
crop=100:100:12:34A 100×100 area with its top-left corner at (12,34)
crop=100:100The central 100×100 area
crop=in_hThe central square
crop=2/3*in_w:2/3*in_hThe central area at 2/3 of the input size
crop=in_w-2*10:in_h-2*20Everything but 10 px left and right, 20 px top and bottom
crop=in_w/2:in_h/2:in_w/2:in_h/2The bottom-right quarter

How do I crop a landscape video to 9:16?

Keep the full height and take a width of 9/16 of it: crop=ih*9/16:ih. With no x, the window is centred. To follow the subject instead, set x yourself, for example crop=ih*9/16:ih:0:0 for the left edge. On the 1920×1080 test clip the output was 608×1080.

With subsampled pixel formats such as yuv420p, FFmpeg rounds the crop to fit the chroma unless you set exact=1, which crops at exactly the values given. If an encoder then refuses an odd width or height, height not divisible by 2 covers that error. For other ways to turn a landscape clip vertical, see convert horizontal video to vertical.

# Centred 9:16 window from a landscape clip, audio copied
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih" -c:a copy vertical.mp4

# Trim 10 px from the left and right, 20 px from top and bottom
ffmpeg -i input.mp4 -vf "crop=in_w-2*10:in_h-2*20" -c:a copy trimmed.mp4

Does cropping a video lose quality?

It re-encodes the picture. The ffmpeg docs say filters can't run on a stream copy, "since filters work on decoded frames", so the cropped video is always encoded again; -c:a copy leaves the audio alone. How to crop a video without losing quality covers keeping that loss small.

Can the crop window move or change size during the video?

It can move, but not resize. The docs say w and h are evaluated only once, when the filter is configured, while x and y are evaluated for every frame. So a fixed-size window can pan across the picture with an expression in t (seconds) or n (frame number). If a computed x or y is not valid, FFmpeg approximates it to the nearest valid value, so a pan that runs past the edge stops at the border.

keep_aspect=1 keeps the input's display aspect ratio by changing the output's sample aspect ratio, rather than cropping to a different shape. It defaults to 0.

# A 9:16 window that pans left to right over 10 seconds
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih:(iw-ow)*t/10:0" -c:a copy pan.mp4

Can I crop a video without running FFmpeg?

Yes, for a file already in your Sume workspace on media.sume.com, such as an earlier Sume job's output: Sume's video filter (POST /v1/video-filter) takes the rectangle as a crop op in fractions of the frame, or crop=… in a filtergraph, and each encode job reserves $0.02. How to crop a video without losing quality shows the request, and convert horizontal video to vertical works out the 9:16 fractions.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume