https://en.wikipedia.org/wiki/Packetized_elementary_stream
Packetized elementary stream
Packetized Elementary Stream (PES) is a specification in the MPEG-2 Part 1 (Systems) (ISO/IEC 13818-1) and ITU-T H.222.0[1][2] that defines carrying of elementary streams (usually the output of an audio or video encoder) in packets withinMPEG program streams andMPEG transport streams.[3] The elementary stream ispacketized by encapsulating sequential data bytes from the elementary stream inside PES packet headers.
A typical method of transmitting elementary stream data from a video or audio encoder is to first create PES packets from the elementary stream data and then to encapsulate these PES packets inside Transport Stream (TS) packets or Program Stream (PS) packets. The TS packets can then be multiplexed and transmitted using broadcasting techniques, such as those used in anATSC andDVB.
Transport Streams and Program Streams are each logically constructed from PES packets. PES packets shall be used to convert between Transport Streams and Program Streams. In some cases the PES packets need not be modified when performing such conversions. PES packets may be much larger than the size of a Transport Stream packet.[3]
PES packet header[edit]
Name | Size | Description |
---|---|---|
Packet start code prefix | 3 bytes | 0x000001 |
Stream id | 1 byte | Examples: Audio streams (0xC0-0xDF), Video streams (0xE0-0xEF) [4][5][6][7] |
Note: The above 4 bytes is called the 32 bit start code. | ||
PES Packet length | 2 bytes | Specifies the number of bytes remaining in the packet after this field. Can be zero. If the PES packet length is set to zero, the PES packet can be of any length. A value of zero for the PES packet length can be used only when the PES packet payload is a video elementary stream.[8] |
Optional PES header | variable length (length >= 9) | not present in case of Padding stream & Private stream 2 (navigation data) |
Stuffing bytes | variable length | |
Data | See elementary stream. In the case of private streams the first byte of the payload is the sub-stream number. |
Optional PES header[edit]
Name | Number of Bits | Description |
---|---|---|
Marker bits | 2 | 10 binary or 0x2 hex |
Scrambling control | 2 | 00 implies not scrambled |
Priority | 1 | |
Data alignment indicator | 1 | 1 indicates that the PES packet header is immediately followed by the video start code or audiosyncword |
Copyright | 1 | 1 implies copyrighted |
Original or Copy | 1 | 1 implies original |
PTS DTS indicator | 2 | 11 = both present, 01 is forbidden, 10 = only PTS, 00 = no PTS or DTS |
ESCR flag | 1 | |
ES rate flag | 1 | |
DSM trick mode flag | 1 | |
Additional copy info flag | 1 | |
CRC flag | 1 | |
extension flag | 1 | |
PES header length | 8 | gives the length of the remainder of the PES header in bytes |
Optional fields | variable length | presence is determined by flag bits above |
Stuffing Bytes | variable length | 0xff |
While above flags indicate that values are appended into variable length optional fields, they are not just simply written out. For example, PTS (and DTS) is expanded from 33 bits to 5 bytes (40 bits). If only PTS is present, this is done by catenating 0010b, most significant 3 bits from PTS, 1, following next 15 bits, 1, rest 15 bits and 1. If both PTS and DTS are present, first 4 bits are 0011 and first 4 bits for DTS are 0001. Other appended bytes have similar but different encoding.
References[edit]
- Jump up^ITU-T (November 2014)."H.222.0 Summary". Retrieved 2015-11-17.
- Jump up^ITU-T."H.222.0 : Information technology - Generic coding of moving pictures and associated audio information: Systems". Retrieved2010-06-03.
- ^ Jump up to: abISO (2000-12-01) ISO/IEC 13818-1 : 2000, Second edition, Retrieved on 2009-07-25
- Jump up^http://www.etsi.org/deliver/etsi_ts/101100_101199/101154/01.09.01_60/ts_101154v010901p.pdf
- Jump up^Method and apparatus for changing codec to reproduce video and/or audio data streams encoded by different codecs within a channel - Patent EP1827030
- Jump up^European publication server
- Jump up^https://publications.european-patent-office.org/PublicationServer/document.jsp?PN=EP1827030%20EP%201827030&iDocId=6296342&iFormat=0
- Jump up^http://happy.emu.id.au/lab/tut/dttb/dtbtut4b.htm#s4p4>
External links[edit]
- http://www.bretl.com/mpeghtml/pespckt.HTM
- http://dvd.sourceforge.net/dvdinfo/pes-hdr.html
- ISO/IEC standard 13818-1 [1])
MPEG Headers Quick Reference
This is a quick reference to the various headers and streams found in MPEG/DVD. For a complete description you should get a copy of ISO/IEC 13818.This is an incomplete work-in-progress
The header
Every stream or table begins with a 32-bit start code, codes 00 through B8 are video stream start codes (fully defined in 13818-2), and codes B9-FF are stream-id'sbyte 0 | byte 1 | byte 2 | byte 3 |
---|---|---|---|
0000 0000 0000 0000 0000 0001 Start code prefix | Stream ID |
|
|
Picture header (0100)
Variable length.byte 4 | byte 5 | byte 6 | byte 7 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
temperal sequence number | frame type 1=I, 2=P 3=B, 4=D | VBV delay | --- |
additional fields appended beginning at byte 7 bit 2:
If frame type = 2 (P) or 3 (B) the following 4 bits are appended to the header:
3 | 2 | 1 | 0 |
---|---|---|---|
full_pel_forward_vector | forward_f_code |
This field is used by MPEG-1 only, for MPEG-2 it should be set to 0 1 1 1
If frame type = 3 (B) the following 4 bits are appended to the header:
3 | 2 | 1 | 0 |
---|---|---|---|
full_pel_backward_vector | backward_f_code |
This field is used by MPEG-1 only, for MPEG-2 it should be set to 0 1 1 1
additionally if the next bit is "1" (extra_bit_picture) it is followed by 8 bits of "extra" data (discarded by decoders). This continues until a "0" bit is encountered.
Sequence header (01B3)
Variable length.byte 4 | byte 5 | byte 6 | byte 7 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
horizontal size | vertical size | aspect ratio | frame rate |
byte 8 | byte 9 | byte 10 | byte 11 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
bit rate | 1 | VBV buffer size | constrained parameters flag | load intra quantiser matrix | (load non-intra quantiser matrix) |
Code | Aspect Ratio | Frame Rate |
---|---|---|
0 | forbidden | forbidden |
1 | 1:1 | 24000/1001 (23.976) |
2 | 4:3 | 24 |
3 | 16:9 | 25 |
4 | 2.21:1(not used in DVD) | 30000/1001 (29.97) |
5 | reserved | 30 |
6 | reserved | 50 |
7 | reserved | 60000/1001 (59.94) |
8 | reserved | 60 |
9 | reserved | reserved |
: | ||
15 | reserved | reserved |
extension header (01B5)
There are a variety of extensions, denoted by the first 4 bits.Sequence_Extension
Fixed length.byte 4 | byte 5 | byte 6 | byte 7 | byte 8 | byte 9 | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0001 | profile and level | progressive_sequence | chroma_format | horizontal size extension | vertical size extension | bit rate extension | 1 | vbv buffer size extension | low delay | frame rate extension n | frame rate extension d |
Sequence_Display_Extension
Variable length.byte 4 | byte 5 | byte 6 | byte 7 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
0010 | video format | color description flag =0 |
| ||||||||||||||||||||||||||||
=1 | color primaries | transfer characteristics | matrix coefficients |
byte 5 byte 8 | byte 6 byte 9 | byte 7 byte 10 | byte 8 byte 11 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
display horizontal size | 1 | display vertical size | 0 0 0 |
Picture_Coding_Extension
Variable length.byte 4 | byte 5 | byte 6 | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
1000 | f_code[0][0] (forward horizontal) | f_code[0][1] (forward vertical) | f_code[1][0] (backward horizontal) | f_code[1][1] (backward vertical) | intra_DC_precision | picture_structure |
byte 7 | |||||||
---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Top_Field_First | frame_pred_frame_dct | concealment_motion_vectors | q_scale_type | intra_vlc_format | alternate_scan | Repeat_First_Field | chroma_420_type |
byte 8 | byte 9 | byte 10 | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
progressive_frame | composite_display =0 | 0 0 0 0 0 0 |
| ||||||||||||||||||||
=1 | v_axis | field_sequence | sub_carrier | burst_amplitude | sub_carrier_phase | 0 0 |
Group Of Pictures (GOP) (01B8)
Fixed length, contains 3 flags and the time stamp for the first frame.byte 4 | byte 5 | byte 6 | byte 7 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
drop frame flag | hour (0-23) | minute (0-59) | 1 | second (0-59) | frame (0-59) | closed GOP | broken GOP | 0 0 0 0 0 |
DVD-Video home