Table of Contents

How to crop a video with ffmpeg

About

This article shows you how to crop 1) a video with ffmpeg.

The crop filter

once you have installed it, you can use the crop filter to crop your video.

the crop is a filter that accepts the parameters such as the following

How to

How to crop towards the center ?

By default, ffmpeg will crop towards the center if the positions of the output egde are not given.

Crop the central input area with size 100×100:

ffmpeg -i "input.mp4" -vf crop=100:100 "output.mp4"
ffmpeg -i "input.mp4" -vf crop=w=100:h=100 "output.mp4"

How to crop an area at a position ?

Crop area with size 100×100 at position (12,34). 3)

ffmpeg -i "input.mp4" -vf crop=100:100:12:34 "output.mp4"
ffmpeg -i "input.mp4" -vf crop=w=100:h=100:x=12:y=34 "output.mp4"

How to crop the black areas ?

The standard procedure to eliminate these black areas is to run first the cropdetect filter 4) and then run the crop filter.

Example: 5) Find video area surrounded by black borders

ffmpeg -i file.mp4 -vf cropdetect,metadata=mode=print -f null -

A human eye give a better result quicker to detect the border.

This wiki page gives another alternative