|
一、 x264運動估計中宏塊的位移cost計算: /* lambda = pow(2,qp/6-2) */
const byte x264_lambda_tab[52] =
{
1, 1, 1, 1, 1, 1, 1, 1, /* 0-7 */
1, 1, 1, 1, /* 8-11 */
1, 1, 1, 1, 2, 2, 2, 2, /* 12-19 */
3, 3, 3, 4, 4, 4, 5, 6, /* 20-27 */
6, 7, 8, 9,10,11,13,14, /* 28-35 */
16,18,20,23,25,29,32,36, /* 36-43 */
40,45,51,57,64,72,81,91 /* 44-51 */
};
/*根據(jù)量化參數(shù)得到i_lambda的值*/
int i_qpm = 10; /*取值0 - 51; 每個宏塊的qpm都是變化的,在函數(shù)x264_ratecontrol_mb中改變qpm值*/
int i_lambda = x264_lambda_tab[i_qpm];
/*計算i_lambda時所有位移的cost值*/
short *cost_mv[92];
malloc(cost_mv[i_lambda], (4*4*2048 + 1) * sizeof(short) );
cost_mv[i_lambda] += 2*4*2048;
for( i = 0; i <= 2*4*2048; i++ )
{
cost_mv[i_lambda][-i] = cost_mv[i_lambda][i]
= (short)( i_lambda * (log2f((float)( i+1 ))*2 + 0.718f + !!i) + .5f );
}
/*得到實際位移cost*/
int i_mvx = -1;
int i_mvy = 2;
int i_cost = cost_mv[i_mvx] + cost_mv[i_mvy];
二、 x264運動估計中宏塊的參考幀cost計算:
/*************************************************************
static const byte x264_ue_size_tab[256] =
{
1, 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
};
static inline int bs_size_te( int x, int val )
{
if( x == 1 )
return 1;
else
return x264_ue_size_tab[val+1];
}
static inline int x264_clip3( int v, int i_min, int i_max )
{
return ( (v < i_min) ? i_min : (v > i_max) ? i_max : v );
}
***************************************************************/
int i_lambda; /*i_lambda的獲取同上*/
/* 92: i_lambda值; 3: 當(dāng)前編碼幀的參考幀數(shù)量(大于3時設(shè)為3); 33: 參考幀序號 */
static short x264_cost_ref[92][3][33];
for( int i = 0; i < 3; i++ )
{
for( int j = 0; j < 33; j++ )
{
x264_cost_ref[i_lambda][i][j] = i ? i_lambda * bs_size_te( i, j ) : 0;
}
}
int i_num_ref_idx_l0_active = h->i_ref0 <= 0 ? 1 : h->i_ref0; /* 當(dāng)前編碼幀的ref0參考幀數(shù)量 */
int i_num_ref_idx_l1_active = h->i_ref1 <= 0 ? 1 : h->i_ref1; /* 當(dāng)前編碼幀的ref1參考幀數(shù)量 */
short *p_cost_ref[2]; /* ref0和ref1 */
p_cost_ref[0] = x264_cost_ref[i_lambda][x264_clip3(i_num_ref_idx_l0_active-1,0,2)];
p_cost_ref[1] = x264_cost_ref[i_lambda][x264_clip3(i_num_ref_idx_l1_active-1,0,2)];
/*得到實際參考幀i_ref的cost*/
int i_cost_ref0 = p_cost_ref[0][i_ref];
int i_cost_ref1 = p_cost_ref[1][i_ref];
總結(jié):(1)一個參考幀時, i_cost_ref始終為0;
(2)兩個參考幀時, i_cost_ref為i_lambda;
(3)大于等于3個參考幀時, i_cost_ref要根據(jù)參考幀的序號來計算。
|