Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to convert a lot of video files to flash video for our company's website. I have a requirement that all of the videos must be in 360p format, so their size would be Nx360.

FFMpeg uses -s argument to specify target resolution as WxH. I don't know Width, as it depends on source file aspect ratio. If source is 640x480, target will be 480x360. If source is 848x480, target will be 636x360.

Is there a way to do it with some switch of ffmpeg? That it will preserve aspect ratio and I'll only specify the height of target video?

I could easily solve it by making a program that will launch ffprobe to get source video size, calculate aspect ratio and then calculate a new width.

share|improve this question
up vote 14 down vote accepted

You could try adding this video filter:

-vf "scale=-1:360" 

-1 in this case means variable / unknown, thus this filter resizes the video to preserve the aspect ratio of the input, keeping 360 as the height.

For me this achieved the same result you are looking for.

share|improve this answer

Don't have enough points to comment on an existing answer yet, but this is following user65600's answer and going further when specific codecs require a width/height that is divisible by 2 (e.g. libx264)

When you use -1 (variable/unknown), it can return an odd #. To guarantee an even #, you have to use something like trunc(ow/a/2)*2, which'll automatically calculate the closest even # while preserving the aspect ratio.

-vf "scale=trunc(ow/a/2)*2:360"


share|improve this answer

-vf "scale=trunc(ow/a/2)*2:360" doesn't work because of "self-referencing" error.

Instead, the following works :

-vf "scale=-1:360, scale=trunc(iw/2)*2:360"

Self-referencing is thus avoided by two consecutive scaling, and the rounding is done in the second step. Cute, isn't it? :)

share|improve this answer
Simple filtergraph 'scale=-1:480; scale=trunc(iw/2)*2:480' does not have exactly one input and output. Error opening filters! – digitalPBK Apr 3 '14 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .