声明 x264_param_t 结构体变量:
x264_param_t params;
x264_param_default_preset(¶ms, "ultrafast", "zerolatency");//优化编码延迟?
变量参数编码前赋值:
params.i_csp = (csp == 17) ? X264_CSP_NV12 : csp;//编码比特流的CSP,仅支持i420,色彩空间设置 #ifdef SQUARE_AND_ROTATE params.i_width = w; params.i_height = h; #else params.i_width = width; params.i_height = height; #endif params.vui.i_sar_width = 1; params.vui.i_sar_height = 1; //设置长宽比 params.i_fps_num = fpsnum;//帧率分子 params.i_fps_den = fpsden;//帧率分母 params.i_timebase_num = 1; params.i_timebase_den = 1000;//ms params.i_keyint_max = fpsnum/fpsden; params.i_keyint_min = fpsnum/fpsden;//X264_KEYINT_MIN_AUTO params.b_repeat_headers = 0;// params.b_annexb = 0; params.b_deblocking_filter = 1; params.rc.f_rf_constant = 33; params.rc.i_bitrate = bitrate;
初始化编码器:
enc = x264_encoder_open(¶ms);
获取整个流的pps和SPS??:
int s = x264_encoder_headers(enc, &nals, &nal_count);
-----------------------------------------------------------------
x264编码:
初始化图片信息:
x264_picture_t picin, picout;
x264_picture_init(&picin);
对图片信息参数设定:
picin.i_pts = ts; picin.i_type = X264_TYPE_AUTO; picin.i_qpplus1 = 0; picin.img.i_csp = (csp == 17) ? X264_CSP_NV12 : csp;//special hack for android
。。。。。。。
。。。。。。。
。。。。。
对帧进行x264编码:
ret = x264_encoder_encode(enc, &nals, &nnal, &picin, &picout);
备注:总结一下就是:
(1)初始化并设定x264_param_t
(2)初始化并设定 x264_picture_t
(3)x264编码
=====================================================
参考:
X264多线程分析
http://blog.sina.com.cn/s/blog_4ae178ba01013yix.html
x264的编码示例
http://blog.csdn.net/xyyangkun/article/details/7255372/
http://www.cnblogs.com/chuncn/archive/2011/02/25/1459805.html