FFMPEG (libx264)“高度不能被 2 整除" [英] FFMPEG (libx264) "height not divisible by 2"

查看:34
本文介绍了FFMPEG (libx264)“高度不能被 2 整除"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 FFMPEG 使用 libx264 编解码器从一组帧中编码 .mp4 视频.

I am trying to encode a .mp4 video from a set of frames using FFMPEG using the libx264 codec.

这是我正在运行的命令:

This is the command I am running:

/usr/local/bin/ffmpeg -r 24 -i frame_%05d.jpg -vcodec libx264 -y -an video.mp4

我有时会收到以下错误:

I sometimes get the following error:

[libx264 @ 0xa3b85a0] height not divisible by 2 (520x369)

经过一番搜索后,问题似乎与缩放算法有关,可以通过添加 -vf 参数来解决.

After searching around a bit it seems that the issue has something to do with the scaling algorithm and can be fixed by adding a -vf argument.

但是,就我而言,我不想进行任何缩放.理想情况下,我希望尺寸与框架完全相同.有什么建议吗?是否有某种 h264 强制执行的纵横比?

However, in my case I don't want to do any scaling. Ideally, I want to keep the dimensions exactly the same as the frames. Any advice? Is there some sort of aspect ratio that h264 enforces?

推荐答案

原始问题不想缩放视频的答案是:

The answer to the original question which does not want to scale the video is:

-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"

命令:

ffmpeg -r 24 -i frame_%05d.jpg -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -vcodec libx264 -y -an video.mp4 

基本上,.h264 需要偶数维度,因此此过滤器将:

Basically, .h264 needs even dimensions so this filter will:

  1. 将原始高度和宽度除以 2
  2. 四舍五入到最近的像素
  3. 再乘以 2,成为偶数
  4. 添加黑色填充像素至此数字

您可以通过添加过滤器参数:color=white 来更改填充的颜色.请参阅 pad 文档.

You can change the color of the padding by adding filter parameter :color=white. See the documentation of pad.

这篇关于FFMPEG (libx264)“高度不能被 2 整除"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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