Tuesday 3 July 2018

How to resize a video to make it smaller with FFmpeg


Is it possible to resize my videos to make them smaller with FFmpeg?


I have an original video dimensions of 1024x576, now I want to resize the video to 720x480 to meet the requirement.


How can I do this?



Answer



The most basic example is this:


ffmpeg -i input.avi -s 720x480 -c:a copy output.mkv

Using the scale filter will provide more flexibility:


ffmpeg -i input.avi -filter:v scale=720:-1 -c:a copy output.mkv

The -1 will tell ffmpeg to automatically choose the correct height in relation to the provided width to preserve the aspect ratio. -1 can also be used for width if you provide a given height.




One downside of scale when using libx264 is that this encoder requires even values and scale may automatically choose an odd value resulting in an error: width or height not divisible by 2. You can tell scale to choose an even value for a given height (720 in this example):


scale="trunc(oh*a/2)*2:720"

...or a given width (1280 in this example):


scale="1280:trunc(ow/a/2)*2"

Note that your ffmpeg build could complain about not recognizing -c or -filter options. It also may not support scale. In that case you should use a newer ffmpeg, which you can download as a static build, or compile yourself.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...