In this tutorial, we learn how to crop a video using FFmpeg‘s
crop filter. We will also learn how to use variables for cropping the video.
How to Crop a Video using Pixel Coordinates
If you know the size and the coordinates of the section of the video that you want to crop, then it’s very simple to crop a video using FFmpeg.
The syntax for cropping a video is
crop=width:height:x:y. With this, here is a command line that crops a 200×200 portion of a video.
ffmpeg -i input.mp4 -filter_complex "[0:v]crop=200:200:300:100[cropped]" -map "[cropped]" output.mp4
This command results in a
200x200 cropped portion of the video situated
300 pixels from the left edge and
100 pixels from the top edge.
If the parameters
300:100 is not provided, the resulting portion will be taken from the center of the video. It’s that easy!
Crop a Video in FFmpeg with Variables
We can implement the video cropping command using variables to denote the video parameters. The input video’s
height can be denoted by
Here is an example of cropping a video in FFmpeg using variables instead of specifying the literal pixel coordinates.
ffmpeg -i input.mp4 -filter_complex "[0:v]crop=in_w/2:in_h/2[cropped]" -map "[cropped]" output.mp4
Some useful variable templates
- Bottom right corner:
$xpixels from the top and bottom:
$xpixels from either side of the video:
Crop A Video using FFmpeg from the Bottom Only
A quick example to drive home the point about cropping. Let’s say your video has some ticker text at the bottom and you want to crop it out.
The way to do it using FFmpeg’s crop command is as follows:
ffmpeg -i input.mp4 -filter_complex "[0:v]crop=in_w:in_h-10:0:0[cropped]" -map "[cropped]" output.mp4
This command line tells FFmpeg to crop a region
- whose width is equal to the source video’s width,
- whose height is equal to the source video’s height minus 10 pixels,
- and the origin is at
All you have to do is adjust this command to the height of the region you want to remove, and you’ll have successfully cropped a video using FFmpeg.
If you enjoyed this post, do check out the rest of OTTVerse’s FFmpeg tutorials to learn more about how to use FFmpeg to improve your video editing, compression, and processing skills!