X264的文檔內(nèi)容比較多,參數(shù)也不少,我就挑一些重要的參數(shù)給大家分享一下。
#nal_unit_type_e//NAL的類型
enum nal_unit_type_e
{
NAL_UNKNOWN = 0,//未知類型
NAL_SLICE = 1,//不分區(qū)、不是IDR 圖像的片
NAL_SLICE_DPA = 2,//片分區(qū)A
NAL_SLICE_DPB = 3,//片分區(qū)B
NAL_SLICE_DPC = 4,//片分區(qū)C
NAL_SLICE_IDR = 5, /* ref_idc != 0 *///序列參數(shù)集
NAL_SEI = 6, /* ref_idc == 0 *///圖像參數(shù)集
NAL_SPS = 7,//分界符
NAL_PPS = 8,//序列結(jié)束
NAL_AUD = 9,//碼流結(jié)束
NAL_FILLER = 12,//填充模式
/* ref_idc == 0 for 6,9,10,11,12 */
};
enum nal_priority_e
enum nal_priority_e//NAL單元的優(yōu)先級(jí)
{
NAL_PRIORITY_DISPOSABLE = 0,
NAL_PRIORITY_LOW = 1,
NAL_PRIORITY_HIGH = 2,
NAL_PRIORITY_HIGHEST = 3,
};
typedef struct x264_nal_t
typedef struct x264_nal_t
{
int i_ref_idc; //nal的優(yōu)先級(jí)
int i_type; //nal單元的類型
int b_long_startcode; // 是否采用長(zhǎng)前綴碼0x00000001
int i_first_mb; // 如果Nal為一條帶,則表示該條帶第一個(gè)宏塊的指數(shù)
int i_last_mb; // 如果Nal為一條帶,則表示該條帶最后一個(gè)宏塊的指數(shù)
int i_payload; // payload 的字節(jié)大小
uint8_t *p_payload; // 存放編碼后的數(shù)據(jù),已經(jīng)封裝成Nal單元
int i_padding;//尾部補(bǔ)全的字節(jié)數(shù)
} x264_nal_t;
Analyse flags
/* Analyse flags */
#define X264_ANALYSE_I4x4 0x0001 /* Analyse i4x4 */
#define X264_ANALYSE_I8x8 0x0002 /* Analyse i8x8 (requires 8x8 transform) */
#define X264_ANALYSE_PSUB16x16 0x0010 /* Analyse p16x8, p8x16 and p8x8 */
#define X264_ANALYSE_PSUB8x8 0x0020 /* Analyse p8x4, p4x8, p4x4 */
#define X264_ANALYSE_BSUB16x16 0x0100 /* Analyse b16x8, b8x16 and b8x8 */
#define X264_DIRECT_PRED_NONE 0//直接預(yù)測(cè)方法
#define X264_DIRECT_PRED_SPATIAL 1//空間
#define X264_DIRECT_PRED_TEMPORAL 2//時(shí)間
#define X264_DIRECT_PRED_AUTO 3
#define X264_ME_DIA 0//運(yùn)動(dòng)估計(jì)方法
#define X264_ME_HEX 1
#define X264_ME_UMH 2
#define X264_ME_ESA 3
#define X264_ME_TESA 4
#define X264_CQM_FLAT 0//自定義量化矩陣方法
#define X264_CQM_JVT 1
#define X264_CQM_CUSTOM 2
#define X264_RC_CQP 0// 碼率控制方法
#define X264_RC_CRF 1
#define X264_RC_ABR 2
#define X264_QP_AUTO 0
#define X264_AQ_NONE 0
#define X264_AQ_VARIANCE 1
#define X264_AQ_AUTOVARIANCE 2
#define X264_AQ_AUTOVARIANCE_BIASED 3
#define X264_B_ADAPT_NONE 0 // 自適應(yīng)B幀
#define X264_B_ADAPT_FAST 1
#define X264_B_ADAPT_TRELLIS 2
#define X264_WEIGHTP_NONE 0// P幀權(quán)重
#define X264_WEIGHTP_SIMPLE 1
#define X264_WEIGHTP_SMART 2
#define X264_B_PYRAMID_NONE 0// 參見(jiàn)param->i_bframe_pyramid ,B幀可作為參考幀
#define X264_B_PYRAMID_STRICT 1
#define X264_B_PYRAMID_NORMAL 2
#define X264_KEYINT_MIN_AUTO 0// IDR幀間距param->i_keyint_max / i_keyint_min
#define X264_KEYINT_MAX_INFINITE (1<<30)
static const char * const x264_direct_pred_names[] = { "none", "spatial", "temporal", "auto", 0 };
static const char * const x264_motion_est_names[] = { "dia", "hex", "umh", "esa", "tesa", 0 };
static const char * const x264_b_pyramid_names[] = { "none", "strict", "normal", 0 };
static const char * const x264_overscan_names[] = { "undef", "show", "crop", 0 };
static const char * const x264_vidformat_names[] = { "component", "pal", "ntsc", "secam", "mac", "undef", 0 };
static const char * const x264_fullrange_names[] = { "off", "on", 0 };
static const char * const x264_colorprim_names[] = { "", "bt709",
"undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "film", "bt2020", 0 };
static const char * const x264_transfer_names[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100", "log316",
"iec61966-2-4", "bt1361e", "iec61966-2-1", "bt2020-10", "bt2020-12", 0 };
static const char * const x264_colmatrix_names[] = { "GBR", "bt709", "undef", "", "fcc", "bt470bg", "smpte170m", "smpte240m", "YCgCo", "bt2020nc", "bt2020c", 0 };
static const char * const x264_nal_hrd_names[] = { "none", "vbr", "cbr", 0 };
Colorspace type
/* Colorspace type:設(shè)置輸出的視頻的采樣格式 */
#define X264_CSP_MASK 0x00ff /* */
#define X264_CSP_NONE 0x0000 /* Invalid mode */
#define X264_CSP_I420 0x0001 /* yuv 4:2:0 planar */
#define X264_CSP_YV12 0x0002 /* yvu 4:2:0 planar */
#define X264_CSP_NV12 0x0003 /* yuv 4:2:0, with one y plane and one packed u+v */
#define X264_CSP_NV21 0x0004 /* yuv 4:2:0, with one y plane and one packed v+u */
#define X264_CSP_I422 0x0005 /* yuv 4:2:2 planar */
#define X264_CSP_YV16 0x0006 /* yvu 4:2:2 planar */
#define X264_CSP_NV16 0x0007 /* yuv 4:2:2, with one y plane and one packed u+v */
#define X264_CSP_V210 0x0008 /* 10-bit yuv 4:2:2 packed in 32 */
#define X264_CSP_I444 0x0009 /* yuv 4:4:4 planar */
#define X264_CSP_YV24 0x000a /* yvu 4:4:4 planar */
#define X264_CSP_BGR 0x000b /* packed bgr 24bits */
#define X264_CSP_BGRA 0x000c /* packed bgr 32bits */
#define X264_CSP_RGB 0x000d /* packed rgb 24bits */
#define X264_CSP_MAX 0x000e /* end of list */
#define X264_CSP_VFLIP 0x1000 /* the csp is vertically flipped */
#define X264_CSP_HIGH_DEPTH 0x2000 /* the csp has a depth of 16 bits per pixel component */
Rate control parameters
/* Rate control parameters*/
struct
{
int i_rc_method; //碼率控制
int i_qp_constant; //QP值,范圍0~51,值越大圖像越模糊,默認(rèn)23
int i_qp_min; //允許的最小量化值
int i_qp_max; //允許的最大量化值
int i_qp_step; //幀間最大量化步長(zhǎng)
int i_bitrate; //設(shè)置平均碼率
float f_rf_constant; //是實(shí)際質(zhì)量,越大圖像越花,越小越清晰
float f_rf_constant_max; //圖像質(zhì)量的最大值
float f_rate_tolerance;//允許的誤差
int i_vbv_max_bitrate;//平均碼率模式下,最大瞬時(shí)碼率,默認(rèn)0(與-B設(shè)置相同)
int i_vbv_buffer_size;//率控制緩沖區(qū)的大小,單位kbit,默認(rèn)0
float f_vbv_buffer_init; // <=1: fraction of buffer_size. >1: kbit碼率控制緩沖區(qū)數(shù)據(jù)保留的最[大數(shù)據(jù)](http://lib.csdn.net/base/20)量與緩沖區(qū)大小之比,范圍0~1.0,默認(rèn)0.9
float f_ip_factor;//ip--i幀p幀的qp的差值
float f_pb_factor;//pb--p幀b幀的qp的差值
/* VBV filler: force CBR VBV and use filler bytes to ensure hard-CBR.
* Implied by NAL-HRD CBR. */
int b_filler;
int i_aq_mode; // 自適應(yīng)量化(AQ)模式。
// 0:關(guān)閉AQ
// 1:允許AQ在整個(gè)視頻中和幀內(nèi)重新分配碼
// 2:自方差A(yù)Q(實(shí)驗(yàn)階段),嘗試逐幀調(diào)整強(qiáng)度
float f_aq_strength;//AQ強(qiáng)度,減少平趟和紋理區(qū)域的塊效應(yīng)和模糊度
int b_mb_tree; //是否開啟基于macroblock的qp控制方法,開啟之后質(zhì)量有所提升
int i_lookahead; // 決定mbtree向前預(yù)測(cè)的幀數(shù)
/* 2pass */
int b_stat_write; //是否將統(tǒng)計(jì)數(shù)據(jù)寫入到文件psz_stat_out中
char *psz_stat_out; // 輸出文件用于保存第一次編碼統(tǒng)計(jì)數(shù)據(jù)
int b_stat_read; // 是否從文件psz_stat_in中讀入統(tǒng)計(jì)數(shù)據(jù)
char *psz_stat_in; // 輸入文件存有第一次編碼的統(tǒng)計(jì)數(shù)據(jù)
/* 2pass params (same as ffmpeg ones) */
float f_qcompress; //量化曲線(quantizer curve)壓縮因子。范圍0-1
0.0 => cbr(constant bitrate), 1.0 => constant qp(constatnt quantity(p frame))
越小-》碼率越恒定,越大-》量化越恒定
float f_qblur; //時(shí)間上模糊量化,減少Q(mào)P的波動(dòng)(after curve compression)
float f_complexity_blur; //時(shí)間上模糊復(fù)雜性,減少Q(mào)P的波動(dòng)(before curve compression)
x264_zone_t *zones; // 碼率控制覆蓋
int i_zones; /* number of zone_t's */
char *psz_zones; /* alternate method of specifying zones */
} rc;
x264_level_t
//在給定的profile下,level通常與解碼器的處理能力和內(nèi)存容量相對(duì)應(yīng)。每一個(gè)檔次設(shè)置不同的參數(shù)
//(如取樣速率、圖像尺寸、編碼比特率等),得到對(duì)應(yīng)的編解碼器性能的不同level。
typedef struct x264_level_t
{
int level_idc;
int mbps; //兆比特每秒
int frame_size; //最大幀的大小
int dpb; // 最大的解碼圖像緩沖區(qū)
int bitrate; //比特率
int cpb; /* max vbv buffer (kbit) */
int mv_range; //最大的垂直的mv分量的范圍
int mvs_per_2mb; /* max mvs per 2 consecutive mbs. */
int slice_rate; /* ?? */
int mincr; /* min compression ratio */
int bipred8x8; /* limit bipred to >=8x8 */
int direct8x8; /* limit b_direct to >=8x8 */
int frame_only; /* forbid interlacing */
} x264_level_t;
x264_image_t
x264_image_t 結(jié)構(gòu)用于存放一幀圖像實(shí)際像素?cái)?shù)據(jù)
typedef struct
{
int i_csp; // 設(shè)置彩色空間,通常取值 X264_CSP_I420,所有可能取值定義在x264.h中
int i_plane; // 圖像平面?zhèn)€數(shù),例如彩色空間是YUV420格式的,此處取值3
int i_stride[4]; // 每個(gè)圖像平面的跨度,也就是每一行數(shù)據(jù)的字節(jié)數(shù)
uint8_t *plane[4]; // 每個(gè)圖像平面存放數(shù)據(jù)的起始地址, plane[0]是Y平面,
// plane[1]和plane[2]分別代表U和V平面
} x264_image_t;
x264_picture_t
x264_picture_t 結(jié)構(gòu)體描述一視頻幀的特征
typedef struct
{
int i_type; // 幀的類型,取值有
X264_TYPE_KEYFRAME、X264_TYPE_P、
// X264_TYPE_AUTO等。初始化為
auto,則在編碼過(guò)程自行控制。
int i_qpplus1; // 此參數(shù)減1代表當(dāng)前幀的量化參數(shù)值
int i_pic_struct; // 幀的結(jié)構(gòu)類型,表示是幀還是場(chǎng),是逐行還是隔行,
// 取值為枚舉值 pic_struct_e,定義在x264.h中
int b_keyframe; // 輸出:是否是關(guān)鍵幀
int64_t i_pts; // 一幀的顯示時(shí)間戳
int64_t i_dts; // 輸出:解碼時(shí)間戳。當(dāng)一幀的pts非常接近0時(shí),該dts值可能為負(fù)。
/* 編碼器參數(shù)設(shè)置,如果為NULL則表示繼續(xù)使用前一幀的設(shè)置。某些參數(shù)
(例如aspect ratio) 由于收到H264本身的限制,只能每隔一個(gè)GOP才能改變。
這種情況下,如果想讓這些改變的參數(shù)立即生效,則必須強(qiáng)制生成一個(gè)IDR幀。*/
x264_param_t *param;
x264_image_t img; // 存放一幀圖像的真實(shí)數(shù)據(jù)
x264_image_properties_t prop;
x264_hrd_t hrd_timing; // 輸出:HRD時(shí)間信息,僅當(dāng)i_nal_hrd設(shè)置了才有效
void *opaque; // 私有數(shù)據(jù)存放區(qū),將輸入數(shù)據(jù)拷貝到輸出幀中
} x264_picture_t ;
x264_nal_t
x264_nal_t中的數(shù)據(jù)在下一次調(diào)用x264_encoder_encode之后就無(wú)效了,因此必須在調(diào)用
x264_encoder_encode 或 x264_encoder_headers 之前使用或拷貝其中的數(shù)據(jù)。
typedef struct
{
int i_ref_idc; // Nal的優(yōu)先級(jí)
int i_type; // Nal的類型
int b_long_startcode; // 是否采用長(zhǎng)前綴碼0x00000001
int i_first_mb; // 如果Nal為一條帶,則表示該條帶第一個(gè)宏塊的指數(shù)
int i_last_mb; // 如果Nal為一條帶,則表示該條帶最后一個(gè)宏塊的指數(shù)
int i_payload; // payload 的字節(jié)大小
uint8_t *p_payload; // 存放編碼后的數(shù)據(jù),已經(jīng)封裝成Nal單元
} x264_nal_t;
cli_opt_t
結(jié)構(gòu)體主要記錄一些與編碼關(guān)系較小的設(shè)置信息,其變量可通過(guò)讀取main()的參數(shù)獲得。
typedef struct
{
int b_progress; // bool類型的變量,用來(lái)控制是否顯示編碼進(jìn)度。取值為0或1。
int i_seek; // 整數(shù)類型 表示開始從哪一幀開始編碼。
// 因?yàn)椴灰欢◤奈募牡谝粠_始編碼,這是可以控制的。
/* hnd_t(hnd=handle)是一個(gè)空指針, 定義在x264cli.h 中。void *在C語(yǔ)言里空指針是有幾個(gè)
特性的,它是一個(gè)一般化指針,可以指向任何一種類型,但卻不能解引用,需要解引
用的時(shí)候,需要進(jìn)行強(qiáng)制轉(zhuǎn)換。采用空指針的策略,是為了聲明變量的簡(jiǎn)便和統(tǒng)一。 */
hnd_t hin; // 指向輸入yuv文件的指針
hnd_t hout; // 指向編碼過(guò)后生成的文件的指針。
/* 一個(gè)指向文件類型的指針,它是文本文件,其每一行的格式是 :framenum frametye
QP用于強(qiáng)制指定某些幀或者全部幀的幀類型和QP(quant param量化參數(shù))的值. */
FILE *qpfile;
} cli_opt_t;