开发者

when encoding live video with avcodec/H264

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->qcompres开发者_开发百科s=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.


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:

m_pCodecCtx->profile = FF_PROFILE_H264_BASELINE;

After that you can set constant quality with crf, e.g.:

m_pCodecCtx->crf = 28;

Then you set the options width, height, time_base and pix_fmt like you did.

Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜