"H.264/AVC Video codec technology specific explanation" video tutorial has been in the "CSDN College" on-line, the video details of the background, standard protocol and implementation, and through a practical project in the form of the standard of H. A to analyze and realize, welcome to watch! "The paper is finally light. I know this matter to be preach. " Only have their own in accordance with the standard document in the form of code, the ability of the video compression coding standard ideas and methods have enough deep understanding and experience. Link Address: H.264/AVC Video codec technology specific explanation GitHub code address: Click here 1. The process of parsing macro-block residuals data with H. CAVLC
When decoding the residual data of a macro block, the decoder in H. The process is similar to the inverse process of the CAVLC encoding mentioned above.
When parsing a macro block residuals. First, the non-0 coefficients of the residual matrix and the number of Numcoeff and trailingonesof the trailing coefficients are analyzed. The symbol trailingsignsis followed by each trailing factor. It is then the value of each non- trailing non-0 coefficient level. Then the total number of the 0 in front of the highest-frequency non-0 coefficients is resolved totalzeros. Finally, each non-0 coefficient before the number of consecutive 0 Runbefore.
2. Calculating the context parameters for CAVLC analytic residuals
The context in the CAVLC codec process is the current block value numbercurrent. This value is related to the number of non-0 coefficients in the left and upper adjacent blocks of the current pixel block.
Take the size 4x4 macro block cutting method as an example. The relative position of the current pixel block with the left and upper adjacent blocks, for example, with:
For the current pixel block. If the upper and left adjacent blocks are not visible (unavailable), then the numbercurrent value of the current pixel block is 0, and if the upper or left side, there is only one adjacent block visible. Then the numbercurrent value of the current pixel block is the number of non-0 coefficients in the adjacent block Numcoeff; If two adjacent blocks are visible, the numbercurrent value of the current pixel block is the rounded average of two adjacent blocks Numcoeff.
3. Resolving the total number of non-0 coefficients and the number of trailing coefficients
In the parsing process of CAVLC. The total number of non-0 coefficients Numcoeff and the number of trailing coefficients trailingones two values are resolved together.
The two values are parsed according to table 9-5 in the standard document, for example, the following table is part of table 9-5:
Based on the previously resolved numbercurrent values, select a column in this table as a reference for decoding data. Thereafter, the binary stream of the corresponding length is read from the bitstream. Compare to the values in the table. When the stream matches the values in the table, the first two columns of the table are the subscripts of the array. The value is equal to the value of Numcoeff and trailingones that you want to parse out.
4. Parsing the symbol of the trailing factor
We know that the number of non-0 coefficients of the highest frequency in the matrix of the transformation coefficients is called the trailing factor, which has a range of 0~3.
The symbol representing each trailing factor can be represented by a bit of Trailing_ones_sign_flag:
- When Trailing_ones_sign_flag is 1, the trailing factor symbol is-.
- When the Trailing_ones_sign_flag is 0, the trailing factor symbol is +;
5. Resolution of amplitudes of non-0 coefficients
The amplitude of non-trailing 0 coefficients is usually expressed as levels.
The resolution of levels is relatively complex. This section is based on a non-0 factor that resolves from the highest frequency to the lowest frequency. In other words, the levels part is parsed in reverse frequency order.
At the time of parsing each level. Each value is parsed according to the prefix (prefix) and suffix (suffix) two parts.
5.1 Parsing the Level_prefix section:
The level_prefix part is the prefix portion of the level, which is simpler to parse, and is represented by pseudo-code such as:
leadingZeroBits = ?1for( b = 0; !b; leadingZeroBits++ ) b = read_bits( 1 )level_prefix = leadingZeroBits
In conjunction with the presentation of table 9-6 in the standard documentation. The level prefix value is the number of consecutive bits 0 before the next bit 1 of the current stream.
5.2 Parsing the Level_suffix section:
Level_suffix part of the resolution than the prefix part of the complex, the overall can be divided into the following several steps:
- Before the parsing process starts. Initialize the value of the Suffixlength: When the total number of non-0 coefficients Numcoeff is greater than 10 and the number of trailing coefficients trailingones equals 3 o'clock, Suffixlength is initialized to 1, otherwise initialized to 0;
- Determine the value of levelsuffixsize: Typically, the value of levelsuffixsize is equal to the current suffixlength. In addition to the following two types of contingencies: first. The value of Level_prefix is equal to 14 and Suffixlength is 0, at this time Levelsuffixsize is set to 4, second, Level_prefix is greater than or equal to 15, Levelsuffixsize is set to level_prefix-3 at this time.
- Resolves the value of Level_suffix: As a length based on the value of Levelsuffixsize. Reads the corresponding binary data in the stream as a level_suffix. If the levelsuffixsize is 0. The value of Level_suffix is 0;
5.3 by Level_prefix and Level_suffix part combinations become levelcode
After parsing Level_prefix and Level_suffix, combine the two to generate Levelcode.
The calculation method is:levelcode= (Min (15,level_prefix) <
5.3 Calculated level by Levelcode
The parity of the levelcode based on the calculated results. To infer the sign of level:
- If Levelcode is an even number, the return level value is (Levelcode + 2) >>1;
- If Levelcode is odd, the return level value is (? levelcode?1) >>1;
5.4 Updating the value of Suffixlength
Updating suffixlength in the process of parsing embodies the idea of context self-adaptation.
- When suffixlength = 0 o'clock. Suffixlength updated to 1;
- When Suffixlength is less than 6. And the level value that has just been resolved is greater than the threshold value of threshold, suffixlength self-increment 1; The threshold value threshold is defined as (3 << (suffixlength 1));
6. Parse 0 coefficient information
The 0 coefficients in the transformation coefficient matrix are also important information. The 0-Factor information analyzed by CAVLC is divided into two main categories:
- Totalzeros: A value for each matrix representing the total number of the first 0 coefficients of the highest-frequency non-0 coefficients;
- Runbefore: A value for each non-0 coefficient representing the total number of consecutive 0 preceding the non-0 coefficient.
The process of parsing Totalzeros is similar to parsing Numcoeff and Trailingones, which is to look up a column table from a two-dimensional table and find a value that matches the table in the stream. The index is then the Totalzeros value that is being asked. The table for parsing Totalzeros is table 9-7 in the standard document. is part of table 9-7:
In the process of parsing totalzeros. The index value of the selection table is equal to the non-0-series number Numcoeff of the current matrix block.
When the runbefore of each non-0 coefficient is parsed, it is also processed in reverse order from high frequency to low frequency. Each parsing Runbefore is also based on similar parsing methods. Reads the code stream of the corresponding length from the stream and matches the value in the table, and returns the index value as the parsed value. Table 9-10 of the Analytical Runbefore reference standard document:
Each time a runbefore is parsed, Totalzeros subtracts the value and then takes the next processing. If there are n non-0 coefficients. There is a total need to parse n-1 Runbefore. The minimum frequency of non-0 coefficients before the Runbefore does not need to be written in the stream, because it can be inferred from the above information.
The above is the main idea and process of parsing the 4x4 residual coefficient matrix of a macro block corresponding to the grammatical elements. Of course, the actual parsing process is much more complicated than this, and more specific cases can be seen in the course of the CSDN Academy: H.264/AVC Video codec technology specific explanations to watch.
"H.264/AVC Video codec technology specific explanation" 13, Entropy coding Algorithm (4): H. CAVLC parsing the residual data of a macro block