x264编码参数设置

H264Encoder *pEn = (H264Encoder *)    AllocBuffer(sizeof(H264Encoder));
pEn->param       = (x264_param_t *)   AllocBuffer(sizeof(x264_param_t));
x264_param_default(pEn->param);			//set default param

/*设置profile属性*/
//x264_profile_names数组定义如下:static const char * const x264_profile_names[] = 
//{ "baseline", "main", "high", "high10", "high422", "high444", 0 };
x264_param_apply_profile(pEn->param,x264_profile_names[0]);


pEn->param->i_csp                = X264_CSP_I420;// 设置帧数据格式为420
pEn->param->i_width			 = m_nPicW;		 // 设置帧宽度
pEn->param->i_height			 = m_nPicH;		 // 设置帧高度
pEn->param->rc.i_lookahead		 = 0;            

pEn->param->i_fps_num			 = m_nFps;       // 设置帧率(分子)
pEn->param->i_fps_den			 = 1;            // 设置帧率时间1s(分母)

pEn->param->rc.i_bitrate	     = m_nBitrate;   // 设置码率
pEn->param->rc.i_vbv_max_bitrate = pCodecParam->encoder.iMaxBitrate; // 设置平均码率模式下,最大瞬时码率
pEn->param->i_keyint_max         = m_nFps * 2;   // 设置GOP最大长度
pEn->param->i_keyint_min         = m_nFps * 2;   // 设置GOP最小长度

pEn->param->pf_log = x264_log;	                 // 设置打印日志回调
pEn->param->p_log_private = NULL;
pEn->param->i_log_level = X264_LOG_WARNING;
pEn->param->b_vfr_input = 0;                     // 1:使用timebase和时间戳做码率控制 0:只使用fps做码率控制

pEn->param->i_timebase_num = 1;                  // timebase(分子)
pEn->param->i_timebase_den = 1000;               // timebase(分母)

pEn->param->b_repeat_headers = 0;                // 1:在每个关键帧前面放sps和pps
pEn->param->i_threads = 1;                       // 并行编码多个帧线程数
pEn->param->rc.i_rc_method       = X264_RC_ABR;  // 码率控制方法,CQP(恒定质量),CRF(恒定码率),ABR(平均码率)
pEn->param->rc.i_vbv_buffer_size = pCodecParam->encoder.iMaxBitrate; //码率控制缓冲区的大小,单位kbit,默认0

pEn->handle = x264_encoder_open(pEn->param);     // 创建一个新的编码器句柄

你可能感兴趣的:(音视频基础)