使用FFmpeg保持宽高比

使用FFmpeg保持宽高比

本文介绍了使用FFmpeg保持宽高比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用FFmpeg转换一堆视频文件.我运行了一个Bash文件,可以很好地转换所有文件,但是如果转换后的文件不是16:9格式,则会出现问题.

I need to convert a bunch of video files using FFmpeg. I run a Bash file that converts all the files nicely, however there is a problem if a file converted is not in 16:9 format.

当我将屏幕尺寸固定为-s 720x400时,如果原始图片的宽高比为4:3,则FFmpeg会创建一个16:9的输出文件,搞砸了宽高比.

As I am fixing the size of the screen to -s 720x400, if the aspect ratio of the original is 4:3, FFmpeg creates a 16:9 output file, screwing up the aspect ratio.

是否有设置可以将长宽比作为主要参数,并且可以调整尺寸(例如,仅通过固定X或Y尺寸)?

Is there a setting that allows setting an aspect ratio as the main parameter, with size being adjusted (for example, by fixing an X or Y dimension only)?

推荐答案

我很久以前就问过这个问题,但实际上我有一个当时不为人知的解决方案-为了保持宽高比,则应使用视频滤镜比例,这是一个非常强大的滤镜.

I've asked this a long time ago, but I've actually got a solution which was not known to me at the time -- in order to keep the aspect ratio, you should use the video filter scale, which is a very powerful filter.

您可以像这样简单地使用它:

You can simply use it like this:

-vf "scale=640:-1"

将固定宽度并提供保持长宽比所需的高度.但是您还可以使用许多其他选项甚至数学函数,请在此处查看文档- http://ffmpeg.org /ffmpeg.html#scale

Which will fix the width and supply the height required to keep the aspect ratio. But you can also use many other options and even mathematical functions, check the documentation here - http://ffmpeg.org/ffmpeg.html#scale

这篇关于使用FFmpeg保持宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:05