根据条件改变分辨率的ffmpeg

3

我想使用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

你不想使用任何编程语言?那么你可能问错了地方。 - Grady Player
2个回答

3

在您的命令中使用此过滤器:

-filter_complex "scale=if(gt(iw,852),852,-1)':'if(gt(ih,480),480,-1)':force_original_aspect_ratio=decrease"

1

@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)]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接