How to crop and scale correctly with FFMPEG?
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.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on July 05, 2022Comments
-
Admin almost 2 years
I'm trying to remove the TOP AND BOTTOM black bars of a video.
What i'm trying to achieve
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
andscale
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.
-
Admin over 5 yearsHey that worked! Thanks a lot for your time and your help!
-
Tomasz Gandor about 4 yearsWait, how to crop without centering?
-
Alexis Wilke about 3 yearsOne important point to be noted is that the
-filter:v
(or-vf
) option can only be used once. The last one is the one that acts on the data (previous instances are silently ignored).