应用X264进行H.264编码,如果编码不能成功,大部分情况是编码参数选择不正确 请看图片: 这里边的编码参数大家应该看到了吧,那么如果我们用ffmpeg怎么设置这些编码参数呢? 代码为证: m_VCtx->codec_type = CODEC_TYPE_VIDEO; m_VCtx->bit_rate = bitrate * 1000; m_VCtx->width = width; m_VCtx->height = height; m_VCtx->time_base.den = fps; m_VCtx->time_base.num = 1; m_VCtx->gop_size = fps * 10; //m_VCtx->gop_size = 1; m_VCtx->crf = 26; m_VCtx->refs = 3; m_VCtx->flags2 = CODEC_FLAG2_MIXED_REFS; m_VCtx->max_b_frames = 3; m_VCtx->deblockbeta = -1; m_VCtx->deblockalpha = -1; m_VCtx->trellis = 2; m_VCtx->partitions = X264_PART_I4X4 | X264_PART_I8X8 | X264_PART_P8X8 | X264_PART_P4X4 | X264_PART_B8X8; m_VCtx->flags2 |= CODEC_FLAG2_8X8DCT; m_VCtx->me_method = 8; m_VCtx->me_range = 16; m_VCtx->me_subpel_quality = 7; m_VCtx->qmin = 10; m_VCtx->qmax = 51; m_VCtx->rc_initial_buffer_occupancy = 0.9; m_VCtx->i_quant_factor = 1.0 / 1.40f; // x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); m_VCtx->b_quant_factor = 1.30f; m_VCtx->chromaoffset = 0; m_VCtx->max_qdiff = 4; m_VCtx->qcompress = 0.6f; m_VCtx->complexityblur = 20.0f; m_VCtx->qblur = 0.5f; m_VCtx->directpred = 1; m_VCtx->noise_reduction = 0; m_VCtx->pix_fmt = PIX_FMT_YUV420P; m_VCtx->thread_count = 1; m_VCtx->scenechange_threshold = 40; m_VCtx->bframebias = 0; m_VCtx->flags2 |= CODEC_FLAG2_AUD; m_VCtx->coder_type = FF_CODER_TYPE_AC; m_VCtx->flags |= CODEC_FLAG_LOOP_FILTER; m_VCtx->me_cmp = FF_CMP_CHROMA; m_VCtx->flags2 |= CODEC_FLAG2_FASTPSKIP; m_VCtx->flags2 |= CODEC_FLAG2_BPYRAMID; m_VCtx->flags2 |= CODEC_FLAG_NORMALIZE_AQP; m_VCtx->flags2 |= CODEC_FLAG2_WPRED; m_VCtx->keyint_min = 25; m_VCtx->flags2 |= CODEC_FLAG2_MBTREE; // m_VCtx->rc_min_rate =1024 * 1000; // m_VCtx->rc_max_rate = 1024 * 1000; // m_VCtx->bit_rate_tolerance = 1024 * 1000; // m_VCtx->rc_buffer_size=1024 * 1000; // m_VCtx->rc_initial_buffer_occupancy = m_VCtx->rc_buffer_size*3/4; // m_VCtx->rc_buffer_aggressivity= (float)1.0; // m_VCtx->rc_initial_cplx= 0.5; //m_VCtx->ticks_per_frame = 2; m_VCtx->level = 30; m_VCtx->b_frame_strategy = 2; m_VCtx->codec_tag = 7; // FLV must not = 0 {CODEC_ID_H264, FLV_CODECID_H264 },