What is video cropping?

Cropping a video means to trim the edges of the video frame to remove unwanted or unnecessary parts of the video. Cropping a video can be done using a video editing software or with a command-line tool like FFMPEG.

There are many potential use cases for cropping a video. Some common examples include:

  1. Removing black bars from a video that was recorded in a non-standard aspect ratio. This can improve the viewing experience by making the video fill the entire screen.
  2. Cropping a video to focus on a specific part of the frame. For example, if you recorded a video of a person speaking and you only want to show their face, you can crop the video to only show the area around their face.
  3. Cropping a video to create a specific aspect ratio. For example, if you recorded a video in a 4:3 aspect ratio but you want to share it on a platform that only supports 16:9 videos, you can crop the video to fit the 16:9 aspect ratio.
  4. Cropping a video to remove distractions or objects in the background. For example, if you recorded a video of yourself talking but there is a distracting object in the background, you can crop the video to remove the object and make the video more professional.

How to crop a video with FFMPEG?

Cropping a video with ffmpeg is a relatively simple process. Here is a step-by-step guide:

  1. First, you need to make sure you have ffmpeg installed on your computer. If you don't have it, you can download it from the official website.
  2. Once you have ffmpeg installed, open a command prompt or terminal window and navigate to the folder where the video you want to crop is located.
  3. To crop a video with ffmpeg, you will need to use the following command:
ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4

In this command, input.mp4 is the name of the input video file, and output.mp4 is the name of the output video file that will be created after cropping.

The -filter:v "crop=w:h:x:y" part of the command specifies the cropping settings. In this part of the command, w is the width of the cropped area, h is the height of the cropped area, x is the horizontal offset of the top left corner of the cropped area, and y is the vertical offset of the top left corner of the cropped area.

For example, -filter:v "crop=100:100:50:50" would crop a 100x100 pixel area starting at the coordinates (50, 50) of the input video.

Once you have entered the ffmpeg command with the correct cropping settings, press enter to execute it. ffmpeg will then begin to process the video and create the output file with the cropped area.

When the process is complete, you will have a new video file with the cropped area. You can then watch the video to make sure it was cropped correctly.

How to crop an image using FFMPEG?

FFMPEG can also be used to crop images like JPEG, PNG or other image formats.

To crop an image using ffmpeg, you can use the following command:

ffmpeg -i input.jpg -filter:v "crop=w:h:x:y" output.jpg

In this command, input.jpg is the name of the input image file, and output.jpg is the name of the output image file that will be created after cropping.

The -filter:v "crop=w:h:x:y" part of the command specifies the cropping settings. In this part of the command, w is the width of the cropped area, h is the height of the cropped area, x is the horizontal offset of the top left corner of the cropped area, and y is the vertical offset of the top left corner of the cropped area. For example, -filter:v "crop=100:100:50:50" would crop a 100x100 pixel area starting at the coordinates (50, 50) of the input image.

Once you have entered the ffmpeg command with the correct cropping settings, press enter to execute it. FFMPEG will then process the image and create the output file with the cropped area.

When the process is complete, you will have a new image file with the cropped area. You can then view the image to make sure it was cropped correctly.

Other considerations

Here are a few additional things you should know about cropping videos:

Self-evaluation

How do you crop a video using ffmpeg?

Can you use the crop filter to resize a video in ffmpeg?

What is the syntax for the crop filter in ffmpeg?

Published on November 3rd, 2022

Author
David Bosch
David Bosch David is an experienced engineer, now collaborating with JSON2Video.