Skip to content

Instantly share code, notes, and snippets.

@Rpsl
Created November 18, 2019 18:35
Show Gist options
  • Save Rpsl/6e65d89cc8c6934f55e6c94a52416990 to your computer and use it in GitHub Desktop.
Save Rpsl/6e65d89cc8c6934f55e6c94a52416990 to your computer and use it in GitHub Desktop.
ffmpeg crop blank lines

1. Get crop parameters

cropdetect can be used to provide the parameters for the crop filter. In this example the first 90 seconds is skipped and 10 frames are processed:

$ ffmpeg -ss 90 -i input.mp4 -vframes 10 -vf cropdetect -f null -
...
[Parsed_cropdetect_0 @ 0x220cdc0] x1:0 x2:1279 y1:0 y2:719 w:1280 h:720 x:0 y:0 pts:215 t:0.215000 crop=1280:720:0:0
[Parsed_cropdetect_0 @ 0x220cdc0] x1:0 x2:1279 y1:0 y2:719 w:1280 h:720 x:0 y:0 pts:257 t:0.257000 crop=1280:720:0:0
[Parsed_cropdetect_0 @ 0x220cdc0] x1:0 x2:1279 y1:0 y2:719 w:1280 h:720 x:0 y:0 pts:299 t:0.299000 crop=1280:720:0:0

So according to cropdetect we can use crop=1280:720:0:0.

2. Preview with ffplay

$ ffplay -vf crop=1280:720:0:0 input.mp4

3. Re-encode using the crop filter

$ ffmpeg -i input.mp4 -vf crop=1280:720:0:0 -c:a copy output.mp4

In this example the audio is just stream copied (re-muxed) since you probably don't need to re-encode it.

Also see FFmpeg and H.264 Video Encoding Guide Crop during playback As you've seen above with the ffplay example some players allow you to crop upon playback. This has the advantage of:

Instant gratification; no need to re-encode The quality is preserved

https://superuser.com/questions/810471/remove-mp4-video-top-and-bottom-black-bars-using-ffmpeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment