H.264 study notes 5-cavlc of entropy Encoding

Source: Internet
Author: User

In H.264, after the pixel blocks of 4x4 are transformed and quantified, the low-frequency signal is concentrated in the upper left corner, and a large number of high-frequency signals are concentrated in the lower right corner. The low-frequency signal on the left is relatively large, while a large number of high-frequency signals in the lower right corner are quantified to 0, 1, and-1. The residual information after transformation quantization has certain statistical characteristics and rules.

Cavlc (context-based adaptive variable-length code): context-based Variable Length Encoding, Which is H. in 264, the 4x4 pixel block is used for entropy encoding. In basic (baseline) grades, only cavlc can be used. cabac can be used only for major grades and extended grades (see Note: cabac of entropy encoding ).

I,4x4 pixel residual after zag scan (z scan,Encoding ProcessIncluding:

A. encoding of the number of non-zero coefficients (totalcoeffs) and the number of trailing coefficients (trailingones:

Tail drag coefficient: After a Z scan, the number of consecutive 1 or-1 (which can be separated by any number of 0 in the middle) appears in the high-frequency signal at the end. The tail drag coefficient can have a maximum of 5. When the number of consecutive 1 or-1 exceeds 3, only the last 3 1 or-1 is the tail coefficient, and others are treated as normal non-zero coefficients.

Totalcoeffs and trailingones are encoded using the Table query method. H.264 provides four Variable Length tables and one fixed length table for totalcoeffs and trailingones (see table 9-5 ). The selection of the encoding table is determined by NC, And the NC value is determined by the context information. For the chromium DC signal, NC =-1; for other NC, the number of non-zero coefficients of the 4x4 block on the left of the current block and the 4x4 block on the top is determined by a and B. For example, in table 1, X indicates that the block and the current block belong to the same slice and are available. The policy for selecting an encoding table based on NC is shown in table 2:

Table 1
A (left) B (above) NC
X X (A + B)/2
X - A
- X B
- - 0
Table 2
NC Code table number
0, 1 Variable Length table 1
2, 3 Variable Length table 2
4,5, 6,7 Variable Length table 3
> = 8 Fixed Length table
-1 Variable Length table 4

After determining the selected table through NC, the encoded binary is output.

B. The positive and negative code of each tail coefficient (according to the reverse code of the Z scanning result ):

Encode the symbols of each tail coefficient in reverse order, and use 0 to represent 1 (positive) and 1 to represent-1 (negative). The encoding result is output.

C. Each non-zero coefficient amplitude (Level, containing positive and negative numbers) except the tail coefficient is encoded (according to the reverse order of the Z scan results ):

The code of the tail coefficient amplitude includes the prefix level_prefix and suffix level_suffix. In addition, suffixlength is updated in real time according to level_suffix and level based on context information during the encoding process. The specific process is as follows:

1. Set the initial suffixlength:

When totalcoeffs> 10 and trailingones <= 1, suffixlength is set to 1; otherwise, it is set to 0;

2. convert a signed level to an unsigned levelcode:

If level> 0: levelcode = (level <1)-2;

If level <0: levelcode =-(level <1)-1;

In this way, the level positive and negative can be determined based on the parity of levelcode, and the signed level can be decoded Based on levelcode.

3. Calculate level_prefix and level_suffix:

Level_prefix = levelcode/(1 <suffixlength );

Level_suffix = levelcode % (1 <suffixlength );

4. level_prefix and level_suffix encoding:

Encoding level_prefix is obtained by checking the standard table 9-6 (see Appendix 9-6). The Code is the prefix, so it can be decoded even if it is unique. Level_suffix encoding is the binary unsigned form of level_suffix. Then, the level_prefix and level_suffix encoding results are output in sequence, but when suffixlength = 0, there is no level_suffix and no output is required.

5. Update the value of suffixlength and return to step 2 to encode the next non-zero coefficient. The update process can be represented by the following code:

1 if(SuffixLength == 0)2     SuffixLength++;3 else if (abs(Level) > (3 << (SuffixLength -1)) && SuffixLength < 6)4     SuffixLength++;

That is, when suffixlength is 0, suffixlength is added to 1; When suffixlength reaches 6, suffixlength is not updated; When suffixlength is between 1 and 6, if the absolute value of the currently encoded non-zero coefficient (ABS (level) is greater than the given threshold value S, the suffixlength increases by 1, where the threshold S is: S = 3*2 ^ (SuffixLength-1) = 3 <(SuffixLength-1 ).

D. The number of the first 0 of the last Non-zero coefficient (totalzeros) encoding: Search for standard table 9-7 (see Appendix 9-7 )~ 9-9

E. runbefore encoding of the number of consecutive zeros before each non-zero coefficient (according to the reverse encoding of the Z scanning result): Find the standard table 9-10 (see table 9-10)

During the encoding process, zerosleft indicates the number of all 0 values on the left of the current non-zero coefficient of the encoding. The number of 0 values before the non-zero coefficient of the last (last in the reverse order) does not need to be encoded.

II,For the 4x4 Residual Block after encoding,Decoding processIncluding:

Iii. Example:For residual blocks of 4x4, such:

0 3 -1 0
0 -1 1 0
1 0 0 0
0 0 0 0

After Z scanning, the sequence is obtained:,-1,-, 0, 0, 0.

PerformEncodingAs follows:

1. Initial Value Setting:

Totalcoeffs = 5; trailingones = 3; totalzeros = 3; assume NC = 1; suffixlength = 0; the final encoding output code stream is out.

2. Encoding totalcoeffs and trailingones:

Check the table 9-5. When totalcoeffs = 5, trailingones = 3 and 0 <= NC <2, the encoding result is 0000 100.

In this case, out = 0000 100.

3. drag-and-tail coefficient symbols:

The tail coefficient is 1,-1,-1 (scan backward), and the corresponding symbol is encoded as 0, 1, 1. So now out = 0000 1000 11.

4. encode the amplitude level of each non-tail non-zero coefficient:

The non-zero coefficient to be encoded is 1, 3 (reverse z scan). The initial I = 2 is as follows:

Level [I --] = 1; levelcode = 0, level_prefix = 0, no level_suffix (because suffixlength = 0) is obtained, and the encoding result of Table 9-6 is 1. In this case, out = 0000 1000 111.

Then update suffixlength and suffixlength ++ to obtain suffixlength = 1;

Level [I --] = 3; levelcode = 4, level_prefix = 2, level_suffix = 0. The level_prefix encoding result of Table 9-6 is 001, and then the level_suffix binary is 0.

Out = 0000 1000 1110 010. At this time, I = 0. The encoding is complete.

5. Encoding totalzeros: the encoding result of Table 9-7 is 111. In this case, out = 0000 1000 1110 0101 11.

6. encode the number of consecutive o before each non-zero coefficient: the number of consecutive 0 before the four non-zero coefficients must be encoded. The initial I = 5. The encoding process for table 9-10 is as follows:

Zerosleft = 3, runbefore = 1, level [I --] = 1, and the encoding result is 10;

Zerosleft = 2, runbefore = 0, level [I --] =-1, and the encoding result is 1;

Zerosleft = 2, runbefore = 0, level [I --] =-1, and the encoding result is 1;

Zerosleft = 2, runbefore = 1, level [I --] = 1, and the encoding result is 01;

Zerosleft = 1, runbefore = 1, level [I --] = 3, corresponding to the first non-zero coefficient, no encoding required;

The output result is out = 0000 1000 1110 0101 1110 1101.

CorrespondingDecodingAs follows:

Iv. Appendix:

  

 

H.264 study notes 5-cavlc of entropy Encoding

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.