I would like to take this document to the QQ Group "H.264 Park" and those selfless friends in the group!
I also hope to help my friends who have just entered this field. You are welcome to criticize and correct those who have done this!
Encoding Process:
Assume there is a 4*4 data block.
{
0, 3,-1, 0,
0,-1, 1, 0,
1, 0, 0, 0,
0, 0, 0, 0
}
Data re-arrangement:,-1 ......
1) Initial Value Setting:
Number of non-zero coefficients (totalcoeffs) = 5;
Trailingones = 3;
The number of zeros before the last non-zero coefficient (total_zeros) = 3;
Variable NC = 1;
(Note: The NC value is determined: The DC coefficient of the color NC =-1; the NC value of other coefficient types is based on the number of non-zero coefficients (NA) of 4*4 blocks on the left of the current block) the number of non-zero coefficients (NB) of 4*4 blocks in the current block is obtained. For details, see table 6.10 of bihoujieshu p120)
Suffixlength = 0;
I = totalcoeffs = 5;
2) coeff_token:
Query criteria (bs iso/IEC 14496-) Table 9-5, available:
If (totalcoeffs = 5 & trailingones = 3 & 0 <= NC <2)
Coeff_token = 0000 100;
Code = 0000 100;
3) encode all trailingones characters:
In reverse order, the symbols of the three backend coefficients are + (0),-(1), and-(1 );
That is:
Trailingone sign [I --] = 0;
Trailingone sign [I --] = 1;
Trailingone sign [I --] = 1;
Code = 0000 1000 11;
4) non-zero coefficient amplitude levels except tail coefficient:
The process is as follows:
(1) convert signed level [I] into a signed levelcode;
If level [I] is positive, levelcode = (level [I] <1)-2;
If level [I] is negative, levelcode =-(level [I] <1)-1;
(2) Calculate level_prefix: level_prefix = levelcode/(1 <suffixlength );
The corresponding bit string is available in the 9-6 table;
(3) Calculate level_suffix: level_suffix = levelcode % (1 <suffixlength );
(4) determine the suffix Length Based on the suffixlength value;
(5) suffixlength updata:
If (suffixlength = 0)
Suffixlength ++;
Else if (levelcode> (3 <suffixLength-1) & suffixlength <6)
Suffixlength ++;
Back in the example, level [I --] = 1; (I = 1)
Levelcode = 0; level_prefix = 0;
Query Table 9-6. The corresponding Bit String = 1 when level_prefix is 0;
Because suffixlength is initialized to 0, there is no suffix for this level;
Suffixlength = 0, so suffixlength ++;
Code = 0000 1000 111;
Encode the next level: level [0] = 3;
Levelcode = 4; level_prefix = 2; Bit String = 001;
Level_suffix = 0; suffixlength = 1; therefore, the bitstream is 0010;
Code = 0000 1000 1110 010;
I = 0, encoding level ends.
5) Number of totalzeros before the last non-zero coefficient of encoding ):
Table 9-7. When totalcoeffs = 5 and total_zero = 3, bit string = 111;
Code = 0000 1000 1110 0101 11;
6) encode the number (runbefore) of the first zero of each non-zero coefficient:
I = totalcoeffs = 5; zerosleft = total_zeros = 3; Table 9-10:
Encoding in reverse order
Zerosleft = 3, run_before = 1 run_before [4] = 10;
Zerosleft = 2, run_before = 0 run_before [3] = 1;
Zerosleft = 2, run_before = 0 run_before [2] = 1;
Zerosleft = 2, run_before = 1 run_before [1] = 01;
Zerosleft = 1, run_before = 1 run_before [0], which is expressed by code streams.
Code = 0000 1000 1110 0101 1110 1101;
Encoding is complete.