Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to crop and scale correctly with FFMPEG?

Tags:

scale

ffmpeg

crop

I'm trying to remove the TOP AND BOTTOM black bars of a video.

Image sample from video image

What i'm trying to achieve

image

The video itself is 1280x720 16:9, but the portion that's image information is at 4:3 since it's been captured from a VHS. I want to somehow stretch it until the top bars disappear without deforming the image. I don't care about the left and right bars.

I tried using crop and scale with no luck.

By using this code the top and bottom black bars disappeared on VLC when on normal screen but when going Full Screen the bars appeared again.

ffmpeg -i test.avi -filter:v "crop=1280:670" output_video.mp4

I thought it had something to do with the Scale of the video but honestly every scale code I tried to use deformed the image a lot.

I hope someone can help me, fairly new to FFMPEG but really enjoying it this far.

like image 312
Rivera A. Pablo Avatar asked Oct 05 '18 21:10

Rivera A. Pablo


1 Answers

I got your image, resized it to 720p, made a 30 second video to test.

In my example I've also cropped the edges (left/right) because as @LordNeckbeard mentioned, when they hit the side of your screen, they may prevent the top/bottom of the video from reaching the top/bottom of the screen, which will again, look like black bars at the top/bottom, whether they are there or not.

This worked for me:

ffmpeg -y -hide_banner -i "test.avi" -filter:v "crop=iw-400:ih-40,scale=960:720" -pix_fmt yuv420p output_video.mp4

Quick explanation:

crop=iw-400:ih-40 Cropping 400 from the input width (iw) (2x200 left/right) Cropping 40 from the input height (ih) (2x20 top/bottom) You can cut a little more off if you want a 'crisper' edge.

scale=960:720 Scaling the video slightly to bring it back to your original 720p, the 960 is to keep it at a nice 4x3 ratio. This scaling is not needed, your preference.

Let me know if it worked for you.

like image 132
video.baba Avatar answered Oct 02 '22 22:10

video.baba