Darius
Darius

Reputation: 1664

FFMPEG scaling, how to set scale so width AND height don't exceed a certain amount?

I have 2 videos, one is 500 pixels by 100 pixels (just an example, like something recorded sideways on an iphone). And a 1980 x 400 pixels videos. I need the video to convert maintaining aspect ratios. I know of the -vf scale filter such as -vf scale=-1:320, but that only takes the width and scales the height accordingly. My 500 x 100 video would be 320px wide and 1600 pixels tall. That's bad, I need it to be max 500 pixels tall and max width of 320 (just example sizes).

How would I configure the -vf scale function to do that?

Using latest ffmpeg 0.11

Recap: scale any video to max 500 height : 320 width while keeping aspect ratio

Upvotes: 8

Views: 12438

Answers (2)

markshep
markshep

Reputation: 746

To avoid encoding black bands into the video (which the -aspect option does) you can pass a couple of expressions to the scale video filter instead, like this:

-vf scale='if(gt(a,320/500),320,-1)':'if(gt(a,320/500),-1,500)'

Note that the single quotes need to be received by ffmpeg so if you're running the command under a shell you'll need to escape them (e.g. with double quotes round the whole scale=... argument).

(Credit: ffmpeg trac)

Upvotes: 11

av501
av501

Reputation: 6739

You don't need to use vf scale. Just give -s widthxheight and it will scale to that size. For aspect ratio use -aspect Eg. I have a 320x240 file that I want to convert to 360x240 with black bands on the side

ffmpeg -i input.mp4 -acodec copy -vcodec mpeg4 -s 360x240 -aspect 4:3 out.mp4

That's it.

Upvotes: 2

Related Questions