{ 算法
/* 開闢內存空間*/ 大數據
memset( param, 0, sizeof( x264_param_t ) ); 優化
/* CPU自動檢測 */ ui
param->cpu = x264_cpu_detect(); 編碼
param->i_threads = X264_THREADS_AUTO; /* 並行編碼線程爲0 */ spa
param->b_deterministic = 1; /*容許非肯定性時線程優化*/ .net
param->i_sync_lookahead = X264_SYNC_LOOKAHEAD_AUTO; /* 自動選擇線程超前緩衝大小-1 */ 線程
/* 視頻屬性 */ 日誌
param->i_csp = X264_CSP_I420; /*設置輸入的視頻採樣的格式0x0001yuv 4:2:0 planar*/ orm
param->i_width = 0; /* 寬度*/
param->i_height = 0; /* 高度*/
param->vui.i_sar_width = 0;
param->vui.i_sar_height= 0; /* 設置長寬比 */
param->vui.i_overscan = 0; /* 過掃描線,默認undef(不設置),可選:show(觀看)crop(去除) */
param->vui.i_vidformat = 5; /* undef視頻格式 */
param->vui.b_fullrange = 0; /* off */
param->vui.i_colorprim = 2; /* undef原始色度格式*/
param->vui.i_transfer = 2; /* undef 轉換方式*/
param->vui.i_colmatrix = 2; /* undef 色度矩陣設置*/
param->vui.i_chroma_loc= 0; /* left center 色度樣本指定,範圍0~5,默認0*/
param->i_fps_num = 25; /*幀率*/
param->i_fps_den = 1; /*用兩個整型的數的比值,來表示幀率*/
param->i_level_idc = -1; /* level值的設置*/
param->i_slice_max_size = 0; /* 每片字節的最大數,包括預計的NAL開銷. */
param->i_slice_max_mbs = 0; /* 每片宏塊的最大數,重寫 i_slice_count */
param->i_slice_count = 0; /* 每幀的像條數目: 設置矩形像條. */
/* 編碼參數 */
param->i_frame_reference = 3; /*參考幀的最大幀數。*/
param->i_keyint_max = 250; /* 在此間隔設置IDR關鍵幀 */
param->i_keyint_min = 25; /* 場景切換少於次值編碼位I, 而不是 IDR. */
param->i_bframe = 3; /*兩個參考幀之間的B幀數目*/
param->i_scenecut_threshold = 40; /*如何積極地插入額外的I幀 */
param->i_bframe_adaptive = X264_B_ADAPT_FAST; /*自適應B幀斷定1*/
param->i_bframe_bias = 0; /*控制插入B幀斷定,範圍-100~+100,越高越容易插入B幀*/
param->b_bframe_pyramid = 0; /*容許部分B爲參考幀 */
param->b_deblocking_filter = 1; /*去塊效應相關*/
param->i_deblocking_filter_alphac0 = 0; /* [-6, 6] -6 亮度濾波器, 6 強 */
param->i_deblocking_filter_beta = 0; /* [-6, 6] 同上 */
param->b_cabac = 1; /*cabac的開關*/
param->i_cabac_init_idc = 0;
/*碼率控制*/
param->rc.i_rc_method = X264_RC_CRF;/*恆定碼率*/
param->rc.i_bitrate = 0;/*設置平均碼率大小*/
param->rc.f_rate_tolerance = 1.0;
param->rc.i_vbv_max_bitrate = 0; /*平均碼率模式下,最大瞬時碼率,默認0(與-B設置相同) */
param->rc.i_vbv_buffer_size = 0; /*碼率控制緩衝區的大小,單位kbit,默認0 */
param->rc.f_vbv_buffer_init = 0.9; /* <=1: fraction of buffer_size. >1: kbit碼率控制緩衝區數據保留的最大數據量與緩衝區大小之比,範圍0~1.0,默認0.9*/
param->rc.i_qp_constant = 23;/*最小qp值*/
param->rc.f_rf_constant = 23;
param->rc.i_qp_min = 10; /*容許的最小量化值 */
param->rc.i_qp_max = 51; /*容許的最大量化值*/
param->rc.i_qp_step = 4; /*幀間最大量化步長 */
param->rc.f_ip_factor = 1.4;
param->rc.f_pb_factor = 1.3;
param->rc.i_aq_mode = X264_AQ_VARIANCE; /* psy adaptive QP. (X264_AQ_*) */
param->rc.f_aq_strength = 1.0;
param->rc.i_lookahead = 40;
param->rc.b_stat_write = 0; /* Enable stat writing in psz_stat_out */
param->rc.psz_stat_out = "x264_2pass.log";
param->rc.b_stat_read = 0;
param->rc.psz_stat_in = "x264_2pass.log";
param->rc.f_qcompress = 0.6; /* 0.0 => cbr, 1.0 => constant qp */
param->rc.f_qblur = 0.5; /*時間上模糊量化 */
param->rc.f_complexity_blur = 20; /* 時間上模糊複雜性 */
param->rc.i_zones = 0; /* number of zone_t's */
param->rc.b_mb_tree = 1; /* Macroblock-tree ratecontrol. */
/* 日誌 */
param->pf_log = x264_log_default;
param->p_log_private = NULL;
param->i_log_level = X264_LOG_INFO;/*默認爲"Info"*/
/*分析 */
param->analyse.intra = X264_ANALYSE_I4x4 | X264_ANALYSE_I8x8;
param->analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_I8x8
| X264_ANALYSE_PSUB16x16 | X264_ANALYSE_BSUB16x16;
param->analyse.i_direct_mv_pred = X264_DIRECT_PRED_SPATIAL;/*空間預測模式*/
param->analyse.i_me_method = X264_ME_HEX;/*運動估計算法HEX*/
param->analyse.f_psy_rd = 1.0;
param->analyse.b_psy = 1;
param->analyse.f_psy_trellis = 0;
param->analyse.i_me_range = 16;/*運動估計範圍*/
param->analyse.i_subpel_refine = 7; /* 亞像素運動估計質量 */
param->analyse.b_mixed_references = 1; /*容許每一個宏塊的分區在P幀有它本身的參考號*/
param->analyse.b_chroma_me = 1; /* 亞像素色度運動估計和P幀的模式選擇 */
param->analyse.i_mv_range_thread = -1; /* 線程之間的最小空間. -1 = auto, based on number of threads. */
param->analyse.i_mv_range = -1; /*運動矢量最大長度set from level_idc*/
param->analyse.i_chroma_qp_offset = 0; /*色度量化步長偏移量 */
param->analyse.b_fast_pskip = 1; /*快速P幀跳過檢測*/
param->analyse.b_weighted_bipred = 1; /*爲b幀隱式加權 */
param->analyse.b_dct_decimate = 1; /* 在P-frames轉換參數域 */
param->analyse.b_transform_8x8 = 1; /* 幀間分區*/
param->analyse.i_trellis = 1; /* Trellis量化,對每一個8x8的塊尋找合適的量化值,須要CABAC,默認0 0:關閉1:只在最後編碼時使用2:一直使用*/
param->analyse.i_luma_deadzone[0] = 21; /*幀間亮度量化中使用的無效區大小*/
param->analyse.i_luma_deadzone[1] = 11; /*幀內亮度量化中使用的無效區大小*/
param->analyse.b_psnr = 0;/*是否顯示PSNR*/
param->analyse.b_ssim = 0;/*是否顯示SSIM*/
/*量化*/
param->i_cqm_preset = X264_CQM_FLAT; /*自定義量化矩陣(CQM),初始化量化模式爲flat 0*/
memset( param->cqm_4iy, 16, 16 );
memset( param->cqm_4ic, 16, 16 );
memset( param->cqm_4py, 16, 16 );
memset( param->cqm_4pc, 16, 16 );
memset( param->cqm_8iy, 16, 64 );
memset( param->cqm_8py, 16, 64 );/*開闢空間*/
/*muxing*/
param->b_repeat_headers = 1; /* 在每一個關鍵幀前放置SPS/PPS*/
param->b_aud = 0; /*生成訪問單元分隔符*/
}
轉自:http://blog.csdn.net/vblittleboy/article/details/8028923