ffmpeg (libavcodec) 警告:编码帧太大

发布于 2024-09-26 00:37:53 字数 420 浏览 9 评论 0原文

我正在尝试使用 libavcodec (ffmpeg) 将原始像素数据编码为 mp4 格式。一切都很顺利,我得到了质量不错的 .avi 文件,但有时编解码器会发出“编码帧太大”警告。当它这样做时,某些框架的一部分(通常是框架的底部)看起来乱码或全部混合在一起。谁能告诉我这个警告是什么时候发出的?以下是我用于编码器的设置:

qmax = 6;
qmin = 2;
bit_rate = 200000; // if I increase this, I get more warnings. 
width = 1360;
height = 768;
time_base.den = 15; // frames per second
time_base.num = 1;
gop_size = 48;
pix_fmt = PIX_FMT_YUV420P;

问候,

I'm trying to use libavcodec (ffmpeg) to encode raw pixel data to mp4 format. Every thing goes well and I'm getting .avi file with decent quality but some times the codec gives "encoded frame too large" warning. And when ever it does that, a part of some frames (usually bottom portion of the frame) look garbled or all mixed up. Can any one tell me when this warning is given. Following are the settings I'm using for encoder:

qmax = 6;
qmin = 2;
bit_rate = 200000; // if I increase this, I get more warnings. 
width = 1360;
height = 768;
time_base.den = 15; // frames per second
time_base.num = 1;
gop_size = 48;
pix_fmt = PIX_FMT_YUV420P;

Regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事↓在人 2024-10-03 00:37:53

据我所知,ffmpeg 分配一个 2MB 的恒定缓冲区大小来保存压缩的
框架。例如,1080p 未压缩时为 3MB,编解码器无法始终将大帧压缩为小于 2MB。

您可以通过增加缓冲区大小和/或使其动态来解决此问题。

From what I can gather ffmpeg allocates a constant buffer size of 2MB to hold a compressed
frame. 1080p is 3MB uncompressed for example, and the codec can't always compress a large frame into less than 2MB.

You can possibly fix this by increasing the buffer size, and/or making it dynamic.

静谧 2024-10-03 00:37:53

很可能编解码器的缓冲区不够大。尝试更改 rc_buffer_size。或者,您可以尝试以下设置:

ctx->bit_rate = 500000;
ctx->bit_rate_tolerance = 0;
ctx->rc_max_rate = 0;
ctx->rc_buffer_size = 0;
ctx->gop_size = 40;
ctx->max_b_frames = 3;
ctx->b_frame_strategy = 1;
ctx->coder_type = 1;
ctx->me_cmp = 1;
ctx->me_range = 16;
ctx->qmin = 10;
ctx->qmax = 51;
ctx->scenechange_threshold = 40;
ctx->flags |= CODEC_FLAG_LOOP_FILTER;
ctx->me_method = ME_HEX;
ctx->me_subpel_quality = 5;
ctx->i_quant_factor = 0.71;
ctx->qcompress = 0.6;
ctx->max_qdiff = 4;
ctx->directpred = 1;
ctx->flags2 |= CODEC_FLAG2_FASTPSKIP;

Very probably that codec's buffer is not big enough. Try to change rc_buffer_size. Alternatively, you can try this settings:

ctx->bit_rate = 500000;
ctx->bit_rate_tolerance = 0;
ctx->rc_max_rate = 0;
ctx->rc_buffer_size = 0;
ctx->gop_size = 40;
ctx->max_b_frames = 3;
ctx->b_frame_strategy = 1;
ctx->coder_type = 1;
ctx->me_cmp = 1;
ctx->me_range = 16;
ctx->qmin = 10;
ctx->qmax = 51;
ctx->scenechange_threshold = 40;
ctx->flags |= CODEC_FLAG_LOOP_FILTER;
ctx->me_method = ME_HEX;
ctx->me_subpel_quality = 5;
ctx->i_quant_factor = 0.71;
ctx->qcompress = 0.6;
ctx->max_qdiff = 4;
ctx->directpred = 1;
ctx->flags2 |= CODEC_FLAG2_FASTPSKIP;
桃扇骨 2024-10-03 00:37:53

在示例代码中,我发现类似以下内容:

outbuf_size = 100000;
outbuf = malloc(outbuf_size);

[...]

out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);

outbuf_size 推得更大可以解决问题。

In the example code I found something like:

outbuf_size = 100000;
outbuf = malloc(outbuf_size);

[...]

out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);

Pushing outbuf_size to be larger resolved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文