Use the crop
filter:
1 2 |
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4 |
Where the options are as follows:
out_w
is the width of the output rectangleout_h
is the height of the output rectanglex
andy
specify the top left corner of the output rectangle
Example 1
To crop a 80×60 section, starting from position (200, 100):
1 |
ffmpeg -i in.mp4 -filter:v "crop=80:60:200:100" -c:a copy out.mp4 |
Example 2
To crop the bottom right quarter:
1 2 |
ffmpeg -i in.mp4 -filter:v "crop=in_w/2:in_h/2:in_w/2:in_h/2" -c:a copy out.mp4 |
This is the same as:
1 2 |
ffmpeg -i in.mp4 -filter:v "crop=320/2:240/2:320/2:240/2" -c:a copy out.mp4 |
Which is the same as:
1 |
ffmpeg -i in.mp4 -filter:v "crop=160:120:160:120" -c:a copy out.mp4 |
Example 3
Crop 20 pixels from the top, and 20 from the bottom:
1 2 |
ffmpeg -i in.mp4 -filter:v "crop=in_w:in_h-40" -c:a copy out.mp4 |
- The filter will automatically center the crop if
x
andy
are omitted such as in this example.
Previewing
You can take a crop (heh heh) and preview it live with ffplay
:
1 |
ffplay -i input -vf "crop=in_w:in_h-40" |