Ch. 16 · Containers in Depth

한국어日本語
6 min

MPEG-TS: A Container That Streams in 188-Byte Packets

MPEG-TS, used in broadcasting and early HLS, was designed on the assumption of a never-ending stream, not a file.

MPEG-TS (Transport Stream) is a container designed for broadcast transmission. It has no index for the whole file; instead it keeps sending small packets of equal size so that it can be read no matter where you start receiving. That character is also why early HLS used this format for its segments (HLS and DASH).

Packet structure

  • A packet is a fixed 188 bytes, and its first byte (the sync byte) is always 0x47. Even if you start receiving in the middle, you can find this byte and realign the packet boundaries.
  • The header has a PID (13 bits) that says which stream (video, audio, tables, and so on) this packet is a piece of. Multiple programs and streams are mixed into a single TS.
  • There is a continuity counter (4 bits) so you can tell whether a packet was dropped along the way. It is a design that assumes broadcast networks where transmission errors occur.
PATPMTVideoVideoAudioVideoPMTVideoAudioVideo Every packet is 188 bytes. PAT → PMT tells you which PID is the video
Packets distinguished by PID flowing mixed together (conceptual diagram)

A receiver first reads the PAT (Program Association Table), which arrives on PID 0, to learn the list of programs and where each program's PMT is. From the PMT (Program Map Table) it learns which PID carries the video and which the audio, and which codecs they use. Because these tables are sent repeatedly, a receiver that tunes in mid-stream can work out the structure soon after.

PES and the 90 kHz clock

Video and audio data are wrapped into PES packets, then cut into 188-byte pieces and carried in TS packets. The PES header holds the PTS and DTS (next lesson), and these values are in units of a 90 kHz clock. In addition, the PCR (based on 27 MHz), which carries the sender's reference clock, is transmitted at regular intervals so the receiver can synchronize its clock.

MPEG-TSMP4
IndexNone (the PAT/PMT tables only describe the structure)An index such as moov/Cues is central
Reading from the middleEasy: the sync byte and repeated tablesNeeds the index (fMP4 can do it fragment by fragment)
OverheadRelatively large, because of fixed-size packet headers and repeated tablesRelatively small
Main usesBroadcast, IPTV, camcorders (AVCHD), early HLSFile storage and distribution, fMP4 streaming

"Larger overhead" describes the direction implied by the structure; the exact ratio varies by stream.

In the field: why people cut and concatenate .ts files

Because TS packets are independent, simply joining two TS files end to end often plays back (though the timestamps are discontinuous, so the player has to handle that). Thanks to this property, TS has long been used for editing broadcast recordings and for joining HLS segments. Still, new streaming today is largely moving toward fMP4 (CMAF) (CMAF).

MPEG-TSMPEG transport stream

A broadcast container that streams fixed 188-byte packets, distinguished by PID.

PIDPacket identifier

A 13-bit value in the TS packet header. It indicates which stream the packet belongs to.

PAT / PMTProgram association table / Program map table

Tables where the PAT gives the program list and the PMT locations, and the PMT gives each stream's PID and type.

PCRProgram clock reference

A value that carries the sender's reference clock to the receiver. Based on 27 MHz.

Check yourself

In MPEG-TS, how does a receiver find out which PID is the video and which is the audio?