"H.264/AVC Video Codec technology detailed" 13, Entropy coding Algorithm (4): H. CAVLC parsing the residual data of a macro block

Source: Internet
Author: User

"H.264/AVC Video Codec Technology detailed" 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 the resolution and implementation of H. A, Welcome to watch! "The paper came to the end of shallow, I know this matter to preach", only by themselves in accordance with the standard document in the form of code to operate, in order to video compression coding standard ideas and methods have a profound understanding and experience! Link Address: H.264/AVC Video codec technology detailed GitHub code address: Click here 1. The process of parsing macro-block residuals data with H. CAVLC

The process of decoding the residual data of a macro block is similar to the inverse process of the CAVLC encoding mentioned above. When parsing a macro block residuals, the first is to parse the non-0 coefficients of the residual matrix and the number of trailing coefficients Numcoeff and trailingones. Then is the symbol trailingsignsfor 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 parsing 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 top adjacent blocks of the current pixel block.

Take size 4x4 macro block segmentation as an example. The relative position of the current pixel block with the left and upper adjacent blocks is as follows:

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 the left side, there is only one adjacent block is 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 by table 9-5 in the standard document, as the following table is part of table 9-5:

Based on the previously parsed numbercurrent value, select a column in this table as a reference for decoding the data. Thereafter, the binary stream of the corresponding length is read from the stream, compared 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, and their values are equal to the values of the 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. A symbol that represents each trailing factor can be represented by a bit of Trailing_ones_sign_flag:

    • When the 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 a non-0 factor that starts at the highest frequency and resolves to the lowest frequency. In other words, the levels part is parsed in reverse frequency order.

At 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 representation of table 9-6 in the standard document, the level prefix value is the number of bits 0 contiguous 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 steps:

    1. Before the parsing process begins, initialize the value of Suffixlength: When the total number of non-0 coefficients is numcoeff greater than 10 and the number of trailing coefficients is trailingones equal to 3 o'clock, Suffixlength is initialized to 1, otherwise initialized to 0;
    2. Determine the value of the levelsuffixsize: Typically, the value of Levelsuffixsize equals the current suffixlength except for the following two exceptions: first, the value of Level_prefix equals 14 and Suffixlength is 0, At this time Levelsuffixsize is set to 4, second, Level_prefix is greater than or equal to 15, at this time levelsuffixsize is set to level_prefix-3;
    3. Parse the value of Level_suffix: According to the value of levelsuffixsize as the length, read the corresponding binary data in the stream as Level_suffix, if the levelsuffixsize is 0, then the value of Level_suffix is 0;
5.3 by Level_prefix and Level_suffix part combinations become levelcode

After parsing completes Level_prefix and Level_suffix, a combination of the two is generated levelcode. The calculation method is:levelcode= (Min (15,level_prefix) <

5.3 Calculated level by Levelcode

According to the levelcode of the calculated results, the symbol of level is judged:

    • 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 is updated to 1;
    • When the suffixlength is less than 6 and the level value just resolved is greater than the threshold value threshold, the suffixlength is increased by 1, and the threshold 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 of 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, find the value that matches the table from the stream, and then index 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:

During parsing of Totalzeros, the index value of the selected table is equal to the non-0-series number of the current matrix block Numcoeff.

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, reading the corresponding length stream from the stream and matching the value in the table, and then returning the index value as the parsed value. Table 9-10 of the parsing Runbefore reference standard Documentation:

Each time a runbefore is parsed, Totalzeros subtracts the value and then takes the next processing. If there are n non-0 coefficients, then a total of n-1 runbefore must be parsed. 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 corresponding grammatical elements of a 4x4 residual coefficient matrix of a macro block. Of course, the actual parsing process is much more complicated than this, and more details can be seen in the course of the CSDN Academy: H.264/AVC Video codec technology in a detailed view.

"H.264/AVC Video Codec technology detailed" 13, Entropy coding Algorithm (4): H. CAVLC parsing the residual data of a macro block

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.