Introduction
The MPEG transport stream is the container used for digital television. It is defined
in MPEG-2 Systems (ISO/IEC 13818-1, also ITU-T H.222.0) and was designed for links that
can lose or corrupt data, such as broadcast. DVB, ATSC and IPTV broadcasts use it,
recordings from TV tuners are saved as .ts files, and HTTP Live Streaming
has long delivered its segments as .ts files.
Blu-ray discs and AVCHD camcorders use a variant with the extensions
.m2ts and .mts, in which each packet is preceded by a
4-byte timestamp. The .ts extension is also used for TypeScript source
code.
Structure
A transport stream is a sequence of fixed-size packets of 188 bytes. Each packet
starts with the sync byte 47, followed by flags and a 13-bit packet
identifier (PID) that says which stream the packet belongs to, a continuity counter
and an optional adaptation field that can carry the programme clock. The rest of the
packet is payload.
The audio and video are cut into PES packets (packetised elementary streams) and spread across transport packets with the same PID. Tables tell a receiver what is in the stream: the Program Association Table on PID 0 lists the programmes, and each programme’s Program Map Table lists the PIDs of its video, audio and subtitle streams.
0Sync byte471 byte1Flags and PID error, payload start, priority, 13-bit PID2 bytes3Control scrambling, adaptation field control, continuity counter1 byte4Adaptation field and payload184 bytes
.m2ts files a 4-byte timestamp comes first, making 192 bytes.Also used for
Links
Software
- VLC media player (Windows, macOS, Linux, mobile)
- mpv (Windows, macOS, Linux)
- HandBrake (Windows, macOS, Linux)
- FFmpeg (Windows, macOS, Linux)
- TSDuck, tools for analysing and editing transport streams (Windows, macOS, Linux)
- MKVToolNix, which remuxes TS into MKV (Windows, macOS, Linux)
Developers
- libavformat, C, FFmpeg’s container library
- TSDuck, C++ library behind the TSDuck tools
Reference
- ITU-T Recommendation H.222.0, MPEG-2 Systems