video - 计算目标宽高比的视频尺寸的公式

标签 video ffmpeg formula aspect-ratio dimension

我目前正在构建一个应用程序,在考虑目标宽高比的情况下将视频转换为特定尺寸。

目标分辨率必须始终为 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/

相关文章:

android - 如何使用变量从原始文件夹访问视频?

java - 以编程方式从 youtube 和其他音乐网站下载 mp3 Java

ffmpeg - 如何使用 ffmpeg 流式传输到多个目的地

video - 结合来自ffmpeg的两个视频

重新制定 R log(Y+1)

excel - 可以水平过滤吗?

Php附近的地方脚本帮助

c++ - 在实时视频上检测 SURF 点

c - 使用ffmpeg c连接视频和音频时如何计算pts和dts

nginx - 用于实时流媒体的 MPEG-DASH 编码