完整的分析mpeg2 video

转自:http://www.cnitblog.com/vcommon/archive/2007/05/27/27662.html


举例分析:

首先是一段例子:

Test.m2v

 

00 00 01 B3 08 00 80 23 00 FA 20 30 00 00 01 B5

 

根据13813-2 Table 6-1 Start code values: 00 00 01 B3 为sequence_header_code.根据6.2.2节(附)                                               

horizontal_size_value(12 bits):08 0 = 128

vertical_size_value(12 bits):0 80 = 128

aspect_ratio_information(4 bits)  = 2

frame_rate_code (4 bits) = 3

bit_rate_value(18 bits) = 00 FA 2>>2 = 0000 0000 1111 1010 00 = 1000

marker_bit(1 bit) = 1

vbv_buffer_size_value(10 bits) = 0 0000 0011 0 = 6

constrained_parameters_flag(1 bit) = 0
load_intra_quantiser_matrix( 1bit) = 0

load_non_intra_quantiser_matrix(1bit) = 0

 

00 00 01 b5 extension_start_code

 

14 82 00 01 00 00 00 00 01 B5 23 05 05 05 02 02

04 00 00 00 00 01 B2

extension_start_code_identifier(4 bits) = 1

profile_and_level_indication(8 bit) = 48

progressive_sequence( 1 bit) = 0

chroma_format(2 bits) = 01

horizontal_size_extension(2bit) = 0

vertical_size_extension(2 bit) = 0

bit_rate_extension(12 bit) = 0 0000 0000 000

marker_bit(1 bit) = 1

vbv_buffer_size_extension(8 bits) = 00

low_delay(1 bit) = 0

frame_rate_extension_n(2 bit) = 00

frame_rate_extension_d(5 bit) = 00000

 

接着,下组是Extension and user data  ,00 00 01 B5 extension_start_code,所以接下来是extension_data( i ),

extension_start_code_identifier(4bit) = 2, Sequence Display Extension ID

video_format((3 bit) = 001

colour_description(1bit)=1

  colour_primaries(8) = 05

  transfer_characteristics(8)=05

  matrix_coefficients(8) = 05

display_horizontal_size(14) = 0000 0010 0000 00

marker_bit(1 bit) = 1

display_vertical_size(14) = 0 0000 0100 0000 0

还剩余了3bit 000

 

接下来是00 00 01 b2 user_data_start_code,user_data(),我们忽略它,因为他是用户自定义的。

 

         00 00 01 B2 4D 50 45 47 2D32 20 56 65 72

69 66 69 63 61 74 69 6F5E20 53 65 71 75 65 6E

63 65 0A 00 00 01 B8

 

00 00 01 B8 ,group_start_code, group_of_pictures_header

       00 00 01 B8 5FBF 6C 40

time_code(25): 0101 1111 1011 1111 0110 1100 0 = 49022

closed_gop(1): 1

broken_link(1):0

剩余5bit 0 0000

 

                            00 00 01 00 00

0A 58 58 00 00 01 B5

00 00 01 00, picture_start_code, picture_header

temporal_reference(10): 0000 0000 00

picture_coding_type(3): 00 1

vbv_delay(16):001 1000 1001 1

extra_bit_picture(1):0

         

        00 00 01 B5 8F FF F7 CC 00 00 00 01 01

00 00 01 B5: extension_start_code,所以接下来是extension_data( i ),

extension_start_code_identifier(4bit) = 8, Picture Coding Extension ID,6.2.3.1节

 

f_code[0][0]   /* forward horizontal */(4): F

f_code[0][1]   /* forward vertical */(4):F

f_code[1][0]   /* backward horizontal */(4):F

f_code[1][1]   /* backward vertical */(4):F

intra_dc_precision(2): 01

picture_structure(2): 11

top_field_first(1):1

frame_pred_frame_dct(1):1

concealment_motion_vectors(1):0

q_scale_type(1):0

intra_vlc_format:(1):1

alternate_scan(1);1

repeat_first_field(1):0

chroma_420_type(1):0

progressive_frame(1);0

composite_display_flag(1):0

 

所以接下来将是picture_data,即是很多slice

00 00 01 01: slice_start_code,

Sequence header中horizontal_size_value 和Sequence header extention中的horizontal_size 组成了horizontal_size。

53 D0 54 90 F1 E7 21 48 18 A0 3C24 B6 F3 4A D2

 

quantiser_scale_code(5): 0101 0 = 10

extra_bit_slice /* with the value “0” */ (1):0

接下来就是macroblock()了。

 

macroblock_address_increment(1-11) — This is a variable length coded integer coded as per Annex B Table B-1,

查表得:macroblock_address_increment  = 1

macroblock_modes():table 6.2.51.

macroblock_type(1-9): Tables B-2 through B-8, selected by picture_coding_type and scalable_mode.

 

1 1101 0000  

查表得:macroblock_type = 1,I picture,no scale

              macroblock_quant = 0

              macroblock_motion_forward = 0

              macroblock_motion_backward = 0

              macroblock_pattern = 0

              macroblock_intra = 1

              spatial_temporal_weight_code_flag = 0

              permitted spatial_temporal_weight_classes:0 ,Intra

所以没有其他结构,block_count = Table 6-20(并根据chroma_format’10’ = ‘4:2:0‘ see Table 6-5 8-5) 全是block = 6。

 

VLC见7.2节:

对于前4个blcok,cc = 0.cc = 0,使用B-12,cc!=0,使用B13

First DCT coefficient(3-24)即是DC系数,根据B-12,B13.

First DCT coefficient = 110, dct_dc_size_luminance = 4,所以dct_dc_differential(=4bit)

dct_dc_differential = 1 000

pattern_code[i] = 1 默认?

First DCT coefficient应该 = 预测值+differential,预测值初始化0,然后[i]的预测值变为1000 = 8, intra_dc_precision((picture_coding_extension) = 01, 所以Precision (bits) = 9, 由7.4.1得

First DCT coefficient = 8*4 = 32。

 

 

然后是接下来的AC系数。

53 D0 54        90       F1       E7       21      

48      18        A0       3C      24

B6      F3      4A        D2

0 0101 0100 1001 0000 1111 0001 1110 0111 0010 0001

0100 1000 0001 0100 1010 0000 0011 1100 0010 0100

1011 0110 1111 0011 0100 1010 1101 0010 

根据b-14,B-15得:

AC:intra_vlc_format (picture_coding_extension) = 1,macroblock_intra = 1,所以使用B-15

quantiser_scale_code (slice header)= 10, q_scale_type(picture_coding_extension) = 0, quantiser_scale[q_scale_type] = 20.根据7.4.2.3 intra_block,加权系数根据6.2.3.2决定,或6.3.11有个默认矩阵。矩阵z字型对应alternate_scan(picturecodeing_extension)决定。

val = val * quantiser_scale[q_scale_type] * w[]/16;

00101: run 2 level 1 len5,run代表0的个数。,AC[1] = 0,AC[2] = 0

0:signed,所以AC[3] = 1 计算= 1* 20* 22/16 = 27

10:run 0 level 1 len 2,

0:signed,AC[4]=1 计算 =1*20*16/16 = 20

0 1001

。。。。。。。

最后得到一个block:

32 20 23 27 32 -33 0 0

0 20 0 0 0 0 0 0

0 0 0 0 36 0 0 0

27 0 0 33 0 0 0 0

-27 0 0 0 0 0 0 0

0 -33 36 0 87 0 -60 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

 

 

根据alter的z-zig的排列,dc = 32, ac[1] = 0,ac[2] = 0,ac[3] = 27,ac[4] = 20,……图II2-7.3

 

然后经过IDCT:

38 4 -35 7 28 -15 -9 18

…….

 

然后把所有变成一个范围内的Clip.

把所有的block到结束时,就行成了一个完整的Frame.

                     

 

 

 

附录,主要

Table 6-1 — Start code values

Name

start code value

(hexadecimal)

picture_start_code

00

Slice_start_code

01 through AF

Reserved

B0

Reserved

B1

User_data_start_code

B2

sequence_header_code

B3

sequence_error_code

B4

extension_start_code

B5

Reserved

B6

Sequence_end_code

B7

group_start_code

B8

system start codes (see note)

B9 through FF

NOTE - system start codes are defined in Part 1 of this specification

 

6.2.2节:

video_sequence() {

        next_start_code()

        sequence_header()

        if ( nextbits() == extension_start_code ) {

                sequence_extension()

                do {

                        extension_and_user_data( 0 )

                        do {

                                if (nextbits() == group_start_code) {

                                        group_of_pictures_header()

                                        Extension_and_user_data( 1 )

                                }

                                picture_header()

                                picture_coding_extension()

                                extensions_and_user_data( 2 )

                                picture_data()

                        } while ( (nextbits() == picture_start_code) ||

                                        (nextbits() == group_start_code) )

                        if ( nextbits() != sequence_end_code ) {

                                sequence_header()

                                sequence_extension()

                        }

                } while ( nextbits() != sequence_end_code )

        } else {

                /* ISO/IEC 11172-2 */

        }

        sequence_end_code

}

 

6.2.2.1            Sequence header

sequence_header() {

No. of bits

Mnemonic

        sequence_header_code

32

bslbf

        horizontal_size_value

12

uimsbf

        vertical_size_value

12

uimsbf

        aspect_ratio_information

4

uimsbf

        frame_rate_code

4

uimsbf

        bit_rate_value

18

uimsbf

        marker_bit

1

bslbf

        vbv_buffer_size_value

10

uimsbf

        constrained_parameters_flag

1

 

        load_intra_quantiser_matrix

1

 

        if ( load_intra_quantiser_matrix )

 

 

                intra_quantiser_matrix[64]    

8*64

uimsbf

        load_non_intra_quantiser_matrix

1

 

        if ( load_non_intra_quantiser_matrix )

 

 

                non_intra_quantiser_matrix[64]

8*64

uimsbf

        next_start_code()

 

 

}

 

 

 

6.2.2.3            Sequence extension

sequence_extension() {

No. of bits

Mnemonic

        extension_start_code

32

bslbf

        extension_start_code_identifier

4

uimsbf

        profile_and_level_indication

8

uimsbf

        progressive_sequence

1

uimsbf

        chroma_format

2

uimsbf

        horizontal_size_extension

2

uimsbf

        vertical_size_extension

2

uimsbf

        bit_rate_extension

12

uimsbf

        marker_bit

1

bslbf

        vbv_buffer_size_extension

8

uimsbf

        low_delay

1

uimsbf

        frame_rate_extension_n

2

uimsbf

        frame_rate_extension_d

5

uimsbf

        next_start_code()

 

 

}

 

 

 

6.2.2.2            Extension and user data

extension_and_user_data( i ) {

No. of bits

Mnemonic

        while ( ( ( i != 1) && ( nextbits()== extension_start_code ) ) ||

 

 

                        ( nextbits()== user_data_start_code ) ) {

 

 

                if ( nextbits()== extension_start_code )

 

 

                        extension_data( i )

 

 

                if ( nextbits()== user_data_start_code )

 

 

                        user_data()

 

 

        }

 

 

}

 

 

Table 6-2. extension_start_code_identifier codes.

extension_start_code_identifier

Name

0000

reserved

0001

Sequence Extension ID

0010

Sequence Display Extension ID

0011

Quant Matrix Extension ID

0100

Copyright Extension ID

0101

Sequence Scalable Extension ID

0110

reserved

0111

Picture Display Extension ID

1000

Picture Coding Extension ID

1001

Picture Spatial Scalable Extension ID

1010

Picture Temporal Scalable Extension ID

1011

reserved

1100

reserved

...

...

1111

reserved

 

6.2.2.4            Sequence display extension

sequence_display_extension() {

No. of bits

Mnemonic

        extension_start_code_identifier

4

uimsbf

        video_format

3

uimsbf

        colour_description

1

uimsbf

        if ( colour_description ) {

 

 

                colour_primaries

8

uimsbf

                transfer_characteristics

8

uimsbf

                matrix_coefficients

8

uimsbf

        }

 

 

        display_horizontal_size

14

uimsbf

        marker_bit

1

bslbf

        display_vertical_size

14

uimsbf

        next_start_code()

 

 

}

 

 

 

6.2.2.2.2   User data

user_data() {

No. of bits

Mnemonic

        user_data_start_code

32

bslbf

        while( nextbits() != ‘0000 0000 0000 0000 0000 0001’) {

 

 

                user_data

8

 

        }

 

 

        next_start_code()

 

 

}

 

 

 

6.2.2.6            Group of pictures header

group_of_pictures_header() {

No. of bits

Mnemonic

        group_start_code

32

bslbf

        time_code

25

bslbf

        closed_gop

1

uimsbf

        broken_link

1

uimsbf

        next_start_code()

 

 

}

 

 

 

6.2.3   Picture header

picture_header()  {

No. of bits

Mnemonic

        picture_start_code

32

bslbf

        temporal_reference

10

uimsbf

        picture_coding_type

3

uimsbf

        vbv_delay

16

uimsbf

        if ( picture_coding_type == 2 || picture_coding_type == 3) {

 

 

                full_pel_forward_vector

1

 

                forward_f_code

3

uimsbf

        }

 

 

        if ( picture_coding_type == 3 ) {

 

 

                full_pel_backward_vector

1

 

                backward_f_code

3

uimsbf

        }

 

 

        while ( nextbits() == '1' ) {

 

 

                extra_bit_picture        /* with the value “1”*/

1

uimsbf

                extra_information_picture

8

 

        }

 

 

        extra_bit_picture        /* with the value “0” */

1

uimsbf

        next_start_code()

 

 

}

 

 

 

6.2.3.1            Picture coding extension

picture_coding_extension() {

No . of bits

Mnemonic

        extension_start_code

32

bslbf

        extension_start_code_identifier

4

uimsbf

        f_code[0][0]  /* forward horizontal */

4

uimsbf

        f_code[0][1]  /* forward vertical */

4

uimsbf

        f_code[1][0]  /* backward horizontal */

4

uimsbf

        f_code[1][1]  /* backward vertical */

4

uimsbf

        intra_dc_precision

2

uimsbf

        picture_structure

2

uimsbf

        top_field_first

1

uimsbf

        frame_pred_frame_dct

1

uimsbf

        concealment_motion_vectors

1

uimsbf

        q_scale_type

1

uimsbf

        intra_vlc_format

1

uimsbf

        alternate_scan

1

uimsbf

        repeat_first_field

1

uimsbf

        chroma_420_type

1

uimsbf

        progressive_frame

1

uimsbf

        composite_display_flag

1

uimsbf

        if ( composite_display_flag ) {

 

 

                v_axis

1

uimsbf

                field_sequence

3

uimsbf

                sub_carrier

1

uimsbf

                burst_amplitude

7

uimsbf

                sub_carrier_phase

8

uimsbf

        }

 

 

        next_start_code()

 

 

}

 

 

 

6.2.3.6            Picture data

picture_data() {

No. of bits

Mnemonic

        do {

 

 

                slice()

 

 

        } while ( nextbits() == slice_start_code )

 

 

        next_start_code()

 

 

}

 

 

 

6.2.4   Slice

slice() {

No. of bits

Mnemonic

        slice_start_code

32

bslbf

        if (vertical_size > 2800)

 

 

                slice_vertical_position_extension

3

uimsbf

        if ( <sequence_scalable_extension() is present in the bitstream> )

 

 

                if (scalable_mode == “data partitioning” )

 

 

                        priority_breakpoint

7

uimsbf

        quantiser_scale_code

5

uimsbf

        if ( nextbits() == '1' ) {

 

 

                intra_slice_flag

1

bslbf

                intra_slice

1

uimsbf

                reserved_bits

7

uimsbf

                while ( nextbits() == '1' ) {

 

 

                        extra_bit_slice     /* with the value “1”*/

1

uimsbf

                        extra_information_slice

8

 

                }

 

 

        }

 

 

        extra_bit_slice     /* with the value “0” */

1

Uimsbf

        do {

 

 

                macroblock()

 

 

        } while ( nextbits() != '000 0000 0000 0000 0000 0000' )

 

 

        next_start_code()

 

 

}

 

 

 

B.1    Macroblock addressing

Table B-1 --- Variable length codes for macroblock_address_increment

macroblock_address_ increment VLC code

increment value

macroblock_address_ increment VLC code

increment value

1

1

0000 0101 01

18

011

2

0000 0101 00

19

010

3

0000 0100 11

20

0011

4

0000 0100 10

21

0010

5

0000 0100 011

22

0001 1

6

0000 0100 010

23

0001 0

7

0000 0100 001

24

0000 111

8

0000 0100 000

25

0000 110

9

0000 0011 111

26

0000 1011

10

0000 0011 110

27

0000 1010

11

0000 0011 101

28

0000 1001

12

0000 0011 100

29

0000 1000

13

0000 0011 011

30

0000 0111

14

0000 0011 010

31

0000 0110

15

0000 0011 001

32

0000 0101 11

16

0000 0011 000

33

0000 0101 10

17

0000 0001 000

macroblock_escape

Note:              The “macroblock stuffing” entry that is available in ISO/IEC11172-2  is not available in this specification.

B.2    Macroblock type

The properties of the macroblock are determined by the macroblock type VLC according to these tables.

Table B-2 — Variable length codes for macroblock_type in I-pictures

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

1

0

0

0

0

1

0

Intra

0

01

1

0

0

0

1

0

Intra, Quant

0

 

Table B-3 — Variable length codes for macroblock_type in P-pictures

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

1

0

1

0

1

0

0

MC, Coded

0

01

0

0

0

1

0

0

No MC, Coded

0

001

0

1

0

0

0

0

MC, Not Coded

0

0001 1

0

0

0

0

1

0

Intra

0

0001 0

1

1

0

1

0

0

MC, Coded, Quant

0

0000 1

1

0

0

1

0

0

No MC, Coded, Quant

0

0000 01

1

0

0

0

1

0

Intra, Quant

0

 

Table B-4 — Variable length codes for macroblock_type in B-pictures

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

10

0

1

1

0

0

0

Interp, Not Coded

0

11

0

1

1

1

0

0

Interp, Coded

0

010

0

0

1

0

0

0

Bwd, Not Coded

0

011

0

0

1

1

0

0

Bwd, Coded

0

0010

0

1

0

0

0

0

Fwd, Not Coded

0

0011

0

1

0

1

0

0

Fwd, Coded

0

0001 1

0

0

0

0

1

0

Intra

0

0001 0

1

1

1

1

0

0

Interp, Coded, Quant

0

0000 11

1

1

0

1

0

0

Fwd, Coded, Quant

0

0000 10

1

0

1

1

0

0

Bwd, Coded, Quant

0

0000 01

1

0

0

0

1

0

Intra, Quant

0

 

Table B-5 — Variable length codes for macroblock_type in I-pictures with spatial scalability.

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

1

0

0

0

1

0

0

Coded, Compatible

4

01

1

0

0

1

0

0

Coded, Compatible, Quant

4

0011

0

0

0

0

1

0

Intra

0

0010

1

0

0

0

1

0

Intra, Quant

0

0001

0

0

0

0

0

0

Not Coded, Compatible

4

 

Table B-6 — Variable length codes for macroblock_type in P-pictures with spatial scalability.

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

10

0

1

0

1

0

0

MC, Coded

0

011

0

1

0

1

0

1

MC, Coded, Compatible

1,2,3

0000 100

0

0

0

1

0

0

No MC, Coded

0

0001 11

0

0

0

1

0

1

No MC, Coded, Compatible

1,2,3

0010

0

1

0

0

0

0

MC, Not Coded

0

0000 111

0

0

0

0

1

0

Intra

0

0011

0

1

0

0

0

1

MC, Not coded, Compatible

1,2,3

010

1

1

0

1

0

0

MC, Coded, Quant

0

0001 00

1

0

0

1

0

0

No MC, Coded, Quant

0

0000 110

1

0

0

0

1

0

Intra, Quant

0

11

1

1

0

1

0

1

MC, Coded, Compatible, Quant

1,2,3

0001 01

1

0

0

1

0

1

No MC, Coded, Compatible, Quant

1,2,3

0001 10

0

0

0

0

0

1

No MC, Not Coded, Compatible

1,2,3

0000 101

0

0

0

1

0

0

Coded, Compatible

4

0000 010

1

0

0

1

0

0

Coded, Compatible, Quant

4

0000 011

0

0

0

0

0

0

Not Coded, Compatible

4

 

Table B-7 — Variable length codes for macroblock_type in B-pictures with spatial scalability.

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

10

0

1

1

0

0

0

Interp, Not coded

0

11

0

1

1

1

0

0

Interp, Coded

0

010

0

0

1

0

0

0

Back, Not coded

0

011

0

0

1

1

0

0

Back, Coded

0

0010

0

1

0

0

0

0

For, Not coded

0

0011

0

1

0

1

0

0

For, Coded

0

0001 10

0

0

1

0

0

1

Back, Not Coded, Compatible

1,2,3

0001 11

0

0

1

1

0

1

Back, Coded, Compatible

1,2,3

0001 00

0

1

0

0

0

1

For, Not Coded, Compatible

1,2,3

0001 01

0

1

0

1

0

1

For, Coded, Compatible

1,2,3

0000 110

0

0

0

0

1

0

Intra

0

0000 111

1

1

1

1

0

0

Interp, Coded, Quant

0

0000 100

1

1

0

1

0

0

For, Coded, Quant

0

0000 101

1

0

1

1

0

0

Back, Coded, Quant

0

0000 0100

1

0

0

0

1

0

Intra, Quant

0

0000 0101

1

1

0

1

0

1

For, Coded, Compatible, Quant

1,2,3

0000 0110 0

1

0

1

1

0

1

Back, Coded, Compatible, Quant

1,2,3

0000 0111 0

0

0

0

0

0

0

Not Coded, Compatible

4

0000 0110 1

1

0

0

1

0

0

Coded, Compatible, Quant

4

0000 0111 1

0

0

0

1

0

0

Coded, Compatible

4

 

Table B-8 — Variable length codes for macroblock_type in I-pictures, P-pictures and B-pictures with SNR scalability.

macroblock_type VLC code

 

macroblock_quant

 

 

macroblock_motion_forward

 

 

 

macroblock_motion_backward

 

 

 

 

macroblock_pattern

 

 

 

 

 

macroblock_intra

 

 

 

 

 

 

spatial_temporal_weight_code_flag

 

 

 

 

 

 

 

permitted spatial_temporal_weight_classes

 

 

 

 

 

 

 

Description

 

1

0

0

0

1

0

0

Coded

0

01

1

0

0

1

0

0

Coded, Quant

0

001

0

0

0

0

0

0

Not Coded

0

 

Note               There is no differentiation between picture types, since macroblocks are processed identically in I, P and B-pictures. The "Not coded" type is needed, since skipped macroblocks are not allowed at beginning and end of a slice.

 

B.3    Macroblock pattern

Table B-9 --- Variable length codes for coded_block_pattern.

coded_block_pattern VLC code

cbp

coded_block_pattern VLC code

cbp

111

60

0001 1100

35

1101

4

0001 1011

13

1100

8

0001 1010

49

1011

16

0001 1001

21

1010

32

0001 1000

41

1001 1

12

0001 0111

14

1001 0

48

0001 0110

50

1000 1

20

0001 0101

22

1000 0

40

0001 0100

42

0111 1

28

0001 0011

15

0111 0

44

0001 0010

51

0110 1

52

0001 0001

23

0110 0

56

0001 0000

43

0101 1

1

0000 1111

25

0101 0

61

0000 1110

37

0100 1

2

0000 1101

26

0100 0

62

0000 1100

38

0011 11

24

0000 1011

29

0011 10

36

0000 1010

45

0011 01

3

0000 1001

53

0011 00

63

0000 1000

57

0010 111

5

0000 0111

30

0010 110

9

0000 0110

46

0010 101

17

0000 0101

54

0010 100

33

0000 0100

58

0010 011

6

0000 0011 1

31

0010 010

10

0000 0011 0

47

0010 001

18

0000 0010 1

55

0010 000

34

0000 0010 0

59

0001 1111

7

0000 0001 1

27

0001 1110

11

0000 0001 0

39

0001 1101

19

0000 0000 1

0 (NOTE)

NOTE — This entry shall not be used with 4:2:0 chrominance structure

 

 

6.2.5.1            Macroblock modes

macroblock_modes() {

No. of bits

Mnemonic

        macroblock_type

1-9

vlclbf

        if ( ( spatial_temporal_weight_code_flag == 1 ) &&

 

 

                ( spatial_temporal_weight_code_table_index != ‘00’) ) {

 

 

                spatial_temporal_weight_code

2

uimsbf

        }

 

 

        if ( macroblock_motion_forward ||

 

 

                macroblock_motion_backward ) {

 

 

                if ( picture_structure == ‘frame’ ) {

 

 

                        if ( frame_pred_frame_dct == 0 )

 

 

                                frame_motion_type

2

uimsbf

                } else {

 

 

                        field_motion_type

2

uimsbf

                }

 

 

        }

 

 

        if ( ( picture_structure == “Frame picture” ) &&

 

 

                ( frame_pred_frame_dct == 0 ) &&

 

 

                ( macroblock_intra || macoblock_pattern) ){

 

 

                dct_type

1

uimsbf

        }

 

 

}

 

 

 

 

block( i )  {

No. of bits

Mnemonic

        if ( pattern_code[i] ) {

 

 

                if ( macroblock_intra )  {

 

 

                        if ( i<4 ) {

 

 

                                dct_dc_size_luminance

2-9

vlclbf

                                if(dct_dc_size_luminance != 0)

 

 

                                        dct_dc_differential

1-11

uimsbf

                        } else {

 

 

                                dct_dc_size_chrominance

2-10

vlclbf

                                if(dct_dc_size_chrominance !=0)

 

 

                                        dct_dc_differential

1-11

uimsbf

                        }

 

 

                } else {

 

 

                        First DCT coefficient

3-24

 

                }

 

 

                while ( nextbits() != End of block )

 

 

                        Subsequent DCT coefficients

2-24

 

                End of block

2 or 4

vlclbf

        }

 

 

}

 

 

B.3    Macroblock pattern

Table B-9 --- Variable length codes for coded_block_pattern.

coded_block_pattern VLC code

cbp

coded_block_pattern VLC code

cbp

111

60

0001 1100

35

1101

4

0001 1011

13

1100

8

0001 1010

49

1011

16

0001 1001

21

1010

32

0001 1000

41

1001 1

12

0001 0111

14

1001 0

48

0001 0110

50

1000 1

20

0001 0101

22

1000 0

40

0001 0100

42

0111 1

28

0001 0011

15

0111 0

44

0001 0010

51

0110 1

52

0001 0001

23

0110 0

56

0001 0000

43

0101 1

1

0000 1111

25

0101 0

61

0000 1110

37

0100 1

2

0000 1101

26

0100 0

62

0000 1100

38

0011 11

24

0000 1011

29

0011 10

36

0000 1010

45

0011 01

3

0000 1001

53

0011 00

63

0000 1000

57

0010 111

5

0000 0111

30

0010 110

9

0000 0110

46

0010 101

17

0000 0101

54

0010 100

33

0000 0100

58

0010 011

6

0000 0011 1

31

0010 010

10

0000 0011 0

47

0010 001

18

0000 0010 1

55

0010 000

34

0000 0010 0

59

0001 1111

7

0000 0001 1

27

0001 1110

11

0000 0001 0

39

0001 1101

19

0000 0000 1

0 (NOTE)

NOTE — This entry shall not be used with 4:2:0 chrominance structure

 

Table B-14 --- DCT coefficients Table zero

Variable length code (NOTE1)

run

level

10 (NOTE 2)

End of Block

 

1 s (NOTE 3)

0

1

11 s (NOTE 4)

0

1

011 s

1

1

0100 s

0

2

0101 s

2

1

0010 1 s

0

3

0011 1 s

3

1

0011 0 s

4

1

0001 10 s

1

2

0001 11 s

5

1

0001 01 s

6

1

0001 00 s

7

1

0000 110 s

0

4

0000 100 s

2

2

0000 111 s

8

1

0000 101 s

9

1

0000 01

Escape

 

0010 0110 s

0

5

0010 0001 s

0

6

0010 0101 s

1

3

0010 0100 s

3

2

0010 0111 s

10

1

0010 0011 s

11

1

0010 0010 s

12

1

0010 0000 s

13

1

0000 0010 10 s

0

7

0000 0011 00 s

1

4

0000 0010 11 s

2

3

0000 0011 11 s

4

2

0000 0010 01 s

5

2

0000 0011 10 s

14

1

0000 0011 01 s

15

1

0000 0010 00 s

16

1

NOTE1 - The last bit 's' denotes the sign of the level, '0' for positive '1' for negative.

NOTE2 - “End of Block” shall not be the only code of t he block.

NOTE3 - This code shall be used for the first (DC) coefficient in the block

NOTE4 - This code shall be used for all other coefficients

 

Table B-14 --- DCT coefficients Table zero (continued)

Variable length code (NOTE)

run

level

0000 0001 1101 s

0

8

0000 0001 1000 s

0

9

0000 0001 0011 s

0

10

0000 0001 0000 s

0

11

0000 0001 1011 s

1

5

0000 0001 0100 s

2

4

0000 0001 1100 s

3

3

0000 0001 0010 s

4

3

0000 0001 1110 s

6

2

0000 0001 0101 s

7

2

0000 0001 0001 s

8

2

0000 0001 1111 s

17

1

0000 0001 1010 s

18

1

0000 0001 1001 s

19

1

0000 0001 0111 s

20

1

0000 0001 0110 s

21

1

0000 0000 1101 0 s

0

12

0000 0000 1100 1 s

0

13

0000 0000 1100 0 s

0

14

0000 0000 1011 1 s

0

15

0000 0000 1011 0 s

1

6

0000 0000 1010 1 s

1

7

0000 0000 1010 0 s

2

5

0000 0000 1001 1 s

3

4

0000 0000 1001 0 s

5

3

0000 0000 1000 1 s

9

2

0000 0000 1000 0 s

10

2

0000 0000 1111 1 s

22

1

0000 0000 1111 0 s

23

1

0000 0000 1110 1 s

24

1

0000 0000 1110 0 s

25

1

0000 0000 1101 1 s

26

1

NOTE - The last bit 's' denotes the sign of the level, '0' for positive, '1' for negative.

 

Table B-14 --- DCT coefficients Table zero (continued)

Variable length code (NOTE)

run

level

0000 0000 0111 11 s

0

16

0000 0000 0111 10 s

0

17

0000 0000 0111 01 s

0

18

0000 0000 0111 00 s

0

19

0000 0000 0110 11 s

0

20

0000 0000 0110 10 s

0

21

0000 0000 0110 01 s

0

22

0000 0000 0110 00 s

0

23

0000 0000 0101 11 s

0

24

0000 0000 0101 10 s

0

25

0000 0000 0101 01 s

0

26

0000 0000 0101 00 s

0

27

0000 0000 0100 11 s

0

28

0000 0000 0100 10 s

0

29

0000 0000 0100 01 s

0

30

0000 0000 0100 00 s

0

31

0000 0000 0011 000 s

0

32

0000 0000 0010 111 s

0

33

0000 0000 0010 110 s

0

34

0000 0000 0010 101 s

0

35

0000 0000 0010 100 s

0

36

0000 0000 0010 011 s

0

37

0000 0000 0010 010 s

0

38

0000 0000 0010 001 s

0

39

0000 0000 0010 000 s

0

40

0000 0000 0011 111 s

1

8

0000 0000 0011 110 s

1

9

0000 0000 0011 101 s

1

10

0000 0000 0011 100 s

1

11

0000 0000 0011 011 s

1

12

0000 0000 0011 010 s

1

13

0000 0000 0011 001 s

1

14

NOTE - The last bit 's' denotes the sign of the level, '0' for positive, '1' for negative.


 

Table B-14 --- DCT coefficients Table zero (concluded)

Variable length code (NOTE)

run

level

0000 0000 0001 0011 s

1

15

0000 0000 0001 0010 s

1

16

0000 0000 0001 0001 s

1

17

0000 0000 0001 0000 s

1

18

0000 0000 0001 0100 s

6

3

0000 0000 0001 1010 s

11

2

0000 0000 0001 1001 s

12

2

0000 0000 0001 1000 s

13

2

0000 0000 0001 0111 s

14

2

0000 0000 0001 0110 s

15

2

0000 0000 0001 0101 s

16

2

0000 0000 0001 1111 s

27

1

0000 0000 0001 1110 s

28

1

0000 0000 0001 1101 s

29

1

0000 0000 0001 1100 s

30

1

0000 0000 0001 1011 s

31

1

NOTE - The last bit 's' denotes the sign of the level, '0' for positive, '1' for negative.

 


你可能感兴趣的:(完整的分析mpeg2 video)