Transport Packets
MPEG packages all data into fixed-size 188-byte packets for transport.
Video or audio payload data may have already been placed in PES packets before it is broken up into fixed length transport packet payloads. A PES packet may be much longer than a transport packet. When segmenting the PES packet for placement in transport packet payloads, the PES header is always placed immediately following a transport header. Successive portions of the PES packet are then placed in the payloads of transport packets. Remaining space in the final transport packet payload is filled with stuffing bytes = 0xFF (all ones).
Each transport packet starts with a sync byte = 0x47. In the ATSC US terrestrial DTV VSB transmission system, this byte is not processed, but is replaced by a different sync symbol especially suited to RF transmission.
Among other data, the transport packet header contains a 13-bit PID (packet ID), which corresponds to a particular elementary stream of video, audio, or other program element. PID 0x0000 is reserved for transport packets carrying a program association table (PAT). The PAT points to a Program Map Table (PMT), which in turn points to particular elements of a program. Demultiplexing a transport stream thus involves:
1) finding the PAT by selecting packets with PID = 0x0000
2) reading the PIDs for the PMTs
3) reading the PIDs for the elements of a desired program from its PMT (for example, a basic program will have a PID for audio and a PID for video)
4) detecting packets with the desired PIDs and routing them to the decoders