Take the 2-minute tour ×
Video Production Stack Exchange is a question and answer site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation. It's 100% free, no registration required.

I'm new to this StackExchange site, and to using the ffmpeg encoder. I have a video that is 720x480 (3:2) that I would like to change to 720x406 (16:9) to match the other videos I have for a site. I have tried various command combinations, including:

ffmpeg -i myfile.mv4 -s 720x406 outfile.mp4
ffmpeg -9 myfile.m4v -c copy -aspect 16:9 outfile.mp4

What I end up with is a video that scaled down to the specified height, but didn't preserve the width. It ends up at 608x406 or thereabout. I've been playing with various GUI versions of ffmpeg today, and they seem to do the same thing.

What would be the proper options/parameters to pass in (assuming I'll have more control via the command line) to achieve the desired frame size?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

using the scale filter will do it, but there is a bit more to it.

ffmpeg -i input.mov -vf scale=720x406 output.mov 

will create a movie with the required pixel dimensions, but if you look at the output you'll find that it adds information into the metadata so that it will play back at the same aspect ratio as the original, by using non-square pixels. So if you want to stretch the movie anamorphically to a new aspect ratio you need to manually set the pixel aspect ratio, called the SAR for "Sample Aspect Ratio", thus for square pixels use:

ffmpeg -i input.mov -vf scale=720x406,setsar=1:1 output.mov

Alternatively you can set the display aspect ratio to whatever you want, thus:

ffmpeg -i input.mov -vf scale=720x406,setdar=16:9 output.mov

What I'm doing with the -vf command and the x=y,z=a expressions that follow is creating a chain of filters. Filters can be quite complex, but in the most simple usage they take the form effect=parameter,nexteffect=anotherparameter, and they get processed in the order you write them.

You may want to put additional commands for the codec and so on, eg -c:v libx264 to use the x264 mp4 encoder, and something like -crf 20 to set the constant rate factor to 20 (usually a pretty good compromise between size and quality). So, a reasonably complete command would look like:

ffmpeg -i input.mov -vf scale=720x406,setdar=16:9 -c:v libx264 -preset slow -profile:v main -crf 20 output.mov

Main profile is good for device compatibility, the slow preset for the libx264 encoder is a pretty good balance of speed and quality, so this is a good general web-encoding workhorse. You can make it faster by using fast or veryfast or slower with veryslow and placebo will make it ever so slightly better than veryslow at the expense of a lot more processing time (hence the name).

BTW Don't use -c copy, that means just copy the video and audio streams without doing anything to them at all, so nothing you do in terms of scale, codec, bitrate etc will have any effect.

share|improve this answer
    
Awesome! Worked like a charm. Thank you, stib! –  eljefejb Jan 20 at 17:21
add comment

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.