Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Cropping Videos With ffmpeg

Cropping in ffmpeg is down with the [TODO: Code shorthand span ] [TODO: Code shorthand span ] filter. For example :

No Crop

Starting with a video that's 3840x2160, this command uses the crop flag but won't change the dimensions since the OUTWIDTH and OUTHEIGHT are the same as the video and the STARTX and STARTY values are both zero.

ffmpeg -i input.mp4 -vf "crop=3840:2160:0:0" output.mp4

Cropping The Right

Removing the right side of the frame is done by *decreasing the value for OUTWIDTH**. That reduces the size of the output while keeping the starting point at zero so the right gets cropped off.

ffmpeg -i input.mp4 -vf "crop=2840:2160:0:0" output.mp4

Cropping The Left

Removing the left side of the frame is done by *increasing the value for STARTX and decreasing the value for OUTWIDTH**. The amount of the increase and decrease need to be the same in order to keep the crop flush against the side. For example, here's what it looks like if the OUTWIDTH is reduced by 1000 and the STARTX is increased by the same amount.

ffmpeg -i input.mp4 -vf "crop=2840:2160:1000:0" output.mp4

Cropping To The Center

Removing both sides is done by *increasing STARTX and decreasing OUTWIDTH by more** For example, this command increase the STARTX value to 1000. The original width of the video is 3840. If we subtract 1000 from that we'd get 2840. If we set the OUTWIDTH to that, it would reach all the way across. Reducing it further to 1840 pulls back 1000 pixels.

ffmpeg -i input.mp4 -vf "crop=1840:2160:1000:0" output.mp4

Enlarging Doesn't Work

Setting the crop values larger than the source video resolves in an error. For example, give a 3840x2160 video this will fail :

-vf "crop=4840:2160:0:0"

with an error message like :

code full

- These examples all use with OUTWIDTH and STARTX for cropping along the horizontal axis. The same stuff all applies for the vertical dimension with OUTHEIGHT and STARTY.

- These example images have all be resized down to make them easier to see. The resize was the same on all of them so the ratios are all the same.

- The size can be adjusted in ffmpeg at the same time as the crop. I don't have a good write - up on that yet.

[] write up ffmpeg resizing and cropping together