如何使用 libavcodec/x264 编码 h.264?
我正在尝试使用 libavcodec/libavformat 对视频进行编码。音频效果很好,但是当我尝试对视频进行编码时,出现以下错误:
[libx264 @ 0x10182a000]broken ffmpeg default settings detected
[libx264 @ 0x10182a000]use an encoding preset (vpre)
使用命令行 ffmpeg 很容易修复,但我正在尝试在 C 中执行此操作。 我的选择是
AVStream *pVideoOutStream = av_new_stream(pOutFormatCtx, 0);
AVCodecContext *pVideoOutCodecCtx = pVideoOutStream->codec;
pVideoOutCodecCtx->codec_id = CODEC_ID_H264;
pVideoOutCodecCtx->codec_type = CODEC_TYPE_VIDEO;
pVideoOutCodecCtx->bit_rate = pVideoInCodecCtx->bit_rate;
pVideoOutCodecCtx->width = pVideoInCodecCtx->width;
pVideoOutCodecCtx->height = pVideoInCodecCtx->height;
pVideoOutCodecCtx->pix_fmt = pVideoInCodecCtx->pix_fmt;
pVideoOutCodecCtx->sample_rate = pVideoInCodecCtx->sample_rate;
pVideoOutCodecCtx->gop_size = 30;
,但 avcodec_open() 失败。
我还需要设置哪些其他值才能使 x264 满意?
I am attempting to encode video using libavcodec/libavformat. Audio works great, but when I try to encode video I get the following errors:
[libx264 @ 0x10182a000]broken ffmpeg default settings detected
[libx264 @ 0x10182a000]use an encoding preset (vpre)
easy to fix using the command line ffmpeg, but I am trying to do this in C.
my options are
AVStream *pVideoOutStream = av_new_stream(pOutFormatCtx, 0);
AVCodecContext *pVideoOutCodecCtx = pVideoOutStream->codec;
pVideoOutCodecCtx->codec_id = CODEC_ID_H264;
pVideoOutCodecCtx->codec_type = CODEC_TYPE_VIDEO;
pVideoOutCodecCtx->bit_rate = pVideoInCodecCtx->bit_rate;
pVideoOutCodecCtx->width = pVideoInCodecCtx->width;
pVideoOutCodecCtx->height = pVideoInCodecCtx->height;
pVideoOutCodecCtx->pix_fmt = pVideoInCodecCtx->pix_fmt;
pVideoOutCodecCtx->sample_rate = pVideoInCodecCtx->sample_rate;
pVideoOutCodecCtx->gop_size = 30;
but avcodec_open() fails.
What other values do I need to set to make x264 happy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不要忘记使用 x264 私有选项。
您始终可以设置配置文件:
或设置最低编码延迟:
或选择预设:
在打开编解码器之前
Don't forget to use x264 private options.
You can always set a profile:
Or set the lowest encoding latency:
Or select a preset:
Before opening a codec
下面是如何解读ffmpeg的x264预设。
不幸的是,我不知道像 ffmpeg 那样导入预设的简单方法。
您可以查找全部存储在 /usr/local/share/ffmpeg/libx264-{name}.ffpreset 中的 x264 预设值,其中 {name} 为 ffmpeg 指定为 -vpre {name} 命令行参数。
因此,通常 ffmpeg 会包含 libx264-medium.ffpreset,然后包含 libx264-main.ffpreset,指定为 ffmpeg -vpremedium -vpre main
您可以查找所有选项(如 libx264-{name}.ffpreset 文件中定义)以获取它们通过查看 libavcodec/options.c 文件来了解结构名称,该文件可以在 ffmpeg SVN 存储库中找到。
以下是如何将中型和主要预设转换为 C 代码:
如果您想自动解析这些预设,则必须查看 ffmpeg 源代码。
我希望我刚才提供的信息能给您带来更多帮助:)
The following is how to interpret the ffmpeg's x264 presets.
Unfortunately I don't know of an easy way to import the presets like ffmpeg does.
You can lookup the x264 preset values which are all stored in /usr/local/share/ffmpeg/libx264-{name}.ffpreset, where {name} is specified for ffmpeg as the -vpre {name} command-line argument.
So typically ffmpeg would include libx264-medium.ffpreset and then libx264-main.ffpreset, specified as ffmpeg -vpre medium -vpre main
You can lookup all the options (as defined in the libx264-{name}.ffpreset files) to get their structure names by looking in the libavcodec/options.c file, which can be found in the ffmpeg SVN repositories.
Here's how the medium and main presets would be translated into C code:
You'll have to look at the ffmpeg source code if you want to parse those presets automatically.
I hope that the information I just gave would help you out a bit more :)
不确定你是否能正常工作,但以下参数对我有用。
错误消息
检测到损坏的 ffmpeg 默认设置
显示在 x264/encoder/encoder.c 当默认 ffmpeg 设置过多时(例如qmin = 2, qmax = 31, qcompress = 0.5< /code>),将这三个值更改为其他值,例如
qmin = 10、qmax = 51、qcompress = 0.6
,即可解决该错误。Not sure whether you got it working, but the following parameters work for me.
The error message
broken ffmpeg default settings detected
is displayed in the x264 library in x264/encoder/encoder.c when too many settings are the default ffmpeg settings (e.g.qmin = 2, qmax = 31, qcompress = 0.5
), changing these three values to something else, e.g.qmin = 10, qmax = 51, qcompress = 0.6
, resolves the error.我使用不同的编解码器将 YUV420P 图片编码为不同的格式。使用guess_format(...) 函数后,我从 AVOutputFormat 获取了 CodecID。但其他编解码器设置是
(所有这些都取自 ffmpeg 示例的源代码):
此设置必须适用于大多数编解码器,但我遇到了 fps 问题:并非所有编解码器都支持任何 fps 值(以及其他一些参数)。
I encode YUV420P pictures into different formats, using different codecs. CodecID I took from AVOutputFormat after using guess_format(...) function. But other codec settings are
(All of them has been taken from ffmpeg examples' source code):
This setting must work to most codecs, but I had a problem with fps: not all codecs supports any fps values (and some other parameters too).
似乎 ffmpeg 版本 20130302 需要类似的东西
seems that the ffmpeg version 20130302 requires something like