A packetised elementary stream (PES) packet carries part of one stream in a program stream, and the same structure is used in transport streams. This layout is that of MPEG-2; an MPEG-1 packet has a simpler header, described at the end.
Fixed header
| Bits | Name | Meaning |
|---|---|---|
| 24 | packet_start_code_prefix | 00 00 01. |
| 8 | stream_id | Which stream. See Stream IDs. |
| 16 | PES_packet_length | Bytes after this field. Zero, meaning unbounded, is allowed only for video in a transport stream. |
Padding and private stream 2 have no optional header: their data follows at once.
Optional header
| Bits | Name | Meaning |
|---|---|---|
| 2 | marker | 10. |
| 2 | PES_scrambling_control | 00 means not scrambled. |
| 1 | PES_priority | Higher priority. |
| 1 | data_alignment_indicator | The header is followed directly by a video start code or audio sync word. |
| 1 | copyright | Copyrighted. |
| 1 | original_or_copy | 1 for an original. |
| 2 | PTS_DTS_flags | 10 PTS only, 11 PTS and DTS, 00 neither, 01 forbidden. |
| 1 | ESCR_flag | ESCR present. |
| 1 | ES_rate_flag | ES rate present. |
| 1 | DSM_trick_mode_flag | Trick mode byte present. |
| 1 | additional_copy_info_flag | Copy info byte present. |
| 1 | PES_CRC_flag | CRC present. |
| 1 | PES_extension_flag | Extension present. |
| 8 | PES_header_data_length | Bytes of optional fields and stuffing that follow. |
Optional fields, in order
| Field | Size | Layout |
|---|---|---|
| PTS | 5 bytes | Prefix 0010 (PTS only) or 0011 (PTS with DTS), then PTS[32..30], marker, [29..15], marker, [14..0], marker. |
| DTS | 5 bytes | Prefix 0001, then the same layout. |
| ESCR | 6 bytes | Prefix 00, then the 33-bit base in three parts with markers, then a 9-bit extension and a marker. |
| ES_rate | 3 bytes | Marker, 22-bit rate in units of 50 bytes per second, marker. |
| DSM trick mode | 1 byte | See below. Not used by DVD. |
| Additional copy info | 1 byte | Marker, 7 bits. |
| Previous PES CRC | 2 bytes | 16 bits, polynomial X16 + X12 + X5 + 1. |
| Extension | varies | A flags byte for private data, pack header field, program packet sequence counter and P-STD buffer, with 111 and extension flag 2; then each field. Private data is 16 bytes. The pack header field has an 8-bit length. The sequence counter has the counter, an MPEG-1 or MPEG-2 flag and the original stuffing length. The P-STD buffer is 01, a scale bit (0 is 128 bytes, 1 is 1024) and a size. Extension flag 2 has a marker and a 7-bit length, then that many bytes. |
| Stuffing | 0 or more | FF bytes, counted in PES_header_data_length. |
The trick mode byte starts with a 3-bit trick_mode_control from memory of
H.222.0: 000 fast forward, 001 slow motion, 010
freeze frame, 011 fast reverse, 100 slow reverse; the rest are
reserved. The remaining 5 bits depend on it.
MPEG-1 packets
Unconfirmed, from memory of ISO/IEC 11172-1: after the packet length come up to 16
stuffing bytes FF; then optionally 01, a buffer scale bit and a
13-bit buffer size; then either a PTS with prefix 0010, a PTS and DTS
with prefixes 0011 and 0001, or the byte
0F.