0

We have videos in row format (.mov) that are 4:3 (768x576) and 5:4 (720x576). We have a recommended preset for streaming over DASH to HTML5 and Silverlight players (this is the second pass):

ffmpeg -i input.mp4 -an -vcodec libx264 -profile:v main -pass 2 \
-vf scale=320:180 -pix_fmt yuv420p -g 75 -keyint_min 25 -b:v 384k \
-maxrate 384k -bufsize 384k -passlogfile passlogfile_fp output_320x180_384.mp4 

with 5 more, but different resolution and bitrate:

  • 480:270 -b:v 700k
  • 800:450 -b:v 1300k
  • 960:540 -b:v 1300k
  • 1280:720 -b:v 3500k
  • 1920:1080 -b:v 5000k

With the 4:3 source videos we are happy with the result - the image doesn't get stretched, but players add black border to fit the width. Although we are not sure if this preset is suitable for these source videos.

With the 5:4 we are not really happy, because the image is stretched for 16:9 display. How can we achieve the same effect as with the 4:3 source videos? Are these presets suitable at all for these video formats or should we be looking for something else?

Appreciate your help. Our knowledge about encoding is pretty limited.

1 Answer 1

2

In order to maintain the aspect ratio of the source movie through FFMpeg's scaler, you have to specify a scale with an unknown:

ffmpeg -i input.mp4 -an -vcodec libx264 -profile:v main \
  -pass 2 -vf scale=-1:180 -pix_fmt (etc...)

The "-1" will tell the scaler to make the output 180px high, and however many pixels wide the output must be to preserve it's original aspect ratio.

This would give you movies with the old aspect ratio, you need a way of forcing the original movie into an arbitrary rectangle. The documentation give an example of how you do this:

ffmpeg -i input.mp4 -vf scale="'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'"  

This example will create a movie that is 320x240, and preserves the original pixel aspect ratio, whatever that may be. The output will be positioned against the upper-left corner (I think) so you'll have to do a filter to repo it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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