x264的x264_param_t結構
typedef struct x264_param_t
{
/* CPU flags */
unsigned int cpu;
/* 並行線程的數量,即同時被編碼的圖像的數量,增加線程數量會影響編碼速度,
* 同時也會影響編碼延遲(所謂編碼延遲就是 編碼器中得到第一個輸出時已經往輸入的幀數)
*/
int i_threads; /* encode multiple frames in parallel */
/* 向前看線程的數量,爲了提高壓縮率得到更好的質量,x264會緩存一部分幀用於分析
* 以得到最優的編碼參數,但是會增加編碼延遲
*/
int i_lookahead_threads; /* multiple threads for lookahead analysis */
/* 是否使用基於slice的線程,使用zerolatency將會禁用該選項,和i_threads是互斥的,即frame級別的並性
* 和slice級別的並行不能同時進行
*/
int b_sliced_threads; /* Whether to use slice-based threading. */
/* 當進行並行處理時,是否使用使用非確定的優化,默認是true
*/
int b_deterministic; /* whether to allow non-deterministic optimizations when threaded */
/* 是否使用cpu相關的優化算法,如果否,那麼選擇傳統的規範的算法(性能可能不高)
*/
int b_cpu_independent; /* force canonical behavior rather than cpu-dependent optimal algorithms */
/* 前向緩存的幀的數量,前向緩存的目的是爲了得到更好的比特率或畫面質量
*/
int i_sync_lookahead; /* threaded lookahead buffer */
/* Video Properties */
int i_width;
int i_height;
int i_csp; /* CSP of encoded bitstream */
int i_level_idc;
int i_frame_total; /* number of frames to encode if known, else 0 */
/* NAL HRD
* Uses Buffering and Picture Timing SEIs to signal HRD
* The HRD in H.264 was not designed with VFR in mind.
* It is therefore not recommendeded to use NAL HRD with VFR.
* Furthermore, reconfiguring the VBV (via x264_encoder_reconfig)
* will currently generate invalid HRD. */
/* 檢驗編碼器產生的符合該標準的NAL單元流或字節流的偏差值。藍光視頻、電視廣播及其它特殊領域有此要求
*/
int i_nal_hrd;
/* 視頻可用信息
*/
struct
{
/* they will be reduced to be 0 < x <= 65535 and prime */
/*
* 樣本的寬高比
*/
int i_sar_height;
int i_sar_width;
/* 過掃描的類型:不設置、觀看、過掃描
*/
int i_overscan; /* 0=undef, 1=no overscan, 2=overscan */
x264_param_t
/* see h264 annex E for the values of the following */
/* 視頻在編碼/數字化之前是什麼類型,默認"undef".
* 取值有:Component, PAL, NTSC, SECAM, MAC 等
*/
int i_vidformat;
/*樣本亮度和色度的計算方式,默認"off",可選項:off/on
*/
int b_fullrange;
/* 原始色度格式,默認"undef"
*/
int i_colorprim;
/* 轉換方式,默認"undef"
*/
int i_transfer;
/* 設置從RGB計算得到亮度和色度所用的矩陣係數,默認"undef"
*/
int i_colmatrix;
/* 設置色度採樣位置,範圍0~5,默認0
*/
int i_chroma_loc; /* both top & bottom */
} vui;
/* Bitstream parameters */
int i_frame_reference; /* Maximum number of reference frames */
/* 強迫DPB(解碼圖像緩存區)的尺寸大於通過(B幀數量和參考幀數量)計算出來的大小
*/
int i_dpb_size; /* Force a DPB size larger than that implied by B-frames and reference frames.
* Useful in combination with interactive error resilience. */
/*
* IDR幀的間隔
*/
int i_keyint_max; /* Force an IDR keyframe at this interval */
/* IDR幀的最小間隔,如果遇到場景切換,但是間隔小於keyint_min。那麼它將被看作I幀而不是IDR幀
*/
int i_keyint_min; /* Scenecuts closer together than this are coded as I, not IDR. */
/* 判斷一個幀是否爲常見切換的閾值
*/
int i_scenecut_threshold; /* how aggressively to insert extra I frames */
/* 是否使用週期幀內刷新代替IDR幀
*/
int b_intra_refresh; /* Whether or not to use periodic intra refresh instead of IDR frames. */
/* 兩個參考幀之間的B幀數量
*/
int i_bframe; /* how many b-frame between 2 references pictures */
/* 自適應的B幀判斷,判斷一個幀是否被編碼器設置爲B幀
*/
int i_bframe_adaptive;
/* 控制B幀代替P幀的概率從-100到100,值越大,概率越高
*/
int i_bframe_bias;
/*是否允許B幀也作爲參考幀,默認是不允許的,這個功能可以進一步壓縮數據,但是相應的延遲也會增加
*/
int i_bframe_pyramid; /* Keep some B-frames as references: 0=off, 1=strict hierarchical, 2=normal */
/* 是否使用開放式圖像組,所謂開放式圖像組就是當前圖像組的幀可以參考前一個圖像組的幀,默認是false
*/
int b_open_gop;x264_param_t
/* 是否支持藍光碟片
*/
int b_bluray_compat;
/* 這個參數沒搞懂,好像是avc幀內處理的一個東西
*/
int i_avcintra_class;
/* 是否開啓去放開濾波
*/
int b_deblocking_filter;
/*alpha和beta是去方塊濾波的參數,強弱濾波相關
*/
int i_deblocking_filter_alphac0; /* [-6, 6] -6 light filter, 6 strong */
int i_deblocking_filter_beta; /* [-6, 6] idem */
/* 是否使用上下文自適應二進制算術編碼x264_param_t
*/
int b_cabac;
/* cabac的初始參數
*/
int i_cabac_init_idc;
/* 場編碼還是幀編碼
*/
int b_interlaced;
/* 強迫進行幀內預測
*/
int b_constrained_intra;
/* 自定義的量化矩陣,量化的模式:flat、jvt、custom
*/
int i_cqm_preset;
/* 自定義量化矩陣的文件名
*/
char *psz_cqm_file; /* filename (in UTF-8) of CQM file, JM format */
/* 自定義量化矩陣,只有在custom模式下才有效
*/
uint8_t cqm_4iy[16]; /* used only if i_cqm_preset == X264_CQM_CUSTOM */
uint8_t cqm_4py[16];
uint8_t cqm_4ic[16];
uint8_t cqm_4pc[16];
uint8_t cqm_8iy[64];
uint8_t cqm_8py[64];
uint8_t cqm_8ic[64];
uint8_t cqm_8pc[64];
/* Log */
void (*pf_log)( void *, int i_level, const char *psz, va_list );
void *p_log_private;
int i_log_level;
/* 是否進行完整的重建
*/
int b_full_recon; /* fully reconstruct frames, even when not necessary for encoding. Implied by psz_dump_yuv */
/* 重建幀,文件名
*/
char *psz_dump_yuv; /* filename (in UTF-8) for reconstructed frames */
/* Encoder analyser parameters */
struct
{
/* 幀內partition(劃分)的數量
*/
unsigned int intra; /* intra partitions */
/* 幀間partition的數量
*/
unsigned int inter; /* inter partitions */
/* 是否使用8x8的DCT變換
*/
int b_transform_8x8;
/* 權重預測中,P幀的權值
*/
int i_weighted_pred; /* weighting for P-frames */
/* B幀的權值是隱式的還是顯示的
*/
int b_weighted_bipred; /* implicit weighting for B-frames */
/* 時域、空間的MV預測方式:是使用時域、還是空域,或者讓編碼器自動選擇
*/
int i_direct_mv_pred; /* spatial vs temporal mv prediction */
/* 色度量化步長的偏移量
*/
int i_chroma_qp_offset;
/* 運動估計的方法:鑽石形狀、三步模式什麼的
*/
int i_me_method; /* motion estimation algorithm to use (X264_ME_*) */
/* 運動搜索的範圍,對編碼速度由很大影響,不同的preset對應不同的搜索範圍
*/
int i_me_range; /* integer pixel motion estimation search range (from predicted mv) */
/* 運動向量的取值範圍,由level決定,-1表示由編碼器自己設置
*/
int i_mv_range; /* maximum length of a mv (in pixels). -1 = auto, based on level */
/* 線程之間的最小運動向量緩存,這個不太理解
*/
int i_mv_range_thread; /* minimum space between threads. -1 = auto, based on number of threads. */
/* 亞像素運動估計的質量(精度)
*/
int i_subpel_refine; /* subpixel motion estimation quality */
/* 是否允許 亞像素色度運動估計和P幀的模式選擇
*/
int b_chroma_me; /* chroma ME for subpel and mode decision in P-frames */
/* 是否允許每個宏塊的分區有自己的參考編號
*/
int b_mixed_references; /* allow each mb partition to have its own reference number */
/* Trellis量化提高效率,對每個8x8的塊尋找合適的量化值,需要CABAC,
* 0 :即關閉 1:只在最後編碼時使用 2:在所有模式決策上啓用
*/
int i_trellis; /* trellis RD quantization */
/* 快速P幀跳過檢測
*/
int b_fast_pskip; /* early SKIP detection on P-frames */
/* P幀變換系數閾值
*/
int b_dct_decimate; /* transform coefficient thresholding on P-frames */
/* 自適應僞盲區
*/
int i_noise_reduction; /* adaptive pseudo-deadzone */
/* Psy優化強度,可能會增強細節
*/
float f_psy_rd; /* Psy RD strength */
/* Psy Trellis強度
*/
float f_psy_trellis; /* Psy trellis strength */
/* Psy優化開關
*/
int b_psy; /* Toggle all psy optimizations */
/* 是否使用輸入的mb信息(在x264_picture_t中)
*/
int b_mb_info; /* Use input mb_info data in x264_picture_t */
/* 是否根據編碼結果更新mb信息
*/
int b_mb_info_update; /* Update the values in mb_info according to the results of encoding. */
/* the deadzone size that will be used in luma quantization */
/* 亮度量化中使用的盲區大小
*/
int i_luma_deadzone[2]; /* {inter, intra} */
/*是否打印,psnr
*/
int b_psnr; /* compute and print PSNR stats */
/* 是否打印ssim
*/
int b_ssim; /* compute and print SSIM stats */
} analyse;
/* Rate control parameters */
struct
{
/* 碼率控制的方法,默認是CRF
* X264_RC_CQP恆定質量, X264_RC_CRF恆定碼率, X264_RC_ABR平均碼率
*/
int i_rc_method; /* X264_RC_* */
/* 指定P幀的量化值
*/
int i_qp_constant; /* 0 to (51 + 6*(x264_bit_depth-8)). 0=lossless */
/* 允許的最大最小QP值
*/
int i_qp_min; /* min allowed QP value */
int i_qp_max; /* max allowed QP value */
/* 量化步長,相鄰兩幀之間量化值的最大差值
*/
int i_qp_step; /* max QP step between frames */
/* 碼率
*/
int i_bitrate;
/* 實際質量,值越大圖像越花,越小越清晰
*/
float f_rf_constant; /* 1pass VBR, nominal QP */
/* 最大碼率因子,該選項僅在使用CRF並開啓VBV時有效,圖像質量的最大值,可能會導致VBV下溢
*/
float f_rf_constant_max; /* In CRF mode, maximum CRF as caused by VBV */
/* 允許的碼率誤差
*/
float f_rate_tolerance;
/* 平均碼率模式下,最大瞬時碼率,默認0
*/
int i_vbv_max_bitrate;
/* 碼率控制緩衝區的大小,單位kbit,默認0
*/
int i_vbv_buffer_size;
/* 設置碼率控制緩衝區(VBV)緩衝達到多滿(百分比),纔開始回放,範圍0~1.0,默認0.9
*/
float f_vbv_buffer_init; /* <=1: fraction of buffer_size. >1: kbit */
/* I幀和P幀之間的量化因子(QP)比值,默認1.4
*/
float f_ip_factor;
/* P幀和B幀之間的量化因子(QP)比值,默認1.3
*/
float f_pb_factor;
/* VBV filler: force CBR VBV and use filler bytes to ensure hard-CBR.
* Implied by NAL-HRD CBR. */
/* 這個參數還不太明白
*/
int b_filler;
/* 自適應量化(AQ)模式。 0:關閉AQ , 1:允許AQ在整個視頻中和幀內重新分配碼 2:自方差AQ(實驗階段),嘗試逐幀調整強度
*/
int i_aq_mode; /* psy adaptive QP. (X264_AQ_*) */
/* 自適應量化的強度,減少平趟和紋理區域的塊效應和模糊度
*/
float f_aq_strength;
/* 是否開啓基於macroblock的qp控制方法
* MBTree File是一個臨時文件,記錄了每個P幀中每個MB被參考的情況。
* 目前mbtree只處理P幀的MB,同時也不支持b_pyramid
*/
int b_mb_tree; /* Macroblock-tree ratecontrol. */
/* 決定mbtree向前預測的幀數
*/
int i_lookahead;
/* 2pass */
/* 是否允許把2pass的統計信息寫入psz_stat_out中
*/
int b_stat_write; /* Enable stat writing in psz_stat_out */
char *psz_stat_out; /* output filename (in UTF-8) of the 2pass stats file */
/* 2pass是否允許從psz_stat_in中讀取統計信息
*/
int b_stat_read; /* Read stat from psz_stat_in and use it */
char *psz_stat_in; /* input filename (in UTF-8) of the 2pass stats file */
/* 2pass params (same as ffmpeg ones) */
/* 量化曲線(quantizer curve)壓縮因子 0.0 => 恆定比特率,1.0 => 恆定量化值。
*/
float f_qcompress; /* 0.0 => cbr, 1.0 => constant qp */
/* 時間上模糊量化,減少QP的波動
*/
float f_qblur; /* temporally blur quants */
/* 時間上模糊複雜性,減少QP的波動
*/
float f_complexity_blur; /* temporally blur complexity */
/* 碼率控制覆蓋
*/
x264_zone_t *zones; /* ratecontrol overrides */
int i_zones; /* number of zone_t's */
/* 指定區的另一種方法
*/
char *psz_zones; /* alternate method of specifying zones */
} rc;
/* Cropping Rectangle parameters: added to those implicitly defined by
non-mod16 video resolutions. */
/* 裁剪矩形窗口參數:隱式添加到分辨率非16倍數的視頻中
* 在碼流層指定一個切除(crop)矩形。若不想x264在編碼時做crop,
* 但希望解碼器在回放時進行切除,可使用此項。單位爲像素
*/
struct
{
unsigned int i_left;
unsigned int i_top;
unsigned int i_right;
unsigned int i_bottom;
} crop_rect;
/* frame packing arrangement flag */
/*
* 編碼3D視頻時,此參數在碼流中插入一個標誌,告知解碼器此3D視頻是如何封裝的。
* 3D視頻幀封裝格式:幀封裝、場交錯、線交錯、左右全景、左右半景、上下半景、L+深度、L+深度+圖形+圖形深度
*/
int i_frame_packing;
/* Muxing parameters */
/* 是否生成nalu分隔符
*/
int b_aud; /* generate access unit delimiters */
/*
* 是否複製sps和pps放在每個關鍵幀的前面
*/
int b_repeat_headers; /* put SPS/PPS before each keyframe */
/* nalu是否符合標準
* 值爲true,則NALU之前是4字節前綴碼0x00000001;值爲false,則NALU之前的4個字節爲NALU長度
*/
int b_annexb; /* if set, place start codes (4 bytes) before NAL units,
* otherwise place size (4 bytes) before NAL units. */
int i_sps_id; /* SPS and PPS id number */
/* VFR輸入。1 :時間基和時間戳用於碼率控制 0 :僅幀率用於碼率控制
*/
int b_vfr_input; /* VFR input. If 1, use timebase and timestamps for ratecontrol purposes.
* If 0, use fps only. */
/*以某個預設模式將輸入流(隔行,恆定幀率)標記爲軟交錯(soft telecine)。默認none. 可用預設有:
* none, 22, 32, 64, double, triple, euro. 使用除none以外任一預設,都會連帶開啓--pic-struct
*/
int b_pulldown; /* use explicity set timebase for CFR */
/* 幀率的分子
*/
uint32_t i_fps_num;
/* 幀率的分母
*/
uint32_t i_fps_den;
/* 時間基的分子
*/
uint32_t i_timebase_num; /* Timebase numerator */
/* 時間基的分母
*/
uint32_t i_timebase_den; /* Timebase denominator */
int b_tff;
/* Pulldown:
* The correct pic_struct must be passed with each input frame.
* The input timebase should be the timebase corresponding to the output framerate. This should be constant.
* e.g. for 3:2 pulldown timebase should be 1001/30000
* The PTS passed with each frame must be the PTS of the frame after pulldown is applied.
* Frame doubling and tripling require b_vfr_input set to zero (see H.264 Table D-1)
*
* Pulldown changes are not clearly defined in H.264. Therefore, it is the calling app's responsibility to manage this.
*/
/* 強制在Picture Timing SEI傳送pic_struct. 默認是未開啓
*/
int b_pic_struct;
/* Fake Interlaced.
*
* Used only when b_interlaced=0. Setting this flag makes it possible to flag the stream as PAFF interlaced yet
* encode all frames progessively. It is useful for encoding 25p and 30p Blu-Ray streams.
*/
/*
* 將視頻流標記爲交錯(隔行),哪怕並非爲交錯式編碼。可用於編碼藍光兼容的25p和30p視頻。默認是未開啓
*/
int b_fake_interlaced;
/* Don't optimize header parameters based on video content, e.g. ensure that splitting an input video, compressing
* each part, and stitching them back together will result in identical SPS/PPS. This is necessary for stitching
* with container formats that don't allow multiple SPS/PPS. */
/* 不要根據視頻內容優化標頭參數
*/
int b_stitchable;
/* openCL 相關的設置
*/
int b_opencl; /* use OpenCL when available */
int i_opencl_device; /* specify count of GPU devices to skip, for CLI users */
void *opencl_device_id; /* pass explicit cl_device_id as void*, for API users */
char *psz_clbin_file; /* filename (in UTF-8) of the compiled OpenCL kernel cache file */
/* Slicing parameters */
/* slice的參數,大小尺寸等
*/
int i_slice_max_size; /* Max size per slice in bytes; includes estimated NAL overhead. */
int i_slice_max_mbs; /* Max number of MBs per slice; overrides i_slice_count. */
int i_slice_min_mbs; /* Min number of MBs per slice */
int i_slice_count; /* Number of slices per frame: forces rectangular slices. */
int i_slice_count_max; /* Absolute cap on slices per frame; stops applying slice-max-size
* and slice-max-mbs if this is reached. */
/* Optional callback for freeing this x264_param_t when it is done being used.
* Only used when the x264_param_t sits in memory for an indefinite period of time,
* i.e. when an x264_param_t is passed to x264_t in an x264_picture_t or in zones.
* Not used when x264_encoder_reconfig is called directly. */
/* x264_param_t參數釋放的函數指針
*/
void (*param_free)( void* );
/* Optional low-level callback for low-latency encoding. Called for each output NAL unit
* immediately after the NAL unit is finished encoding. This allows the calling application
* to begin processing video data (e.g. by sending packets over a network) before the frame
* is done encoding.
*
* This callback MUST do the following in order to work correctly:
* 1) Have available an output buffer of at least size nal->i_payload*3/2 + 5 + 64.
* 2) Call x264_nal_encode( h, dst, nal ), where dst is the output buffer.
* After these steps, the content of nal is valid and can be used in the same way as if
* the NAL unit were output by x264_encoder_encode.
*
* This does not need to be synchronous with the encoding process: the data pointed to
* by nal (both before and after x264_nal_encode) will remain valid until the next
* x264_encoder_encode call. The callback must be re-entrant.
*
* This callback does not work with frame-based threads; threads must be disabled
* or sliced-threads enabled. This callback also does not work as one would expect
* with HRD -- since the buffering period SEI cannot be calculated until the frame
* is finished encoding, it will not be sent via this callback.
*
* Note also that the NALs are not necessarily returned in order when sliced threads is
* enabled. Accordingly, the variable i_first_mb and i_last_mb are available in
* x264_nal_t to help the calling application reorder the slices if necessary.
*
* When this callback is enabled, x264_encoder_encode does not return valid NALs;
* the calling application is expected to acquire all output NALs through the callback.
*
* It is generally sensible to combine this callback with a use of slice-max-mbs or
* slice-max-size.
*
* The opaque pointer is the opaque pointer from the input frame associated with this
* NAL unit. This helps distinguish between nalu_process calls from different sources,
* e.g. if doing multiple encodes in one process.
*/
/* nalu處理的函數指針
*/
void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque );
} x264_param_t;