· ffmpeg til

Cropping a video using FFMPEG

I needed to crop a video that I used as part of a video on my YouTube channel, Learn Data With Mark, and Camtasia kept rendering a black screen. So I had to call for FFMPEG!

Cropping the bottom of a video

My initial video was 2160 x 3840 but I didn’t need the bottom 1920 pixels because I’m using that part of the screen for a video of me. If I was just rendering that video exactly as it is I wouldn’t have bothered cropping it, but because I wanted to zoom into different sections I needed to crop out the bottom bit.

I adapted an example from this article from OTTVerse as my first cut:

ffmpeg -i ConfigSegThresholdDemo.mp4 \
  -filter_complex "[0:v]crop=in_w:in_h-1920:0:0[cropped]" \
  -map "[cropped]" \
  -r output.mp4

This command 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 1920 pixels,

  • and the origin is at [0,0]

This worked, but it lost the quality that I had in the initial video. I fixed this by also passing the qscale flag:

ffmpeg -i ConfigSegThresholdDemo.mp4 \
  -filter_complex "[0:v]crop=in_w:in_h-1920:0:0[cropped]" \
  -map "[cropped]" \
  -qscale 0 \
  -r output.mp4

I think it worked out pretty well, but watch the video and let me know if you agree!

Cropping the top and bottom of a video

For another video that started off 2160 x 3840, I wanted to take off the top 620 pixels and the bottom 370 pixels. I did it by running the following command:

ffmpeg -i PivotDemo.mp4 \
  -filter_complex "[0:v]crop=2160:2850:0:620[cropped]" \
  -map "[cropped]" \
  -qscale 0 \
  PivotDemo-Cropped.mp4

Let’s break down the crop parameters, crop=2160:2850:0:620

  • 2160 - That’s the width of region that I want to crop (i.e. keep the width the same)

  • 2850 - The height of the region that I want to crop (3840 - 620 (top crop) - 370 (bottom crop))

  • 0- The x pixel from where the cropping should begin (i.e. 0 pixels from the left)

  • 620 - The y pixel from where the cropping should begin (i.e. 620 pixels from the top)

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket