Detailed description of the H.264 cavlc (encoding and decoding) Process

Source: Internet
Author: User

Http://hi.baidu.com/hero_xu_2006/blog/category/h.264%D1%A7%CF%B0

You can see that the cavlc is coming at 264, and paste the information here:

Encoding Process:
Assume there is a 4*4 data block (change, which is sent to entropy encoding after quantification)
{
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; (reverse encoding)

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 output = 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 output = 0000 100 0 11;
4) non-zero coefficient amplitude levels except tail coefficient: (this example is not very detailed, and there is a small error)
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)

Note: If the value is greater than the preset value, suffixlength ++ is used;
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 output = 0000 100 011 1; 
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 output = 0000 100 011 1 0010; 
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 output = 0000 100 011 1 0010 111;

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] the last non-zero coefficient does not need to be expressed by code streams.
Code output = 0000 100 011 1 0010 111 10 1 1 01; 
Encoding is complete. (Cavlc is mainly used for table queries. The standard tables are obtained through a large number of experiments !)

Decoding process:

Receiving code stream: 0000 1000 1110 0101 1110 1101

Computing NC = 1
The detailed decoding process is as follows:
1. Based on the coeff_token and NC Lookup tables (see standard table 9-5), the number of non-zero coefficients totalcoeffs and the number of trailing coefficients trailingones are obtained.
NC = 1 select the corresponding table, coeff_token is 0000100, And the totalcoeffs = 5 trailingones = 3 is displayed in the table.
Output sequence: None
2. parsing the tail Coefficient
The first step shows that there are three drag-and-tail coefficients. Enter the drag-and-tail coefficient symbol to encode the code stream 011. Then, the first and second drag-and-1 coefficients are obtained.
Output:-1,-1, 1 (reverse output)
3. Analyze the magnitude (level) of the non-zero coefficient except the tail Coefficient)
(1) determine the suffix length suffixlength
(2) Get the prefix levelprefix according to the code stream Table 9-6
(3) Obtain

Levelcode = (levelprefix <suffixlength) + levelsuffix
(4) levelcode is an even number level = (LEVEL + 2)/2
Levelcode is an odd number of levels = (-level-1)/2
(5) determine whether to update suffixlegth Based on the set threshold.
Return to the example, in reverse order
I = 0, sufixlefix = 0, the prefix levelprefix of Table 9-6 and 1 = 0, levelcode = 0,

Level = 1, I ++, and sufixle+++ are calculated)
I = 1, sufixlefix = 1, look up table 0010 (3 is prefix, 1 suffix) corresponding to the prefix levelprefix = 2, calculate levelcode = 4, level = 3, I ++
I = 2> = totalcoeffs-trailingones. The non-zero coefficient except the tail coefficient is parsed.
Output: 3, 1,-1,-1
4. parse the number of zeros before each non-zero coefficient
Based on totalcoeffs = 5 and input code stream 111, table 9-7 obtains totalzeros = 3.
Initial I = TotalCoeffs-1 = 4, zeroleft = totalzeros = 3, the number of five non-zero coefficients before the zero Parsing is as follows:
I = 4, zeroleft = 3, according to the code stream 10, table 9-10, runbefor = 1,

Output sequence: 3, 1,-1,-1, 0, 1
I = 3, zeroleft = 3-1 = 2. Based on the code stream 1, check the table runbefore = 0,

Output sequence: 3, 1,-1,-1, 0, 1
I = 2, zeroleft = 2-0 = 2. Based on the code stream 1, check the table runbefore = 0,

Output sequence: 3, 1,-1,-1, 0, 1
I = 1, zeroleft = 2-0 = 2, according to the code stream 01, check the table runbefore = 1,

Output sequence: 3, 0, 1,-1,-1, 0, 1
I = 0, zeroleft = 2-1 = 1, output sequence:,-1,-, 1
5. After decoding, set the remaining elements to 0 and arrange them in reverse order to obtain the 4*4 matrix.
6. Restore to a 4*4 data block.
{
0, 3,-1, 0,
0,-1, 1, 0,
1, 0, 0, 0,
0, 0, 0, 0
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.