H.264 framing -3. Golomb coding

 The above comes first_mb_in_slice slice header to framing. Thus, viewed in the standard slice_header first_mb_in_slice descriptors, and found to be ue (v). Expand learning ue (v).

Golomb coding

 Defined by the query descriptor:

 - ue (v): unsigned integer Exp-Golomb-coded syntax element, left bit first.

 The descriptor relates to a new term, exponential Golomb coding, then the removal of the introductory text Golomb coding.

 Golomb coding is a lossless data compression method, a mathematician Solomon W.Golomb invention in the 1960s. Golomb encoding only for non-negative integer is encoded, the probability of the symbol table symbol appears in line when the geometric distribution (Geometric Distribution), using Golomb coding can achieve optimal results, Golomb coding that is more suitable for small numbers larger than relatively high probability of coded numbers appear. It uses a smaller length-coded digital shorter, longer-length coding larger numbers.

 Golomb coding is block coding, requires a positive integer parameter m, and in m numbers of packets to be encoded, as shown below,
Columbus coded packet
 for any non-negative to be coded positive integer N, which is divided into two Golomb coding section: where the number of the group GroupID and after grouping the remaining portion, GroupID is actually to be coded number N and the parameter m quotient, the remaining part is a remainder quotient, specifically calculated as follows:
 Q = N / m,
 R & lt = N % m
 for the number of group Q obtained using unary coded, R is the remainder of a fixed length using binary encoding.
 Unary coded (Unary coding) is only a simple method for encoding a non-negative integer, for any non-negative integer num, it is unary coded num behind a 1 followed by a 0.
 With the above description Golomb coding, Golomb coding index can be further analyzed.

Exponential-Golomb coding

 Golomb coding with respect to the normal, exponential Golomb coding has a greater improvement when the packet is no longer used as a fixed size m, and the size of the group is growing exponentially, m must be a power of 2, see the following figure,
Exponential Golomb coded packet
 symbol Golomb coding index structure is: ** [M zeros prefix] [ 1] [Offset] **, where M is the number of packets GroupID, 1 can look at a separator, is biased in the group Offset shift amount.
 Exponential-Golomb requires a non-negative integer K as a parameter, called K-order exponential Golomb. Wherein, when K = 0, the 0-order index called Golomb, H.264 video coding standard we need to use is the use of the 0-order index Golomb, and can be arbitrary order K goes to 0-order Exp- Golomb coding.
 Table I to show the removal of a 0-order exponential Golomb (Table preamble and a delimiter is 01), the following table
0-order exponential Golomb coding table
 values above table shows that for m group (Group ID) of Golomb coding, can represent range is
2 m 1 n < 2 m + 1 1 2^m-1 \leq n<2^{m+1}-1
 thus be derived for non-negative integer value of n, for Golomb coding, group number
m = l o g 2 n + 1 m = \left \lfloor log_{2}^{n+1} \right \rfloor
 then have group numbers m, n has a value for the encoding process can be expressed out.
 - group number m of unary encoded, m successive writing a 0
 - to calculate the offset of the symbol structure, n-offset = - 2 ^ m
 - m takes the offset in the low bit binary
 0-order exponential Golomb coding , the encoded length of 2 * m + 1, which recommends the removal of the decoding process described in the book of 9.1:

 The syntax element parsing process starts reading the bit stream is the current bit position, comprises a non-zero bits, until the number is 0 leading_bits. Using the following procedure:

	leadingZeroBits = -1;
	for(b = 0; !b; leadingZeroBits++)
    	b = read_bits(1);

CodeNum variable assignment as follows:
c o d e N u m = 2 l e a d i n g Z e r o B i t s 1 + r e a d _ b i t s ( l e a d i n g Z e r o B i t s ) codeNum = 2^{leadingZeroBits} - 1 + read\_bits(leadingZeroBits)
where read_bits (leadingZeroBits) a return value bit first binary unsigned integer.

Optimization:
 Through the above analysis, the value of first_mb_in_slice through determination to determine whether a new one, only determination ue (v) is 0 can not resolve the need to remove the entire Golomb coding. More involved in anti-analytic calculation will consume a long time.
 Therefore, when the practical application of the present embodiment, only the first byte of slice_header operation can be carried out in a 0x80 and. However, for subsequent expansion, in the preparation of the particular function value calculated whether Golomb adds a switching parameter bIsZero.
 Conjunction with the above, the final preparation of the Exponential-Golomb code is as follows:

unsigned int GolombCode(unsigned char *pbyData, int nBytePosition, bool bIsZero)
{
    int nLeadingZeroBits = -1;  // 前导零的位数
    unsigned int dwCodeNum = 0;          // CodeNum值
    unsigned int dwTail = 0;             // 编码后缀
    unsigned int dwOffset = 0;           // 移位偏移量
    unsigned char byPos = 0x80;           // & 变量
    unsigned int dwOffsetByte  = 0;      // 偏移字节数

    if (bIsZero)
    {
        return !(pbyData[nBytePosition+5] & byPos);
    }
    /* 得到前导零的数量 */
    for(int b = 0; !b; nLeadingZeroBits++)
    {
        if (!((nLeadingZeroBits + 1) % 8) && (nLeadingZeroBits + 1))
        {
            dwOffsetByte++;
            byPos = 0x80;
        }
        b = pbyData[nBytePosition + 5 + dwOffsetByte] & byPos;
        byPos >>= 1;
    }

    byPos = 0x80;

    /* 后缀计算 */
    for(int k = nLeadingZeroBits; k >= 0; k--)
    {
        dwOffset = 2 * nLeadingZeroBits - k + 1;
        dwTail += (u32)pow(2.0, k - 1) * (pbyData[nBytePosition + 5 + dwOffset / 8] & (byPos >> ((dwOffset % 8) ? 1 : 0)));
    }

    /* ue(v)的值计算 */
    dwCodeNum = (u32)pow(2.0, (s32)nLeadingZeroBits) - 1 + dwTail;

    return dwCodeNum;
}
Published 60 original articles · won praise 18 · views 20000 +

Guess you like

Origin blog.csdn.net/BadAyase/article/details/103489291