计算目标宽高比的视频尺寸的公式
formula to calculate video dimensions for target aspect ratio
我目前正在构建一个应用程序,在考虑目标宽高比的情况下将视频转换为特定尺寸。
目标分辨率必须始终为 1280x720,我想使用黑条适合此尺寸的上传视频。
谁能指出一个公式来计算目标视频尺寸而不改变它的宽高比?如果目标小于 1280x720,我会将缺失的像素添加为黑条。
我正在使用带有 "-vf scale=1280x720,pad=?:?:black"
命令的 ffmpeg
(对不起,如果我的英语不是很好)
阅读 this 页,尤其是这一部分:
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
我目前正在构建一个应用程序,在考虑目标宽高比的情况下将视频转换为特定尺寸。
目标分辨率必须始终为 1280x720,我想使用黑条适合此尺寸的上传视频。
谁能指出一个公式来计算目标视频尺寸而不改变它的宽高比?如果目标小于 1280x720,我会将缺失的像素添加为黑条。
我正在使用带有 "-vf scale=1280x720,pad=?:?:black"
命令的 ffmpeg
(对不起,如果我的英语不是很好)
阅读 this 页,尤其是这一部分:
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