H264 (1080i) 的 AVCodecContext 设置

发布于 2024-12-20 23:16:22 字数 2216 浏览 1 评论 0原文

我正在尝试配置 x264 以进行 1080i 捕获。下面的大多数设置都可以在不同的示例中找到。然而,编译在一起它们不起作用。 ffmpeg API 没有报告错误,但 avcodec_encode_video() 始终返回零。

有些数字对我来说很奇怪......例如,gop_size。 250是不是太高了?

即使您无法提供最终答案,我仍然对有关此主题的任何评论感兴趣。

pCodecContext->codec_type              = AVMEDIA_TYPE_VIDEO;
pCodecContext->codec_id                = CODEC_ID_H264;

pCodecContext->coder_type              = FF_CODER_TYPE_AC;
pCodecContext->flags                  |= CODEC_FLAG_LOOP_FILTER | CODEC_FLAG_INTERLACED_ME | CODEC_FLAG_INTERLACED_DCT;
pCodecContext->me_cmp                 |= 1;
pCodecContext->partitions             |= X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8;
pCodecContext->me_method               = ME_UMH;
pCodecContext->me_subpel_quality       = 8;
pCodecContext->me_range                = 16;

pCodecContext->bit_rate                = 10 * 1024 * 1024; // 10 Mbps??
pCodecContext->width                   = 1920;
pCodecContext->height                  = 1080;

pCodecContext->time_base.num           = 1;    // 25 fps
pCodecContext->time_base.den           = 25;   // 25 fps

pCodecContext->gop_size                = 250; // 250
pCodecContext->keyint_min              = 25;
pCodecContext->scenechange_threshold   = 40;
pCodecContext->i_quant_factor          = 0.71f;
pCodecContext->b_frame_strategy        = 1;
pCodecContext->qcompress               = 0.6f;
pCodecContext->qmin                    = 10;
pCodecContext->qmax                    = 51;
pCodecContext->max_qdiff               = 4;
pCodecContext->max_b_frames            = 3;
pCodecContext->refs                    = 4;
pCodecContext->directpred              = 3;
pCodecContext->trellis                 = 1;
pCodecContext->flags2                 |= CODEC_FLAG2_WPRED | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP;  // wpred+mixed_refs+dct8x8+fastpskip
pCodecContext->weighted_p_pred         = 2; // not implemented with interlaced ??
pCodecContext->crf                     = 22;

pCodecContext->pix_fmt                 = PIX_FMT_YUV420P;

pCodecContext->thread_count            = 0;

I'm trying to configure x264 for 1080i capturing. Most of these settings below are found in different examples. However, compiled together they don't work. ffmpeg API reports no error, but avcodec_encode_video() always returns zero.

Some of the numbers are strange to me... for example, gop_size. Isn't 250 too high?

Event you can't offer the final answer, I'm still interested in any kind of comment on this subject.

pCodecContext->codec_type              = AVMEDIA_TYPE_VIDEO;
pCodecContext->codec_id                = CODEC_ID_H264;

pCodecContext->coder_type              = FF_CODER_TYPE_AC;
pCodecContext->flags                  |= CODEC_FLAG_LOOP_FILTER | CODEC_FLAG_INTERLACED_ME | CODEC_FLAG_INTERLACED_DCT;
pCodecContext->me_cmp                 |= 1;
pCodecContext->partitions             |= X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8;
pCodecContext->me_method               = ME_UMH;
pCodecContext->me_subpel_quality       = 8;
pCodecContext->me_range                = 16;

pCodecContext->bit_rate                = 10 * 1024 * 1024; // 10 Mbps??
pCodecContext->width                   = 1920;
pCodecContext->height                  = 1080;

pCodecContext->time_base.num           = 1;    // 25 fps
pCodecContext->time_base.den           = 25;   // 25 fps

pCodecContext->gop_size                = 250; // 250
pCodecContext->keyint_min              = 25;
pCodecContext->scenechange_threshold   = 40;
pCodecContext->i_quant_factor          = 0.71f;
pCodecContext->b_frame_strategy        = 1;
pCodecContext->qcompress               = 0.6f;
pCodecContext->qmin                    = 10;
pCodecContext->qmax                    = 51;
pCodecContext->max_qdiff               = 4;
pCodecContext->max_b_frames            = 3;
pCodecContext->refs                    = 4;
pCodecContext->directpred              = 3;
pCodecContext->trellis                 = 1;
pCodecContext->flags2                 |= CODEC_FLAG2_WPRED | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP;  // wpred+mixed_refs+dct8x8+fastpskip
pCodecContext->weighted_p_pred         = 2; // not implemented with interlaced ??
pCodecContext->crf                     = 22;

pCodecContext->pix_fmt                 = PIX_FMT_YUV420P;

pCodecContext->thread_count            = 0;

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

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

发布评论

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

评论(2

绮烟 2024-12-27 23:16:22

您可以分析一些现有的 1080i h264 视频文件以查看其参数。
我发现链接对我很有用:

You could analyze some existing 1080i h264 video files to see their parameters.
I found useful for me that links:

葬心 2024-12-27 23:16:22

您应该努力避免自己设置任何 x264 选项;库本身最了解,并且您只能通过阅读旧源代码得到糟糕的调整。使用 AVOption API 将编码器上的“预设”/“调整”/“配置文件”选项设置为您需要的内容(请参阅x264 --help)。

You should strive to avoid setting any x264 options yourself; the library itself knows best and you'll only get poor tunings from reading old source code. Use the AVOption API to set the "preset"/"tune"/"profile" options on the encoder to what you need (see x264 --help).

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