7

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

Darius
  • 1,613
  • 5
  • 29
  • 58

2 Answers2

9

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)

markshep
  • 728
  • 7
  • 17
3

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.

av501
  • 6,645
  • 2
  • 23
  • 34
  • Appreciate the response. The black bands add to the filesize though, wouldn't keeping the original file without the blackbands produce a smaller file? – Darius Aug 28 '12 at 05:03
  • Well blackbands dont really take much to encode. So dont worry about them. Besides they came in only because we asked the encoder to create them. If you want to maintain the aspect ratio you are going to get black bands. – av501 Aug 28 '12 at 05:19