13

I have a video with that is 480x360 in resolution, what I want to do is upscale this video to 1280:720 and not loos the original videos aspect ration ( letterbox the left and right side)

So I know people can achieve this task with ffmpeg but so far I am not able to do so

So can someone share a ffmpeg commend with me ??

Thank you very much for your help

0

1 Answer 1

27
ffmpeg -i input.mp4 -vf "scale=(iw*sar)*min(1280/(iw*sar)\,720/ih):ih*min(1280/(iw*sar)\,720/ih), pad=1280:720:(1280-iw*min(1280/iw\,720/ih))/2:(720-ih*min(1280/iw\,720/ih))/2" output.mp4

Let me break down this command for you:

ffmpeg -i input.mp4

This is the standard input method for ffmpeg. Replace "input.mp4" with the name of your input file.

-vf

Specifies that some video filters follow in the command. The video filters that are specified are applied sequentially to each frame.

scale=(iw*sar)*min(1280/(iw*sar)\,720/ih):ih*min(1280/(iw*sar)\,720/ih)

The first filter is the scale filter. The scale filter is powerful because it can perform value substitution and math. In this case, the math computes the new scaled width and height. It will scale the input image to fit the width and/or height of the desired output format without distorting the image. You don't need to make any modifications to the scale parameters because it will automatically substitute the actual values for "iw", "sar" and "ih". In your case, since your input video is 4x3, we know that the math will work out to scale to a height of 720 but a width that is less than 1280. More info: https://ffmpeg.org/ffmpeg-filters.html#scale-1

pad=1280:720:(1280-iw*min(1280/iw\,720/ih))/2:(720-ih*min(1280/iw\,720/ih))/2

The second filter is the pad filter. It has the same math/substitution features as the scale feature. So it will figure out the exact numbers for you. You don't need to change anything to make it work. The parameters tell the pad filter to make the output 720x1280 and to place the input image in the center of the frame. The pad filter will fill the output image with black anywhere that the input image doesn't cover. In the case of your input, we know that the scale filter scaled the height to 720, but the width is short of 1280. So black bars will be added to the sides to make up the difference. More info: https://ffmpeg.org/ffmpeg-filters.html#pad

output.mp4

This specifies the output file where ffmpeg will place the results. You may need to add all kinds of parameters for format, bitrate, etc. to meet your exact needs.

5
  • Thank you very much for the reply but I van you explain this command a bit more, are this two different commands that I can use scale or pad or they both should be used at the same time ? and in (iw*sar) should I write something in them ? Thank you
    – Levan
    Commented Mar 19, 2015 at 15:54
  • 1
    I edited the answer to provide more detail about the command. Bottom line: It is a single command. the only thing you should change are "input.mp4" and "output.mp4" as appropriate for your desired source and destination.
    – Brian
    Commented Mar 19, 2015 at 16:55
  • 2
    By the way, there is a very similar Q/A here: superuser.com/questions/547296/…
    – Brian
    Commented Mar 19, 2015 at 17:01
  • I had to add -aspect 16:9 aspect ratio argument force an exact 16:9 metadata flag. I realized it was a tiny bit something else after running an input file through mp4box dash splitter.
    – Whome
    Commented Jul 5, 2017 at 17:02
  • PERFECT ANSWER. I've been struggling to upscale and pad my videos correctly but this does precisely that.
    – hedgehog90
    Commented Mar 6, 2020 at 18:02

You must log in to answer this question.

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