The stream starts with a sequence header, which may be repeated later so a decoder can join part-way through. Fields are big-endian bit fields packed with no alignment, so offsets here are in bits from the end of the start code.
Fields
| Bit | Size | Name | Description |
|---|---|---|---|
| 0 | 12 | horizontal_size_value | low 12 bits of the picture width in pixels |
| 12 | 12 | vertical_size_value | low 12 bits of the picture height in pixels |
| 24 | 4 | aspect_ratio_information | see aspect ratio |
| 28 | 4 | frame_rate_code | see frame rate |
| 32 | 18 | bit_rate_value | low 18 bits of the bit rate, in units of 400 bit/s |
| 50 | 1 | marker_bit | 1, to stop a start code appearing |
| 51 | 10 | vbv_buffer_size_value | low 10 bits of the decoder buffer size, in units of 16,384 bits |
| 61 | 1 | constrained_parameters_flag | MPEG-1 constrained parameters; 0 in MPEG-2 |
| 62 | 1 | load_intra_quantiser_matrix | 1 if a 64-byte intra matrix follows |
| 63 | 8 × 64 | intra_quantiser_matrix | only if the flag is 1, in zig-zag order |
| then | 1 | load_non_intra_quantiser_matrix | 1 if a 64-byte non-intra matrix follows |
| then | 8 × 64 | non_intra_quantiser_matrix | only if the flag is 1, in zig-zag order |
Without an MPEG-2 sequence extension the size fields hold the whole value. The
sequence extension adds high bits:
width = (horizontal_size_extension << 12) | horizontal_size_value,
and bit rate = 400 × ((bit_rate_extension << 18) |
bit_rate_value).
Aspect ratio
In MPEG-2 the field gives the shape of the whole picture:
| Code | Picture aspect ratio |
|---|---|
| 0 | forbidden |
| 1 | square pixels (sample aspect ratio 1:1) |
| 2 | 4:3 |
| 3 | 16:9 |
| 4 | 2.21:1 |
| 5–15 | reserved |
In MPEG-1 it gives the shape of a pixel, as height ÷ width:
| Code | Pixel aspect (height ÷ width) |
|---|---|
| 0 | forbidden |
| 1 | 1.0000 |
| 2 | 0.6735 |
| 3 | 0.7031 |
| 4 | 0.7615 |
| 5 | 0.8055 |
| 6 | 0.8437 |
| 7 | 0.8935 |
| 8 | 0.9157 |
| 9 | 0.9815 |
| 10 | 1.0255 |
| 11 | 1.0695 |
| 12 | 1.0950 |
| 13 | 1.1575 |
| 14 | 1.2015 |
| 15 | reserved |
Frame rate
| Code | Frames per second |
|---|---|
| 0 | forbidden |
| 1 | 24000 / 1001 (about 23.976) |
| 2 | 24 |
| 3 | 25 |
| 4 | 30000 / 1001 (about 29.97) |
| 5 | 30 |
| 6 | 50 |
| 7 | 60000 / 1001 (about 59.94) |
| 8 | 60 |
| 9–15 | reserved. FFmpeg accepts 9 to 13 as 15, 5, 10, 12 and 15 frames per second, written by the Xing and libmpeg3 encoders |
The MPEG-2 sequence extension can scale this: the frame rate is the value above ×
(frame_rate_extension_n + 1) ÷ (frame_rate_extension_d + 1).
Quantiser matrices
When a load flag is 0, the default matrix is used. The non-intra default is 16 for all 64 entries. The intra default, from the standard, is:
8 16 19 22 26 27 29 34
16 16 22 24 27 29 34 37
19 22 26 27 29 34 34 38
22 22 26 27 29 34 37 40
22 26 27 29 32 35 40 48
26 27 29 32 35 40 48 58
26 27 29 34 38 46 56 69
27 29 35 38 46 56 69 83
Matrices are stored in the zig-zag scan order, one byte per entry:
0 1 8 16 9 2 3 10
17 24 32 25 18 11 4 5
12 19 26 33 40 48 41 34
27 20 13 6 7 14 21 28
35 42 49 56 57 50 43 36
29 22 15 23 30 37 44 51
58 59 52 45 38 31 39 46
53 60 61 54 47 55 62 63
Each number is the position, in a row-by-row 8 × 8 block, of the next value read.
Worked example
A PAL DVD stream at 720 × 576, 16:9, 25 frames a second, 8 Mbit/s, with default matrices:
00000000 00 00 01 B3 2D 02 40 33 13 88 23 80
| Bytes | Bits | Value |
|---|---|---|
2D 02 40 | 12 + 12 | width 0x2D0 (720), height 0x240 (576) |
33 | 4 + 4 | aspect code 3 (16:9), frame rate code 3 (25) |
13 88 23 80 | 18, 1, 10, 1, 1, 1 | bit rate value 20,000 (× 400 = 8,000,000), marker 1, VBV 112 (× 16,384 = 1,835,008 bits), then three zero flags |