Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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"

Source: https://ffmpeg.org/trac/ffmpeg/ticket/309

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 at 15:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.