我想用ffmpeg改变我的视频分辨率:
-s 852×480
如果视频宽度或高度大于852×480,我该怎么办?
我想用 ffmpeg 这样的东西,而不是我的编程语言:
if video.width > 852:
resize width and proportionally resize height
if video.height > 480:
resize height and proportionally resize width
if video.width > 852 and video.height > 480:
resize height width
答案 0 :(得分:0)
@LordNeckbeard给了我一个链接https://superuser.com/questions/566998/how-can-i-fit-a-video-to-a-certain-size-but-dont-upscale-it-with-ffmpeg/567934#567934 - 但它确实是一个混乱的解决方案。
所以我只是用python做了:
maximal_width = 852.0
maximal_height = 480.0
if width > maximal_width and height > maximal_height:
args += ['-vf', 'scale=%s:%s' % (maximal_width, maximal_height)]
else:
if width > maximal_width:
coefficient = width / maximal_width
calculated_height = height / coefficient
args += ['-vf', 'scale=%s:%s' % (maximal_width, calculated_height)]
if height > maximal_height:
coefficient = height / maximal_height
calculated_width = width / coefficient
args += ['-vf', 'scale=%s:%s' % (calculated_width, maximal_height)]
答案 1 :(得分:0)
在命令中使用此过滤器:
-filter_complex "scale=if(gt(iw,852),852,-1)':'if(gt(ih,480),480,-1)':force_original_aspect_ratio=decrease"