MPEG Transport Stream
The container DVB broadcast delivery travels in — carrying today's H.264 and H.265 services, because "MPEG-2" names the container, not the codec. Fixed 188-byte packets, 13-bit PIDs, and the tables that turn an opaque bitstream into television.
First, the name is misleading
MPEG-2 Systems
ISO/IEC 13818-1. The transport stream — the container. Still universal in DVB broadcast.
MPEG-2 Video
ISO/IEC 13818-2. A 1990s codec, now largely legacy. Different standard, same family name.
The packet in one picture
| Part | Size | Notes |
|---|---|---|
| Header | 4 bytes | Always present. Never scrambled. |
| Adaptation field | 0 – 183 bytes | Optional. Carries PCR, stuffing, flags. |
| Payload | up to 184 bytes | PES media, or table sections. |
Header fields worth knowing
| Field | Bits | Why you care |
|---|---|---|
| sync_byte | 8 | 0x47 every time. How the demux finds alignment. |
| transport_error_indicator | 1 | Upstream demod says this payload is damaged. |
| PUSI | 1 | This packet starts a new payload unit. Your resync anchor. |
| PID | 13 | Which elementary stream. 0x0000–0x1FFF. |
| scrambling_control | 2 | Scrambled? Even or odd key? |
| adaptation_field_control | 2 | Adaptation field present? Payload present? |
| continuity_counter | 4 | Loss detection, mod 16. |
Reserved PID map — memorize this
| PID | Table | What it tells you |
|---|---|---|
0x0000 | PAT | Every service, and where its PMT lives. Start here. |
0x0001 | CAT | EMM streams. Absent if nothing is scrambled. |
0x0002 | TSDT | Rarely used. |
0x0010 | NIT | Every transport stream in the network, with tuning parameters. |
0x0011 | SDT / BAT | Service names; bouquet groupings. |
0x0012 | EIT | Now/next banner and the full EPG. |
0x0013 | RST | Event started or ended early. |
0x0014 | TDT / TOT | UTC and local offset. Every 10–30 s only. |
0x1FFF | null | Padding to hold constant bitrate. |
PSI vs SI — which spec to open
PSI — MPEG
ISO/IEC 13818-1. Structure of the stream itself: PAT, PMT, CAT, TSDT. Present in any conformant TS anywhere in the world.
SI — DVB
ETSI EN 300 468. The stream as a service offering: NIT, SDT, BAT, EIT, RST, TDT, TOT. Names, schedules, networks, time.
Five things that bite people
A round decimal buffer size eventually splits a packet across a read boundary. Align everything to 188.
Lose exactly 16, 32 or 48 packets and the counter lands where it would have anyway. A cheap check, not a guarantee.
On some hardware, polling signal statistics itself causes continuity errors. Disabling frontend polling can clear them — at the cost of live signal reporting.
Right after tuning, the PMT may not be known yet. Request by explicit PID list and you need no table knowledge; request by program and you must wait.
The decoder locks a PLL to PCR arrival. Remultiplexing and reinserting PCRs at the wrong instants breaks playback that was previously fine, even when every value is technically correct.
Timing in three lines
| Stamp | Clock | Job |
|---|---|---|
| PCR | 27 MHz — 33-bit base at 90 kHz + 9-bit extension | Lets the decoder rebuild the encoder's clock. At least every 100 ms. |
| DTS | 90 kHz | When to decode a frame. |
| PTS | 90 kHz | When to present it. Differs from DTS whenever B-frames are used. |
PCR = PCR_base × 300 + PCR_ext — because 27 MHz ÷ 90 kHz = 300.
Two payload types
PES — media
Video, audio, subtitles, teletext. Up to 65536 bytes per PES packet, spread over many TS packets. Start marked by PUSI.
Sections — tables
Signalling. Up to 4096 bytes per section. Long sections carry a version number and a CRC32; short ones carry neither.