Skip to content
systemcoding.dev
Media

Crop a centred square with crop=ih:ih

Crop a centred square in FFmpeg 7.1 with crop=ih:ih, which defaults the offset to the centre so you only name the size.

1 min read
Summarize in AI

The crop filter takes width, height, then optional x and y. When x and y are left out they default to the centre of the frame, so a square needs only the size, and the input height is already the side of a square that fits a landscape video.

Shell
ffmpeg -i input.mp4 -vf "crop=ih:ih" -c:v libx264 -crf 22 -c:a copy square.mp4
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 square.mp4
Text
1080,1080

For a 1920x1080 source the result is 1080x1080, with 420 pixels removed from each side. Here ih is the input height, one of the variables listed in the crop filter documentation. For a portrait source use crop=iw:iw instead, or min(iw\,ih) for both: crop=min(iw\,ih):min(iw\,ih), where the backslash escapes the comma inside a filter chain.

Cropping loses the sides, so a person standing off-centre can be cut out. Add an x value such as crop=ih:ih:0:0 to keep the left edge instead. If you need the whole picture inside a square, use pad rather than crop.

Taggedffmpeg
Share

More snippets

Media

List ALSA devices with aplay -l

List the playback cards and devices ALSA sees with aplay -l from alsa-utils 1.2, and turn the output into a hw:card,device name.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.