为了减少残差系数使用的编码比特,x264中使用了一种方法--decimation。原话是这样子的:
Writing the 16 CBFs in an i16x16 block is quite costly, so decimation can save many bits. More useful with CAVLC, but still useful with CABAC. 中心思想是如果一个16x16块的非零残差系数个数很少且最大绝对值不超过1(用一个score来衡量),直接将其所有4x4块的残差系数置为0,这样子就不要为该16x16块发送16个cbf;
对于亮度,如果是8x8块,则score<4时,将残差系数全置为0;
如果是16x16块,则score<6时,将残差系数全置为0;
对于色度,则score<7时,将残差系数全置为0;
该技术一般用于帧间宏块,总共在下面几个函数应用:
x264_mb_encode_i16x16;
x264_macroblock_encode_p8x8_internal;
x264_macroblock_probe_skip_internal;
x264_macroblock_encode_internal;
x264_mb_encode_chroma_internal;
以x264_mb_encode_i16x16为例来看看:
static void x264_mb_encode_i16x16( x264_t *h, int p, int i_qp )
{
pixel *p_src = h->mb.pic.p_fenc[p];
pixel *p_dst = h->mb.pic.p_fdec[p];
ALIGNED_ARRAY_N( dctcoef, dct4x4,[16],[16] );
ALIGNED_ARRAY_N( dctcoef, dct_dc4x4,[16] );
int nz, block_cbp = 0;
int decimate_score = h->mb.b_dct_decimate ? 0 : 9;//I帧设置为9,p帧设置为0;
int i_quant_cat = p ? CQM_4IC : CQM_4IY;
int i_mode = h->mb.i_intra16x16_pred_mode;
if( h->mb.b_lossless )
x264_predict_lossless_16x16( h, p, i_mode );
else
h->predict_16x16[i_mode]( h->mb.</