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, each with a stream type.
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.What the explorer shows
A dropped .ts, .m2ts, .mts, .m2t, .tp or .trp file opens as a transport stream when its first three packets each start with 47, an exact stride apart: 188 bytes, 192 in a Blu-ray or AVCHD file (a 4-byte timestamp before each packet) or 204 (16 bytes of Reed-Solomon parity after each). Any other .ts file, such as TypeScript source code or a Qt translation file, is not read as one. See BDAV and M2TS.
The tree has a node for every packet of the file, opened when asked for, with the header, the adaptation field (PCR, OPCR, splice countdown, private data and extension) and the payload broken down to the bit. In a packet that carries a table the section is split into its fields, with the CRC-32 checked; in a packet that starts a PES packet the PES header is shown field by field, and the video, audio and subtitle units in the payload are listed. Damage is shown where it is: a lost sync is a node of its own and the stream is picked up again after it.
The tabs summarise a window of the file (100,000 packets by default; the First packet, Packets and Start time options move and resize it, and Program and PIDs filter it):
- Stream – framing, packets, duration and rate from the PCR, system (DVB, ATSC, ISDB), CRC and continuity totals.
- Programs – the PAT and PMTs: every program with its streams, codecs, languages, parameters from the first headers, and descriptors.
- PIDs – packets, share, payload starts, continuity errors, duplicates, scrambled and error packets, PCRs and rate of each PID, and every continuity jump.
- Tables – the distinct sections and every section in order, each opening field by field: DVB, ATSC and SCTE 35 tables and their descriptors.
- Timing – PCR, PTS and DTS: rate, interval, accuracy and a list of every PCR.
- PES – the PES packets with their time stamps.
- Elementary streams – the headers inside the streams (MPEG-2, H.264, H.265, AV1 and audio frames, subtitles, teletext) as a list, and each stream as a file of its own, from the whole file.
- Sound – playback of MPEG audio, AAC, AC-3, E-AC-3, DTS, Opus and Blu-ray LPCM streams.
- Captions – CEA-608 and CEA-708 closed captions in MPEG-2, H.264 and HEVC video and ARIB STD-B24 captions, one row for each text with its time, all rows paged.
What is not decoded is listed under Not described.
Not described
Known, not yet covered
- Reference and Viewer: the ATSC A/90 data tables, the TV-Anytime tables (RCT, CIT, RNT), the ARIB tables DCT, DLT, AMT, LIT, ERT and ITT and the contents of conditional access messages are named and CRC-checked but their bodies are bytes; object carousel modules are not reassembled; see SI tables and PSI sections.
- Reference and Viewer: some descriptors (the MPEG-4 systems, stereoscopic and a few ATSC and ARIB ones, and the private descriptors of specifiers other than EACEM, NorDig, UK DTT, Eutelsat, Astra, Sky and Australia) are listed by name with their body as bytes; see Descriptors.
- Viewer: pictures are decoded for H.264 only (the Elementary streams tab draws the first, middle and last picture of a stream, interlaced ones too, and says why for one it cannot decode); for MPEG-2 and H.265 slice headers are read to the slice type (for the first slice of each picture) and for AV1 to the frame type. AC-4, MPEG-H 3D audio and the Blu-ray graphics streams are named, not parsed or played; TrueHD has its headers read but is not played; caption text is decoded without its styling. See Elementary stream headers.
- Viewer: the detail tabs cover one window of the file (the tree covers all of it); scrambled payloads are not read; Reed-Solomon errors are detected, not corrected; the BDAV playlist and clip information files are not read.
- Reference: the 2021 edition of ITU-T H.222.0 and the full ETSI and ATSC documents were not available to check every table; names and codes were taken from the published open-source tables of TSDuck and the standards' own listings where they could be read, and the stream type and descriptor pages say where a value is a vendor or system assignment.
Also used for
- TypeScript source code – JavaScript with static types, compiled to plain JavaScript.
- TypeScript source code – JavaScript with static types, compiled to plain JavaScript.
Links
Software
- VLC media player – free media player that plays TS, M2TS and MTS files (Windows, macOS, Linux, mobile)
- mpv – free, minimal media player (Windows, macOS, Linux)
- HandBrake – free video converter that turns TV recordings into MP4 or MKV (Windows, macOS, Linux)
- FFmpeg – command-line tools that read, write and convert transport streams (Windows, macOS, Linux)
- TSDuck – free tools for analysing and editing transport streams (Windows, macOS, Linux)
- MKVToolNix – remuxes TS into MKV without re-encoding (Windows, macOS, Linux)
Developers
- libavformat – FFmpeg’s container library, which reads and writes transport streams (C)
- TSDuck – the library behind the TSDuck tools (C++)
Reference
- ITU-T Recommendation H.222.0 – MPEG-2 Systems, which defines the transport stream