Reputation: 117
i currently building an application that converts videos to a specific dimension under consideration of the target aspect ration.
the target resolution must always be 1280x720, i want to fit the uploaded video in this size using black bars.
can anyone point out a formula to calculate the target video dimensions without changing it's aspect ratio? if the target with is smaller then 1280x720 i'll add the missing pixels as black bars.
i'm using ffmpeg with the "-vf scale=1280x720,pad=?:?:black"
command
(sorry if my english is not that great)
Upvotes: 0
Views: 529
Reputation: 11184
Read this page, particularly this section:
Sometimes there is a need to scale the input image in such way it fits into a specified rectangle, i.e. if you have a placeholder (empty rectangle) in which you want to scale any given image. This is a little bit tricky, since you need to check the original aspect ratio, in order to decide which component to specify and to set the other component to -1 (to keep the aspect ratio). For example, if we would like to scale our input image into a rectangle with dimensions of 320x240, we could use something like this:
ffmpeg -i input.jpg -vf scale="'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'" output_320x240_boxed.png
Upvotes: 2