使用 avcodec/H264 编码实时视频时
我想使用 avcodec/H264 对实时视频进行编码。 我尝试了一些设置参数。
m_pCodec = avcodec_find_encoder(CODEC_ID_H264);
m_pCodecCtx = avcodec_alloc_context3(m_pCodec);
m_pCodecCtx->coder_type=1;
m_pCodecCtx->flags|=CODEC_FLAG_LOOP_FILTER;
m_pCodecCtx->me_cmp |= FF_CMP_CHROMA;
m_pCodecCtx->partitions|=X264_PART_I8X8+X264_PART_I4X4+X264_PART_P8X8+X264_PART_B8X8; // partitions=+parti8x8+parti4x4+partp8x8+partb8x8
m_pCodecCtx->me_method=ME_HEX;
m_pCodecCtx->me_subpel_quality = 6;
m_pCodecCtx->me_range=16;
m_pCodecCtx->gop_size=30;
m_pCodecCtx->keyint_min=10;
m_pCodecCtx->scenechange_threshold=40;
m_pCodecCtx->i_quant_factor=0.71;
m_pCodecCtx->b_frame_strategy=1;
m_pCodecCtx->qcompress=0.6;
m_pCodecCtx->qmin=10;
m_pCodecCtx->qmax=51;
m_pCodecCtx->max_qdiff=4;
m_pCodecCtx->max_b_frames=1;
m_pCodecCtx->refs=2;
m_pCodecCtx->directpred=3;
m_pCodecCtx->trellis=1;
m_pCodecCtx->flags2|=CODEC_FLAG2_BPYRAMID|CODEC_FLAG2_WPRED|CODEC_FLAG2_8X8DCT|CODEC_FLAG2_FASTPSKIP;// +bpyramid+wpred+dct8x8+fastpskip
m_pCodecCtx->width = 720;
m_pCodecCtx->height = 480;
m_pCodecCtx->time_base.num = 1;
m_pCodecCtx->time_base.den = 15;
m_pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
有用。解码方面很好。 但框架尺寸太大。 I帧和P帧约25万字节,不制作B帧。 怎么了?
谢谢。
I want to encode live video whith avcodec/H264.
I tryed with some setting params.
m_pCodec = avcodec_find_encoder(CODEC_ID_H264);
m_pCodecCtx = avcodec_alloc_context3(m_pCodec);
m_pCodecCtx->coder_type=1;
m_pCodecCtx->flags|=CODEC_FLAG_LOOP_FILTER;
m_pCodecCtx->me_cmp |= FF_CMP_CHROMA;
m_pCodecCtx->partitions|=X264_PART_I8X8+X264_PART_I4X4+X264_PART_P8X8+X264_PART_B8X8; // partitions=+parti8x8+parti4x4+partp8x8+partb8x8
m_pCodecCtx->me_method=ME_HEX;
m_pCodecCtx->me_subpel_quality = 6;
m_pCodecCtx->me_range=16;
m_pCodecCtx->gop_size=30;
m_pCodecCtx->keyint_min=10;
m_pCodecCtx->scenechange_threshold=40;
m_pCodecCtx->i_quant_factor=0.71;
m_pCodecCtx->b_frame_strategy=1;
m_pCodecCtx->qcompress=0.6;
m_pCodecCtx->qmin=10;
m_pCodecCtx->qmax=51;
m_pCodecCtx->max_qdiff=4;
m_pCodecCtx->max_b_frames=1;
m_pCodecCtx->refs=2;
m_pCodecCtx->directpred=3;
m_pCodecCtx->trellis=1;
m_pCodecCtx->flags2|=CODEC_FLAG2_BPYRAMID|CODEC_FLAG2_WPRED|CODEC_FLAG2_8X8DCT|CODEC_FLAG2_FASTPSKIP;// +bpyramid+wpred+dct8x8+fastpskip
m_pCodecCtx->width = 720;
m_pCodecCtx->height = 480;
m_pCodecCtx->time_base.num = 1;
m_pCodecCtx->time_base.den = 15;
m_pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
It works. Decoding side is well.
But the frame size is too large.
I-frame and P-frame is about 250,000 bytes, and B-frame is not made.
What's wrong?
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
当我手动设置参数时,我也遇到了问题。当我使用配置文件而不是设置您列出的所有选项时,我的问题得到了解决:
之后您可以使用 crf 设置恒定质量,例如:
然后像您一样设置选项宽度、高度、time_base 和 pix_fmt 。
希望有帮助!
I had problems with the parameters when I set them manually as well. My problem was solved when I used a profile instead of setting all the options you listed:
After that you can set constant quality with crf, e.g.:
Then you set the options width, height, time_base and pix_fmt like you did.
Hope it helps!