h.264 scanning process for transform coefficients
宏塊在經(jīng)過(guò)變換、量化后,得到大小為4x4或者8x8的矩陣,矩陣中的數(shù)據(jù)被稱為transform coefficient levels。這些level在后面會(huì)被用于熵編碼,因此我們需要把矩陣按照一定順序進(jìn)行掃描,得到數(shù)字序列。
?
掃描順序在幀與場(chǎng)會(huì)有所不同
4x4塊矩陣的掃描順序如下
??????????????
Zig-zag scan(Frame)????????????????????????? Field scan???????????
?
8x8塊矩陣的掃描順序如下
???????????
?
Zig-zag scan(Frame)??????? ????????????????????????? Field scan???????????
?
在實(shí)際的代碼處理上(JM),對(duì)變換系數(shù)的掃描過(guò)程是包含在量化過(guò)程中的,因?yàn)閷?duì)矩陣內(nèi)的元素的量化也是逐個(gè)進(jìn)行的,因此就可以按照對(duì)變換系數(shù)掃描的順序取出矩陣內(nèi)的元素進(jìn)行量化,后續(xù)就能直接對(duì)這些transform coefficient level序列進(jìn)行熵編碼。
int quant_4x4_normal(Macroblock *currMB, int **tblock, struct quant_methods *q_method) { VideoParameters *p_Vid = currMB->p_Vid;QuantParameters *p_Quant = p_Vid->p_Quant;Slice *currSlice = currMB->p_Slice;Boolean is_cavlc = (Boolean) (currSlice->symbol_mode == CAVLC);int block_x = q_method->block_x;int qp = q_method->qp;int* ACL = &q_method->ACLevel[0];int* ACR = &q_method->ACRun[0]; LevelQuantParams **q_params_4x4 = q_method->q_params;const byte (*pos_scan)[2] = q_method->pos_scan;const byte *c_cost = q_method->c_cost;int *coeff_cost = q_method->coeff_cost;LevelQuantParams *q_params = NULL;int i,j, coeff_ctr;int *m7;int scaled_coeff;int level, run = 0;int nonzero = FALSE;int qp_per = p_Quant->qp_per_matrix[qp];int q_bits = Q_BITS + qp_per;const byte *p_scan = &pos_scan[0][0];// Quantization// 4x4 block matrix has 16 coefficientsfor (coeff_ctr = 0; coeff_ctr < 16; ++coeff_ctr){//scanning positions (Zig-zag scan or Field scan)i = *p_scan++; // horizontal positionj = *p_scan++; // vertical position//block_x,block_y here is the position of a block on a Macroblock with the unit of pixelm7 = &tblock[j][block_x + i];if (*m7 != 0){q_params = &q_params_4x4[j][i];scaled_coeff = iabs (*m7) * q_params->ScaleComp;level = (scaled_coeff + q_params->OffsetComp) >> q_bits;if (level != 0){if (is_cavlc)level = imin(level, CAVLC_LEVEL_LIMIT);*coeff_cost += (level > 1) ? MAX_VALUE : c_cost[run];level = isignab(level, *m7);*m7 = rshift_rnd_sf(((level * q_params->InvScaleComp) << qp_per), 4);// inverse scale can be alternative performed as follows to ensure 16bit// arithmetic is satisfied.// *m7 = (qp_per<4) ? rshift_rnd_sf((level*q_params->InvScaleComp),4-qp_per) : (level*q_params->InvScaleComp)<<(qp_per-4);*ACL++ = level;*ACR++ = run;// reset zero level counterrun = 0;nonzero = TRUE;}else{*m7 = 0;++run;}}else{++run;}}*ACL = 0;return nonzero; }轉(zhuǎn)載于:https://www.cnblogs.com/TaigaCon/p/5245108.html
總結(jié)
以上是生活随笔為你收集整理的h.264 scanning process for transform coefficients的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Tomcat的优化技巧
- 下一篇: 前端性能优化之DOM(三)