I have an MP4 file of a screen recording that I need to crop down. How can I accomplish this without using expensive tools like Adobe Premier or Final Cut? I prefer
ffmpeg because I have used it before.
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
Where the options are as follows:
out_wis the width of the output rectangle
out_his the height of the output rectangle
yspecify the top left corner of the output rectangle
Original 320x240 image
To crop a 80×60 section, starting from position (200, 100):
ffmpeg -i in.mp4 -filter:v "crop=80:60:200:100" -c:a copy out.mp4
- The audio is stream copied in this example, so re-encoding is avoided.
To crop the bottom right quarter:
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:
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:
ffmpeg -i in.mp4 -filter:v "crop=160:120:160:120" -c:a copy out.mp4
- You can refer to the input image size with
in_has shown in this first example. The output width and height can also be used with
Crop 20 pixels from the top, and 20 from the bottom:
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
yare omitted such as in this example.
You can take a crop (heh heh) and preview it live with
ffplay -i input -vf "crop=in_w:in_h-40"
This way you can experiment and adjust your cropping without the need to encode, view, repeat.
Default encoder for MP4 is
libx264(H.264 video) or
mpeg4(MPEG-4 Part 2 video) depending on your
ffmpegbuild. See FFmpeg Wiki: H.264 Video Encoding Guide for more info.
Instead of cropping and re-encoding, consider cropping upon playback. This is possible with any player worth using.
-croprightoptions instead of the
cropfilter. If this is the case for you then get a modern
ffmpeg. Development is very active and there is no reason to use an antique.