FFMPEG-宽度/高度不能被2整除(缩放以生成MBR输出) [英] FFMPEG - Width/ Height Not Divisible by 2 (Scaling to Generate MBR Output)

查看:85
本文介绍了FFMPEG-宽度/高度不能被2整除(缩放以生成MBR输出)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的媒体库(Mp4格式)中生成视频的多种变体,并计划将其再现范围从1080p到240p,以及介于两者之间的流行尺寸.为此,我正在拍摄具有AxB分辨率的视频,然后运行代码(在bash上),将其缩放为所需的以下尺寸-426x240640x360842x4801280x7201920x1080,当然还有不同的比特率,然后再次另存为Mp4.

I am trying to generate multilple variants of videos in my library (Mp4 formats) and have renditions planned ranging from 1080p to 240p and popular sizes in between. For that I am taking a video with a AxB resolution and then running through a code (on bash) which scales them to desired following sizes - 426x240 640x360 842x480 1280x720 1920x1080, with different bitrates of course, and then saves as Mp4 again.

现在,如果源视频的高度和宽度可被2整除,则此方法就很好了,但是对于奇数宽度和高度的视频,代码在下一行中断: -vf scale = w = $ {width}:h = $ {height}:force_original_aspect_ratio =减少"

Now, this works just fine if source video has height and width divisible by 2, but code breaks on the following line for the videos with odd width and height: -vf scale=w=${width}:h=${height}:force_original_aspect_ratio=decrease"

其中宽度"和高度"是每次迭代所需的 (并经过硬编码):"426x240"和"640x360"

Where 'width' and 'height' are the desired (and hardcoded) for every iteration: E.g. "426x240", and "640x360"

错误: [libx264 @ 00000187da2a1580]的宽度不能被2整除(639x360)初始化输出流1:0时出错-打开输出流#1:0的编码器时出错-可能是不正确的参数,例如bit_rate,rate,width或height

现在的方法已经解释过了,因为我正在扩展-这对我不起作用-

Now approaches those are explained in this one doesn't work for me since I am scaling - FFMPEG (libx264) "height not divisible by 2"

而且,我也尝试过这种方法,但似乎所有质量都达到相同的大小-

And, I tried this one too but it seems all qualities are getting the same size -ffmpeg : width not divisible by 2 (when keep proportions)

  • 这就是我尝试使用的方法: scale ='bitand(oh * dar,65534)':'min($ {height},ih)'

请牢记以下建议:1.我的图书馆很大,无法为每个视频进行手动更改2.我需要缩放视频并保持宽高比

Kindly suggest how to solve this, keeping in view that: 1. I have a very large library and I can't do manual change for every video 2. I need to scale the video and keep the aspect ratio

谢谢!

PS:我可以看到的一种方法是预先使用第二个脚本填充所有奇数的身高/体重视频.但是,这会使我的工作时间和工作量加倍.我希望将其保留在单个脚本中.这是我看到的可用于填充的脚本:``ffmpeg -r 24 -i -vcodec libx264 -y -an -vf"pad = ceil(iw/2)* 2:ceil(ih/2)* 2"''(来自:)

PS: One way that I can see is padding all of the odd height/ weight videos using a second script in advance. This however doubles my work time and load. I would prefer to keep it in single script. This is the script I see that I can use for padding: ```ffmpeg -r 24 -i -vcodec libx264 -y -an -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"`` (from: FFMPEG (libx264) "height not divisible by 2")

推荐答案

您可以在比例尺后面插入一个垫块或作物过滤器,具体取决于您是希望分别增大还是减小尺寸.

You can insert either insert a pad or crop filter after the scale, depending on whether you prefer dimensions to increase or decrease respectively.

例如用于护垫,

scale=w=...,pad='iw+mod(iw\,2)':'ih+mod(ih\,2)'"

例如作物

scale=w=...,crop='iw-mod(iw\,2)':'ih-mod(ih\,2)'"

这篇关于FFMPEG-宽度/高度不能被2整除(缩放以生成MBR输出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆