我目前正在构建一个应用程序,在考虑目标宽高比的情况下将视频转换为特定尺寸。
目标分辨率必须始终为 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
关于video - 计算目标宽高比的视频尺寸的公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29805636/