Home  >  Article  >  Web Front-end  >  Summary of format and parsing of PS stream

Summary of format and parsing of PS stream

高洛峰
高洛峰Original
2017-02-15 09:43:154372browse

For PS streams, recently due to work needs, I have studied the PS stream format and unpacking process in MPEG2.

First we need to know what the PS packet stream format is:

Do the following PS encapsulation for H264: Each IDR NALU usually contains NALUs such as SPS and PPS, so Encapsulate the NALU of SPS, PPS, and IDR into a PS package, including the ps header, and then add PS system header, PS system map, and PES header+h264 raw data. Therefore, the order from outside to inside of an IDR NALU PS packet is: PSheader | PS system header | PS system Map | PES header | h264 raw data. For other non-key frame PS packets, it is much simpler. Just add the PS header and PES header directly. The order is: PS header | PES header | h264raw data. The above is for the case where there is only video. If you want to package the audio into PS package, you can also do it. When there is audio data, just add the PES header to the data and put it after the video PES. The sequence is as follows: PS packet = PS header | PES (video) | PES (audio), and then use RTP to encapsulate and send it.

The above is an overall encapsulation format for the data stream. Let’s take a look at each part of each encapsulation:

PS流的格式和解析总结

The first is the PSheader part: (from the MPEG2 standard Chinese document)

#​ 2 system_clock_reference_base[32..30] marker_bit## system_clock_reference_base[29..15] ##91## program_mux_rate22

Syntax

bits Number

Mnemonic

##pack_header() {

pack_start_code

32

##bslbf

' 01'

##bslbf

3

bslbf

1

bslbf

15

##bslbf

marker_bit

1

bslbf

## system_clock_reference_base[14..0]

15

bslbf

## marker_bit

1

bslbf

system_clock_reference_extension

##uimsbf

marker_bit

bslbf

##uimsbf

# marker_bit

1

bslbf

    marker_bit

1

bslbf

    reserved

5

bslbf

    pack_stuffing_length

3

uimsbf

    for (i=0;i

 

 

        stuffing_byte

8

bslbf

    }

 

 

    if (nextbits()==system_header_start_code) {

 

 

        system_header()

 

 

    }

 

 

}

 

 

The semantic definition of each field in the program stream package (PS header):

Pack start code field pack_start_code

The value is' A bit string of 0000 0000 0000 0000 0000 0001 1011 1010' (0x000001BA), used to mark the beginning of a packet.

System clock reference field system_clock_reference_base, system_clock_reference_extenstion

The system clock reference (SCR) is a 42-bit field encoded in two parts. The first part system_clock_reference_base is a field with a length of 33 bits, and its value SCR_base(i) is given by Equation 2-19; ​​the second part system_clock_reference_extenstion is a field with a length of 9 bits, and its value SCR_ext(i) is given by Equation 2-20 given. The SCR field indicates the expected time for the byte in the elementary stream containing the last bit of ESCR_base to arrive at the input of the program's target decoder.

See 2.7.1 for the encoding frequency requirements of the SCR field.

Marker bit field marker_bit

1-bit field, value '1'.

Program composite rate field program_mux_rate

A 22-bit integer that specifies the rate at which P-STD receives the program stream during the packet containing this field. Its value is in units of 50 bytes/second. A value of 0 is not allowed. The value represented by this field is used to define the byte arrival time at the P-STD input in 2.5.2. The value of this field may be different in different packets of the program multiplex composite stream in this standard.

Pack stuffing length field pack_stuffing_length

3-digit integer, specifies the number of padding bytes after this field.

Stuffing byte field stuffing_byte

8-bit field, the value is always '1111 1111'. This field can be inserted by the encoder, for example to meet channel requirements. It is discarded by the decoder. Only a maximum of 7 padding bytes are allowed in each packet header.

Its definition byte order is as follows:

4B packet start code:

##65 4##107

##byte 0

byte 1

byte 2

##byte 3

7

##3

2

1

##0

7

6

5

##4

##3

2

1

0

7

6

5

4

##3

2

##6

5

##4

##3

2

1

0

#0000 0000 0000 0000 0000 0001

start code

1011 1010

PACK identifier

PACK identifier -- 0xBA

Basic part of the system clock reference (SCR-System Clock Reference)SCR The extension part:

##32 1##07654##32##01SCR 29..15SCR 14..00SCR_ext

byte 4

byte 5

byte 6

##byte 7

byte 8

byte 9

7

6

##5

4

##0

7

6

##5

4

3

2

##1

##0

7

6

##5

4

3

2

1

##3

2

1

##0

7

6

5

4

##3

2

1

##0

7

6

5

##4

##1

0

##SCR 32..30

1

1

1

1

 

PS复用速率:

 

byte 10

byte 11

byte 12

byte 13

7

6

5

4

3

2

1

0

7

6

5

4

3

2

1

0

7

6

5

4

3

2

1

0

7

6

5

4

3

2

1

0

Program_Mux_Rate

1

1

reserved

pack_stuffing_length

 

================================================ ===============

Let’s take a look at the definition of PS system header (i.e. PS system header: program stream system title) part : ( From MPEG-2 standard document)

Table 2-34 Program stream system title

##uimsbf marker_bit## rate_bound##1bslbf1bslbf11 marker_bituimsbf#              2bslbf

Language French

Digits

Mnemonic

##system_header() {

## system_header_start_code

32

bslbf

header_length

16

##1

bslbf

##22

uimsbf

## marker_bit

1

bslbf

audio_bound

6

##uimsbf

fixed_flag

CSPS_flag

## system_audio_lock_flag

bslbf

system_video_lock_flag

##bslbf

##1

bslbf

vedio_bound

5

uimsbf

## packet_rate_restriction_flag

1

bslbf

reserved_bits

7

bslbf

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

## stream_id

##8

'11'

        P-STD_buffer_bound_scale

1

bslbf

        P-STD_buffer_size_bound

13

uimsbf

    }

 

 

}

 

 

 

The semantic definition of each field in the system header:

System header start code field system_header_start_code

Value '0000 0000 0000 0000 A bit string of 0000 0001 1011 1011' (0x000001BB), indicating the beginning of the system header.

Header length field header_length

16-bit field. Indicates the length in bytes of the system header following this field. This field may be extended in future extensions of this specification.

Rate limit field rate_bound

22-bit field, the value is not less than the maximum value of the program_mux_rate field encoded in any packet of the program stream. This field can be used by the decoder to estimate whether it is capable of decoding the entire stream.

Audio bound field audio_bound

6-bit field, the value is an integer in the closed interval from 0 to 32, and is not less than the decoding process in the program stream at the same time The maximum number of active GB/T XXXX.3 and GB/T AAAA.3 audio streams. In this section, if the STD buffer is not empty or the presentation unit is being presented in the P-STD model, the decoding process of GB/T XXXX.3 and GB/T AAAA.3 audio streams is active.

Fixed flag field fixed_flag

1 flag bit. When set to '1', it indicates a constant bit rate operation; when set to '0', it indicates a variable bit rate operation. During constant bitrate operation, the system_clock_reference field value in the composite GB/T XXXX.1 stream shall obey the following linear formula:

SCR_base(i )=((c1×ic2) p 300) % 233                                                                                                                                         

#SCR_ext

(i)=((c1×ic2) p 300) % 300 ​​​​​2-23)Among them:

c1 is a real constant that is valid for all i;

c2 is a real constant that is valid for all i;

i The byte index of the last bit of any system_clock_reference field included in the GB/T XXXX.1 composite stream.

CSPS

Flag field CSPS_flag 1-bit field. When set to '1', the program stream complies with the restrictions defined in 2.7.9.

System audio lock flag field system_audio_lock_flag

1-bit field. Indicates that there is a specified ratio between the audio sample rate of the system target decoder and system_clock_frequency. system_clock_frequency is defined in 2.5.2.1 and the audio sampling rate is specified by GB/T XXXX.3. If the ratio SCASR between system_clock_frequency and the actual audio sampling rate is constant for all presentation units of all audio elementary streams in the program stream, and the standard sampling rate indicated in the audio stream is equal to the value in the following table, then this field can only is '1'.

SCASR

=(system_clock_frequency) / audio_sample_rate_in_the_P-STD (2-24)The notation X/Y represents a real number division.

Standard audio sampling frequency (kHz)16 3222.0544.12448SCASR

System video lock flag field system_video_lock_flag

1-bit field. Indicates that there is a specified ratio between the system target decoder's video frame rate and system_clock_frequency. system_clock_frequency is defined in 2.5.2.1 and the video frame rate is specified by GB/T XXXX.2. If the ratio SCFR between system_clock_frequency and the actual video frame rate is constant for all presentation units of all video elementary streams in GB/T XXXX.1, and the standard frame rate indicated in the video stream is equal to the value in the table below, then This field can only be '1'.

SCFRsystem_clock_frequency / frame_rate_in_the_P-STD           (2-25)

##27 000 000
------- -

16 000

27 000 000
-------

32 000

27 000 000
------

22 050

27 000 000
------

44 100

27 000 000
------

24 000

27 000 000
--------

48 000

##242529.973050 59.9460##SCFR

Standard frame rate (Hz)

##23.976

##1 126 125

1 125 000

1 080 000

900 900

900 000

540 000

450 450

450 000

Ratio SCFR values ​​are precise. For standard rates of 23.976, 29.97, or 59.94 frames/second, the actual frame rate differs slightly from the standard rate.

Video bound field video_bound

5-bit field, the value is an integer in the closed interval from 0 to 16 and is not less than the decoding process in the program stream while active The maximum number of GB/T XXXX.2 and GB/T AAAA.2 streams. In this section, the decoding process of GB/T XXXX.2 and GB/T AAAA.2 video streams is active if the P-STD buffer is not empty or the presentation unit is being presented in the P-STD model.

Packet rate limit flag field packet_rate_restriction_flag

1 bit flag. If the CSPS flag is '1', this field indicates which of the limits specified in 2.7.9 applies to the packet rate. If the CSPS flag is '0', the meaning of this field is undefined.

Reserved bit field reserved_bits

7-bit field. Reserved for future use by ISO/IEC. Its value shall be '111 1111' unless ISO/IEC specifies otherwise.

Stream identification field stream_id

8-bit field. Indicates the encoding and elementary stream number of the stream involved in the subsequent P-STD_buffer_bound_scale and P-STD_buffer_size_bound fields.

If the value is '1011 1000', the subsequent P-STD_buffer_bound_scale and P-STD_buffer_size_bound fields refer to all audio streams in the program stream.

If the value is '1011 1001', the subsequent P-STD_buffer_bound_scale and P-STD_buffer_size_bound fields refer to all video streams in the program stream.

If stream_id takes other values, it should be a one-byte value greater than or equal to '1011 1100' and should be interpreted as the encoding and basic stream number of the stream according to Table 2-18.

Each elementary stream in a program stream shall have its P-STD_buffer_bound_scale and P-STD_buffer_size_bound specified exactly once in each system header through this mechanism.

P-STDBuffer bound scale field P-STD_buffer_bound_scale

1-bit field. Represents the scaling factor used to interpret the subsequent P-STD_buffer_size_bound field. If the previous stream_id represents an audio stream, the value of this field is '0'. If it represents a video stream, the value of this field is '1'. For all other stream types, this field value can be '0' or '1'.

P-STDBuffer size limit field P-STD_buffer_size_bound

13-bit unsigned integer, the value is not less than stream n in the program stream The maximum value of the P-STD buffer size BSn for all packets. If the value of P-STD_buffer_bound_scale is '0', this field measures the bounds of the buffer size in units of 128 bytes. If the value of P-STD_buffer_bound_scale is '1', this field measures the bounds of the buffer size in units of 1024 bytes. Therefore:

if (P-STD_buffer_bound_scale == 0)

BSnP-STD_buffer_size_bound×128

else

BSnP-STD_buffer_size_bound×1024

So for the analysis of the system header, we generally only need to first determine whether there is a system header (according to the start code of the system header 0x000001BB), and then we read the header length of the system header, that is, the PS SYSTEM HEADER LENGTH part. Then based on the length of the header, the PS system header is skipped. Go to the next part, which is the PS program stream mapping header.

============================================ =================

Let’s take a look at the program mapping stream part (program stream mapping) definition of PS stream : (from MPEG- 2 Standard document)

Table 2-35 Program stream mapping

# map_stream_id8 program_stream_map_length current_next_indicator
## Language French

bit Number

Mnemonic

program_stream_map() {

packet_start_code_prefix

24

##bslbf

##uimsbf

##16

uimsbf

##1

bslbf

    reserved

2

bslbf

    program_stream_map_version

5

uimsbf

    reserved

7

bslbf

    marker_bit

1

bslbf

    program_stream_info_length

16

uimsbf

    for (i=0;i

 

 

        descriptor()

 

 

    }

 

 

    elementary_stream_map_length

16

uimsbf

    for (i=0;i

 

 

       stream_type

8

uimsbf

       elementary_stream_id

8

uimsbf

       elementary_stream_info_length

16

uimsbf

       for (i=0;i

 

 

           descriptor()

 

 

       }

 

 

    }

 

 

    CRC_32

32

rpchof

}

 

 

The semantic definition of each field in the program stream mapping:

Packet start code prefix field packet_start_code_prefix

24-bit code. It and the following map_stream_id together form a group start code to mark the start of the group. This field is a bit string with the value '0000 0000 0000 0000 0000 0001' (0x000001).

Map stream identification field map_stream_id

8-bit field, the value is 0xBC.

Program stream mapping length field program_stream_map_length

16-bit field. Indicates the number of bytes in program_stream_map immediately following this field. The maximum value of this field is 1018 (0x3FA).

Current next indicator field current_next_indicator

1-bit field. When set to '1', it indicates that the transmitted program stream mapping is currently available. When set to '0', it means that the transmitted program stream mapping is not yet available, but it will be the next effective table.

Program stream mapping version field program_stream_map_version

5-bit field, indicating the version number of the entire program stream mapping. Whenever the definition of the program stream map changes, this field will be incremented by 1, modulo 32. When current_next_indicator is '1', this field should be the version number of the currently applicable program stream mapping; when current_next_indicator is '0', this field should be the version number of the next applicable program stream mapping.

Program stream information length field program_stream_info_length

16-bit field, indicating the total length of the descriptor immediately following this field.

Marker bit field marker_bit

1-bit field, the value is '1'.

Elementary stream map length field elementary_stream_map_length

16-bit field, indicating the byte length of all elementary stream information in the program stream map. It only includes the stream_type, elementary_stream_id and elementary_stream_info_length fields. (Note here that the length of the basic stream mapping here only includes the sum of the definition fields specified later. That is, from this length, we can know how many types of stream definitions it has later. , because the sum of the definition fields of a stream: stream_type (1BYTE), elementary_stream_id (1byte) and elementary_stream_info_length (2byte) is 4 bytes, so you can use elementary_stream_map_length/4 to get several stream type information defined later)#.

##Stream type field stream_type

8-bit field specifies the type of stream according to Table 2-29. This field can only mark the elementary stream contained in the PES packet and the value cannot be 0x05.

(Here we can temporarily know based on the definition in the national standard GB28181

1. MPEG-4 video stream: 0x10;

2. H.264 video stream: 0x1B;

3. SVAC video stream: 0x80;

4. G.711 audio stream: 0x90;

5. G.722.1 audio stream: 0x92;

6, G.723.1 audio stream: 0x93;

7, G.729 audio stream: 0x99;

8, SVAC audio stream: 0x9B. #Because the program mapping stream field will only exist when key frames are packaged, so if you want to determine the stream encoding type of PS packaging, use this field to determine

)

Basically. Stream identification field elementary_stream_id

8-bit field, indicating the value of the stream_id field in the PES packet header of the PES packet where the elementary stream is located.

(Definition of this field, 0x(C0~DF) refers to audio, 0x(E0~EF) refers to video)

Basic stream information length Field elmentary_stream_info_length

16-bit field, indicating the byte length of the descriptor immediately following this field. (That is, the length of the stream description of this type. The specified length behind this field is not in the range specified by elementary_stream_map_length.)

CRC 32

Field CRC_32

32-bit field that contains the CRC value to produce an output value of 0 in the decoder register defined in Appendix A after processing of the entire program stream map.

For the analysis of this field, we need a bit string with a value of 0x000001BC, indicating the beginning of the program stream mapping. There is no need to process it for the time being. Read the Header Length and skip it directly. Yes, if you need to parse the stream encoding type, you must parse this field in detail.

==================PES PACK ================ =============

Next, let’s analyze the contents of the PES package: PES package=PES header+code raw data;

Let’s take a look first

PES headerPS流的格式和解析总结 :(from http://www.php.cn/)

PS流的格式和解析总结

Then let’s take a look at the parsing steps: (from MPEG-2 standard document)

Table 2-17 PES grouping

##stream_id 8uimsbf PES_packet_length16if(stream_id != program_stream_map##&& stream_id !=ITU-T Rec.H.222.1 type E stream){'10' 2PES_priority##bslbf

语法

digit

Mnemonic

PES_packet(){

##packet_start_code_prefix

##24

bslbf

##uimsbf

##&& stream_id !=padding_stream

&& stream_id !=private_stream_2

#&& stream_id !=ECM

#&& stream_id ! =EMM

##&& stream_id !=program_stream_directory

##&& stream_id !=DSMCC_stream

2

bslbf

PES_scrambling_control

##bslbf

## 1

bslbf

data_alignment_indicator

1

##bslbf

##copyright

1

bslbf

original_or_copy

1

PTS_DTS_flags

 2

bslbf

ESCR_flag

 1

bslbf

ES_rate_flag

 1

bslbf

DSM_trick_mode_flag

 1

bslbf

additional_copy_info_flag

 1

bslbf

PES_CRC_flag

 1

bslbf

PES_extension_flag

 1

bslbf

PES_header_data_length

 8

uimsbf

if(PTS_DTS_flags =='10'){

 

 

'0010'

 4

bslbf

PTS[32..30]

 3

bslbf

marker_bit

 1

bslbf

PTS[29..15]

15

bslbf

marker_bit

 1

bslbf

PTS[14..0]

15

bslbf

marker_bit

 1

bslbf

}

 

 

if(PTS_DTS_flags =='11'){

 

 

'0011'

 4

bslbf

PTS[32..30]

 3

bslbf

marker_bit

 1

bslbf

PTS[29..15]

15

bslbf

marker_bit

 1

bslbf

PTS[14..0]

15

bslbf

marker_bit

 1

bslbf

'0001'

 4

bslbf

PTS[32..30]

 3

bslbf

marker_bit

 1

bslbf

PTS[29..15]

15

bslbf

marker_bit

 1

bslbf

PTS[14..0]

15

bslbf

marker_bit

 1

bslbf

}

 

 

if(ESCR_flag =='1'){

 

 

reserved

 2

bslbf

ESCR_base[32..30]

 3

bslbf

marker_bit

 1

bslbf

ESCR_base[29..15]

15

bslbf

marker_bit

 1

bslbf

ESCR_base[14..0]

15

bslbf

marker_bit

 1

bslbf

ESCR_extension

 9

uimsbf

marker_bit

 1

bslbf

}

 

 

if(ES_rate_flag =='1'){

 

 

marker_bit

 1

bslbf

ES_rate

22

uimsbf

marker_bit

 1

bslbf

}

 

 

if (DSM_trick_mode_flag =='1'){

 

 

trick_mode_control

 3

uimsbf

if ( trick_mode_control = =fast_forward ) {

 

 

field_id

 2

bslbf

intra_slice_refresh

 1

bslbf

frequency_truncation

 2

bslbf

}

 

 

else if ( trick_mode_control = = slow_motion ) {

 

 

rep_cntrl

 5

uimsbf

}

 

 

else if ( trick_mode _control = = freeze_frame ) {

 

 

field_id

 2

uimsbf

reserved

 3

bslbf

}

 

 

else if ( trick_mode _control = = fast_reverse ) {

 

 

field_id

 2

bslbf

intra_slice_refresh

 1

bslbf

frequency_truncation

 2

bslbf

else if ( trick_mode_control = = slow_reverse ) {

 

 

rep_cntrl

 5

uimsbf

}

 

 

else

 

 

reserved

 5

bslbf

}

 

 

if ( additional_copy_info_flag = ='1'){

 

 

marker_bit

 1

bslbf

additional_copy_info

 7

bslbf

}

 

 

if (PES_CRC_flag==‘1’){

 

 

previous_PES_packet_CRC

16

bslbf

}

 

 

if ( PES_extension_flag =='1') {

 

 

PES_private_data_flag

 1

bslbf

pack_header_field_flag

 1

bslbf

program_packet_sequence_counter_flag

 1

bslbf

P-STD_buffer_flag

 1

bslbf

reserved

 3

bslbf

PES_extension_flag_2

 1

bslbf

if(PES_private_data_flag =='1'){

 

 

PES_private_data

128

bslbf

}

 

 

if (pack_header_field_flag == '1'){

 

 

pack_field_length

 8

uimsbf

pack_header()

 

 

}

 

 

if (program_packer_sequence_counter_flag == '1'){

 

 

marker_bit

 1

bslbf

program_packet_sequence_counter

 7

uimsbf

marker-bit

 1

bslbf

MPEG1_MPEG2_indentifier

 1

bslbf

original_stuff_length

 6

uimsbf

}

 

 

if (P-STD_buffer_flag = = '1'({

 

 

'01'

 2

bslbf

P-STD_buffer_scale

 1

bslbf

P-STD_buffer_size

13

uimsbf

}

 

 

if (PES_extension_flag_2 == '1'{

 

 

marker_bit

 1

bslbf

PES_extension_field_length

 7

uimsbf

for(i=0;i

 

 

reserved

 8

bslbf

}

 

 

}

 

 

}

 

 

for (i=0;i

 

 

stuffing_byte

 8

bslbf

}

 

 

for (i=0;i

 

 

PES_packet_data_byte

 8

bslbf

}

 

 

}

 

 

else if (stream_id = = program_stream_map

 

 

|| stream_id = = private_stream_2

 

 

|| stream_id = = ECM

 

 

|| stream_id = = EMM

 

 

|| stream_id = = program_stream_directory

 

 

|| stream_id = = DSMCC_stream

 

 

|| stream_id = = ITU-T Rec. H.222.1 type E stream ){

 

 

for (i=0;i

 

 

PES_packet_data_byte

 8

bslbf

}

 

 

}

 

 

else if (steam_id = = padding_stream){

 

 

for (i=0;i

 

 

padding_byte

 8

bslbf

}

 

 

}

 

 

}

 

 

Among them:

Table 2-18 Stream_id assignment

##1011 11113##110x xxxx##GB/T XXXX.1 Appendix B or GB/T XXXX.6_DSMCC_stream(0xF2)2ISO/IEC_13522_stream(0xF3)6ITU-T Rec. H.222.1 Type A6#6667##1111 1010…1111 1110The PES packet of type program_stream_map has a unique syntax, which is specified in 2.5.4.1.

2 PES packets of type private_stream_1 and ISO/IEC_13352_stream obey the same PES packet syntax as GB/T XXXX.2 and GB/T XXXX.3 audio streams.

3 PES packets of type private_stream_2, ECM_stream and EMM_stream are similar to private_stream_1, except that the syntax is not specified after the PES_packet_length field.

4 The PES grouping of type program_stream_directory has a unique syntax, which is specified in 2.5.5.

5 PES packets of type DSM_CC_stream have a unique syntax, which is specified in GB/T XXXX.6.

6 stream_id is associated with stream_type 0x09 in Table 2-29.

7 stream_id is only used for PES grouping. PES packets carry data originating from program streams or GB/T AAAA.1 system streams in the transport stream (see 2.4.3.7).

stream_id

Note

Stream encoding

1011 1100

1

program_stream_map(0xBC

##1011 1101

2

private_stream_1(0xBD)

1011 1110

padding_stream(0xBE)

##private_stream-2(0xBF)

##GB/T XXXX.3 or GB/T AAAA.3 audio stream number xxxx(

0xC0~0xDF

)

1110 xxxx

GB/T XXXX.2 Or GB/T AAAA.2 video stream number xxxx(

0xE0~0xEF

)

1111 0000
3

ECM_stream(0xF0)

1111 0001
3

EMM_stream(0xF1)

1111 0010
5

1111 0011

1111 0100

1111 0101

##ITU-T Rec. H.222.1 Type B

1111 0110

ITU-T Rec. H.222.1 Type C

1111 0111

ITU-T Rec. H.222.1 Type D

1111 1000

ITU-T Rec. H.222.1 Type E

1111 1001

ancillary_stream (0xF9)

Retain data stream

##1111 1111

4
program_stream_directory( 0xFF)

The symbol x indicates that the value '0' or '1' is both allowed and can produce the same stream type. The stream number is determined by the value of x.
Note

1

Semantic definition of each field in the PES packet

Packet start code prefix field packet_start_code_prefix

24-bit code, it and the following stream_id constitutes the packet start code that identifies the start of the packet. It is a bit string with the value '0000 0000 0000 0000 0000 0001' (0x000001).

Stream identification field stream_id

In the program stream, it specifies the number and type of the basic stream. See Table 2-18 for definitions. In a transport stream, it may be set to any valid value that correctly describes the elementary stream type defined in Table 2-18. In transport streams, the elementary stream type is specified in the program-specific information of 2.4.4.

PESPacket length field PES_packet_length

16-bit field, indicating the number of bytes following this field in the PES packet. A value of 0 indicates that the PES packet length is either unspecified or unlimited. This is only allowed in PES packets whose payload contains bytes originating from one of the video elementary streams in the Transport Stream packet.

PES Scrambling control field PES_scrambling_control

2-bit field, indicating the scrambling method of the PES packet payload. When scrambling occurs at the PES layer, the PES packet header, including optional fields if present, shall not be scrambled (see 2-19).

PESPriority field PES_priority

1-bit field indicating the priority of the payload in the PES packet. '1' indicates that the payload in the PES packet has a higher priority than the payload of the PES packet with this field set to '0'. The multiplexer can use this field to prioritize data in the elementary streams. The transport mechanism should not modify this field.

Data alignment indicator field data_alignment_indicator

1 bit flag. When set to '1', it means that the PES packet header is followed by the video start code or audio synchronization word pointed out by the data_alignment_indicator in 2.6.10, if there is a data_alignment_indicator descriptor. If its value is '1' and there is no such descriptor, the alignment represented by alignment_type '01' in Tables 2-47 and 2-48 is required. When the value is '0', it is not defined whether there is any such alignment.

Copyright field copyright

1-digit field. When set to '1', indicates that the material in the associated PES packet payload is copyright protected. When the value is '0', it is not defined whether the material is copyright protected. The copyright descriptors described in 2.6.24 are associated with elementary streams containing PES packets. If the descriptor is applied to material containing PES packets, the copyright flag is set to '1'.

Original or copy field original_or_copy

1-bit field. When set to '1', it indicates that the contents of the relevant PES packet payload are original; a value of '0' indicates that the contents of the relevant PES packet payload are a copy.

PTS DTSFlag field PTS_DTS_flags

2-bit field. When the value is '10', the PTS field should appear in the PES group header; when the value is '11', both the PTS field and the DTS field should appear in the PES group header; when the value is '00', the PTS field Neither the nor DTS fields appear in the PES packet header. The value '01' is not allowed.

ESCRFlag field ESCR_flag

1-bit flag. When set to '1', it indicates that the ESCR basic and extended fields appear in the PES packet header; a value of '0' indicates that there is no ESCR field.

ESRate flag field ES_rate_flag

1 bit flag. When set to '1', it indicates that the ES_rate field appears in the PES packet header; a value of '0' indicates that there is no ES_rate field.

DSMTrick mode flag field DSM_trick_mode_flag

1 bit flag. When set to '1', it means there is an 8-bit stunt mode field; when the value is '0', it means there is no such field.

Additional copyright information flag field additional_copy_info_flag

1 bit flag. When set to '1', it means there is an additional copy information field; when the value is '0', it means there is no such field.

PES CRCFlag field PES_CRC_flag

1 bit flag. When set to '1', it indicates that the CRC field appears in the PES packet header; a value of '0' indicates that there is no such field.

PESExtension flag field PES_extension_flag

1 bit flag. When set to '1', it indicates that there is an extended field in the PES packet header; a value of '0' indicates that there is no such field.

PESHeader data length field PES_header_data_length

8-bit field. Indicates the total number of bytes occupied by optional fields and any padding bytes contained in the PES packet header. The bytes preceding this field indicate whether optional fields are present.

Marker bit field marker_bit

A 1-bit field with a value of '1'.

Show timestamp field PTS

The relationship between presentation time and decoding time is as follows: PTS is a 33-bit number encoded in three separate fields. It indicates the presentation time tpn(k) of the k-th presentation unit of elementary stream n in the system target decoder. The value of PTS is in units of 1/300 of the system clock frequency (i.e. 90 kHz). The display time is calculated by PTS according to Equation 2-11. See 2.7.4 for constraints on the frequency of encoding presentation timestamps.

PTS(k)=((system_clock_frequency×tpn(k)) p 300) % 233           (2-11)

Among them, tpn(k) is the display unit P The display time of n(k).

For audio, if there is a PTS in the PES group header, it refers to the first access unit starting in the PES group. If there is the first byte of the audio access unit in the PES packet, then there is an audio access unit starting in the PES packet.

For video, if there is a PTS in the PES group header, it refers to the access unit containing the first picture start code starting in the PES group. If there is the first byte of the picture start code in the PES packet, then there is a picture start code starting in the PES packet.

For the audio presentation unit (PU), video PU and B picture in the low_delay sequence, the presentation time tpn(k) should be equal to tdn(k) .

For I pictures and P pictures in non-low_delay, when there is no decoding discontinuity between access units (AU) k and k', the presentation time tpn(k) should be Equal to the decoding time tdn(k) of the next transmitted I picture or P picture (see 2.7.5). If there is a decoding discontinuity or stream termination, the difference between tpn(k) and tdn(k) shall continue with the initial stream without discontinuity or termination. are exactly the same.

Note 1: The low_delay sequence is the video sequence with the low_delay flag set (see 6.2.2.3 in GB/T XXXX.2).

If there is filtering in the audio, the system model assumes that filtering does not cause delay. Therefore, the samples involved in the PTS during encoding are the same as the samples involved in the PTS during decoding. For scalable encoding, see 2.7.6.

Decode Timestamp Field DTS

DTS is a 33-bit number encoded in three separate fields. It indicates the decoding time tdn(j) of the j-th presentation unit of elementary stream n in the system target decoder. The value of DTS is in units of 1/300 of the system clock frequency (i.e. 90 kHz). The decoding time is calculated by DTS according to Equation 2-12:

DTS(j)=((system_clock_frequency×tdn (j)) p 300) % 233                 (2-12)

Among them, tdn(j) is the storage Take the decoding time of unit An(j).

For video, if there is DTS in the PES packet header, it refers to the access unit containing the first picture start code starting in the PES packet. If there is the first byte of the picture start code in the PES group, the picture start code starts in the PES group.

For scalable encoding, see 2.7.6.

ESCR Field ESCR_base, ESCR_extension

42-bit field, encoded in two parts. The first part is a field with a length of 33 bits, and its value ESCR_base(i) is given by Equation 2-14; the second part is a field with a length of 9 bits, and its value ESCR_ext(i) is given by Equation 2-15 . The ESCR field indicates the expected time for the byte containing the last bit of ESCR_base in the elementary stream to arrive at the PES-STD output (see 2.5.2.4).

Specially

ESCR(i)=ESCR_base(i)×300+ escr_ext ( i ) (2-13)

Where:

# Escr_base ( i ) =((system_clock_frequency×t(i)) p 300) % 233                                                                                                                   

#ESCR _ext

(i)=((system_clock_frequency×t(i)) p 1) % 300                 (2-15)The ESCR and ES_rate fields (see semantics immediately below) contain timing information related to the PES stream sequence. These fields shall satisfy the constraints defined in 2.7.3.

Basic stream rate field ES_rate

22-bit unsigned integer. For PES streams, it indicates the rate at which the system's target decoder will receive PES packets. This field is valid in the PES packet to which it belongs and in subsequent PES packets of the same PES stream until a new ES_rate field is encountered. The value of this field is in units of 50 bytes/second and cannot be 0. This field is used to define the time when bytes of the PES stream arrive at the P-STD input (see definition in 2.5.2.4). The value encoded in this field may differ between PES packets.

Trick mode control field trick_mode_control

3-digit field. It represents a stunt mode that is applied to the associated video stream. For other types of elementary streams, the meaning of this field and the following five bits is not defined. For the definition of trick_mode state, please refer to the trick mode section of 2.4.2.3.

When the trick_mode status is false, for GB/T XXXX.2 video, the number N of each frame in the progressive sequence output by the decoding process is specified by the repeat_first_field and top_field_first fields. For GB/T AAAA.2 videos, it is determined by the sequence title.

For interlaced sequences, when the trick_mode status is false, for GB/T XXXX.2 video, the number of times N is specified by the repeat_first_field and progressive_frame fields.

When the trick_mode status is true, the number of times the picture is played depends on the value N.

Table 2-20 Stunt mode control values

## Slow down##'101'-'111'

When the value of this field changes or the stunt mode operation is stopped, any combination of the following situations may occur:

l           The time base is discontinuous;

l                                                

#l    The continuity counter is discontinuous;

In the case of trick mode, the non-standard speed of decoding and presentation may cause some field values ​​defined in the video elementary stream data to be incorrect. Likewise, semantic constraints on fragment structures may be invalid. The video syntax elements involved in these exceptions are:

l         bit_rate;

l          vbv_delay; ## l field_sequence;

L Subcarrier;

## L burst_amplitude;

## L Subcarrier_PHASE;

## In the stunt mode, the decoder should not depend on the coding The values ​​in these fields.

The standard does not require the decoder to be able to decode the trick_mode_control field. However, decoders capable of decoding this field shall meet the following standard requirements.

fast forward fast forword

The value '000' in the trick_mode_control field. When this value is present, it represents a fast-forward video stream and defines the meaning of the following 5 bits in the PES packet header. The intra_slice_refresh bit may be set to '1' to indicate that there may be missing macroblocks. The decoder can replace the macroblock with the same position in the previous decoded picture. The field_id field defined in Table 2-21 indicates which field or fields should be displayed. The frequency_truncation field indicates a restricted set of coefficients that may be included. The meaning of this field value is shown in Table 2-22.

Slow motion slow motion

The value '001' in the trick_mode_control field. When this value is present, it represents a slow-motion video stream and defines the meaning of the following 5 bits in the PES packet header. For progressive sequences, the picture should be displayed for N×rep_cntrl time, where N is defined as above.

For GB/T AAAA.2 video and GB/T XXXX.2 video progressive sequence, the picture should be displayed for N×rep_cntrl time, where N is defined as above.

For GB/T XXXX.2 interlaced sequences, this screen should be displayed for N×rep_cntrl time. If the picture is a frame picture, the first field to be displayed should be the top field when top_field_first is 1, and the bottom field when top_field_first is 0 (see GB/T XXXX.2). This field is displayed N×rep_cntrl/2 times. The other fields of the screen are displayed for N-N×rep_cntrl/2 times.

Freeze frame freeze frame

The value '010' in the trick_mode_control field. When this value appears, it represents the freeze frame video stream and defines the meaning of the following 5 bits in the PES packet header. The field_id field defined in Table 2-21 indicates which field(s) should be displayed. The field_id field indicates the first video access unit starting in the PES packet containing this field, unless the PES packet contains 0 payload bytes. In the latter case, the field_id field indicates the most recent previous video access unit.

fast reverse fast reverse

The value '011' in the trick_mode_control field. When this value is present, it represents a rewind video stream and defines the meaning of the following 5 bits in the PES packet header. The intra_slice_refresh bit may be set to '1' to indicate that there may be missing macroblocks. The decoder can replace the macroblock with the same position in the previous decoded picture. The field_id field defined in Table 2-21 indicates which field or fields should be displayed. The frequency_truncation field indicates a restricted set of coefficients that may be included. The meaning of this field value is shown in Table 2-22 "Coefficient Selection Value".

Slow reverse slow reverse

The value '100' in the trick_mode_control field. When this value is present, it represents a slow-reverse video stream and defines the meaning of the following 5 bits in the PES packet header. For GB/T AAAA.2 video and GB/T XXXX.2 video progressive sequence, the picture should be displayed for N×rep_cntrl time, where N is defined as above.

For GB/T XXXX.2 interlaced sequences, this screen should be displayed for N×rep_cntrl time. If the picture is a frame picture, the first field to be displayed should be the bottom field when top_field_first is 1, and the top field when top_field_first is '0' (see GB/T XXXX.2). This field is displayed for N×rep_cntrl/2 times. The other fields of the screen are displayed for N-N×rep_cntrl/2 times.

Field identification field field_id

2-bit field, indicating which field(s) should be displayed. Code it according to Table 2-21.

Table 2-21 field_id field control value

Value

Description

'000'

Fast forward

'001'

SLOW MOTION

##'010'

Freeze Frame

'011'

Fast Rewind

'100'

reserve

Value

Description

'00'

Play from top to bottom only

'01'

Play bottom-up only

'10'

Play all frames

##'11'

Reserved

Intra-slice reference field intra_slice_refresh

1 bit flag. When set to '1', it indicates that there may be missing macroblocks in the encoded piece of video data of the PES packet; when set to '0', it indicates that the above situation may not occur. For more information, see GB/T XXXX.2. The decoder can replace the lost macroblock with a macroblock at the same position in the previous decoded picture.

Frequency truncation field frequency_truncation

2-bit field. Points out that a restricted set of coefficients may be used when encoding data in PES packets. Its value is defined in Table 2-22.

Table 2-22 Coefficient selection value

Display times control field rep_cntrl

5-digit field, indicating the number of times each field is displayed in the interlaced screen or the number of times the progressive screen is displayed. For interlaced pictures, whether the top field or the bottom field should be displayed first is a function of the trick_mode_control field and the top_field_first field in the video sequence header. This field value cannot be '0'.

Additional copyright information field additional_copy_info

7-bit field, containing special data related to copyright information.

Previous PESPacket CRC field previous_PES_packet_CRC

16-bit field. This field contains a CRC value that generates a 0 output in the decoder's 16 registers after processing the previous PES packet (excluding the header of that PES packet). This CRC value is similar to that defined in Appendix A, but with the following polynomial:

x16+x12+x5+1

Note 2: This CRC value is intended for network maintenance, such as isolating sources of intermittent errors, and is not intended for use by the elementary stream decoder. It is only used to count data bytes since PES packet header data may be modified during transmission.

PESPrivate data flag field PES_private_data_flag

1 bit flag. When set to '1', it means that the PES packet header contains special data; when set to '0', it means that there is no special data in the PES packet header.

Pack header field flag field pack_header_field_flag

1 bit flag. When set to '1', it means that the PES packet header contains a GB/T AAAA.2 packet header or a program stream packet header. If this field is in a PES packet contained in a program stream, its value shall be '0'. In a transport stream, a value of '0' indicates that there is no packet header in the PES header.

Program packet sequence count flag field program_packet_sequence_counter_flag

1 bit flag. A value of '1' indicates that the PES packet has program_packet_sequence_counter, MPEG1_MPEG2_identifier and original_stuff_length fields. A value of '0' indicates that these fields are not included in the PES packet header.

P-STDBuffer flag field P-STD_buffer_flag

1 bit flag. When set to '1', it indicates that there are P-STD_buffer_scale and P-STD_buffer_size fields in the PES packet header. A value of '0' indicates that these fields are not included in the PES header.

PESExtension flag field PES_extension_flag_2

1 bit flag, when set to '1', it indicates that there are PES_extension_field_length and related fields.

PESPrivate data field PES_private_data

16-bit field. Contains private data. When these data are combined with the fields before and after them, they cannot conflict with packet_start_code_prefix (0x000001).

Pack field length field pack_field_length

8-bit field. Represents the length of pack_header_field() in bytes.

Program packet sequence count field program_packet_sequence_counter

7-bit field. It is an optional counter that is incremented with each subsequent PES packet from a program stream or GB/T AAAA.1 stream or PES packet with a single program definition in a transport stream to provide consistency with the continuity counter ( See 2.4.3.2) for similar functionality. It can be used to retrieve the initial PES packet sequence in the program stream or the original GB/T AAAA.1 stream. This counter wraps around to 0 after reaching its maximum value. PES groups cannot be repeated. Therefore, any two consecutive PES packets in a composite program should not have the same program_packet_sequence_counter value.

MPEG1 MPEG2Identifier field MPEG1_MPEG2_identifier

1 bit flag. When set to '1', it indicates that the information carried by the PES packet comes from the GB/T AAAA.1 stream; when set to '0', it indicates that the information carried by the PES packet comes from the program stream.

InitialInitial stuffing length field original_stuff_length

6-bit field. Specifies the number of padding bytes used in the initial GB/T XXXX.1 packet header or the initial GB/T AAAA.1 packet header.

P-STDBuffer scale field P-STD_ buffer_scale

1-bit field. It is only meaningful if the PES packet is included in the program stream. It indicates the scaling factor used to interpret subsequent P-STD_buffer_size fields. If the previous stream_id represents an audio stream, the value of this field should be '0'; if the previous stream_id represents a video stream, the value of this field should be '1'. For all other stream types, the value can be '0' or '1'.

P-STDBuffer size field P-STD_buffer_size

13-bit unsigned integer. It is only meaningful if the PES packet is included in the program stream. It defines the size of the P-STD input buffer BSn. If the value of P-STD_buffer_scale is '0', then P-STD_buffer_size measures the size of the buffer in units of 128 bytes. If the value of P-STD_buffer_scale is '1', then P-STD_buffer_size measures the size of the buffer in units of 1024 bytes. Therefore:

if ( P-STD_buffer_scale == 0)

BSnP-STD_buffer_size ×128                                                                                                                                                                                                                    ​#×1024                                                                                                    2-17)

When this field is received by the GB/T XXXX.1 system target decoder, its encoding value takes effect immediately.

PESExtension field length field PES_extension_field_length 7-bit field. Specifies the length in bytes of the data following this field in the PES extension field up to and including any reserved bytes.

Stuffing byte field stuffing_byte

8-bit field, its value is constant '1111 1111'. Can be inserted by the encoder to meet the needs of the channel etc. The decoder discards this field. Only 32 padding bytes may appear in a PES packet header.

PES

Packet data byte field PES_packet_data_byte

This field should be consecutive from the elementary stream specified by the packet's stream_id or PID data bytes. When elementary stream data conforms to GB/T XXXX.2 or GB/T XXXX.3, this field should be bytes aligned with the bytes of this standard. The endianness of elementary streams should be maintained. The number of bytes in this field, N, is specified by the PES_packet_length field. N shall be equal to PES_packet_length minus the number of bytes between the last byte of the PES_packet_length field and the first PES_packet_data_byte.

Padding byte field padding_byte

8-bit field, its value is always '1111 1111'. This field is discarded by the decoder. For more PS stream format and analysis summary, please pay attention to the PHP Chinese website for related articles!

Value

Description

'00'

Only the DC coefficient is non-0

'01'

Only the first three coefficients are non-0

'10'

Only the first six coefficients are non-0

'11'

All coefficients are possible Not 0

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn