Regarding MPEG-2 encoding: the following has been excerpted and paraphrased from http://www.bbc.co.uk/rd/pubs/papers/paper_14/paper_14.shtml:
One MPEG-2 coding element employs discrete cosine transform (DCT). Each frame is broken into small blocks (8 pixels by 8 lines) of each component of the picture. A two-dimensional DCT is performed on the small blocks to produce blocks of DCT coefficients; the magnitude of each DCT coefficient indicates the contribution of a particular combination of horizontal and vertical spatial frequencies to the original picture block.
A second coding element employs motion-compensated inter-frame prediction, a technique that exploits temporal redundancy by attempting to predict the frame to be coded from a previous 'reference' frame. The prediction cannot be based on a source picture because the prediction has to be repeatable in the decoder, where the source pictures are not available; consequently, the coder contains a local decoder which reconstructs pictures exactly as they would be in the decoder, from which predictions can be formed. The simplest inter-frame prediction of the block being coded would take the co-sited (i.e. the same spatial position) block from the reference picture. Motion-compensated inter-frame prediction, however, is more sophisticated and offsets any translational motion that has occurred between the block being coded and the reference frame.
In an MPEG-2 system, the DCT and motion-compensated interframe prediction are combined: the coder subtracts the motion-compensated prediction from the source picture to form a 'prediction error' picture. The prediction error is transformed with the DCT, the coefficients are quantized and these quantized values coded using a variable length code.
MPEG-2 defines three picture types: Intra pictures (I-frames) are coded without reference to other pictures. They are used periodically to provide access points in the bitstream where decoding can begin. Predictive pictures (P-frames) can use the previous I- or P-picture for motion compensation and may be used as a reference for further prediction. Bidirectionally-predictive' pictures (B-frames) can use the previous and next I- or P-pictures for motion-compensation, and offer the highest degree of compression. To enable backward prediction from a future frame, the coder reorders the pictures from natural 'display' order to 'bitstream' order so that the B-picture is transmitted after the previous and next pictures it references. This introduces a reordering delay dependent on the number of consecutive B-pictures. The different picture types typically occur in a repeating sequence, termed a 'Group of Pictures' or GOP. A typical GOP in display order is: B1 B2 I3 B4 B5 P6 B7 B8 P9 B10 B11 P12. For these, the corresponding bitstream order is: I3 B1 B2 P6 B4 B5 P9 B7 B8 P12 B10 B11.
Regarding the use of MPEG-2 encoding in other video formats:
VOB (DVD Video OBject) files are closely related to MPEG-2 files. VOB files are assembled by DVD producers, and they contain the actual Video, Audio, Subtitle, and Menu contents in stream form. The Wikipedia entry for VOB (as of November 28, 2006), reports that "VOB files are encoded very much like standard MPEG-2 files. When the extension is renamed from .vob to .mpg or .mpeg the file will still be readable and will continue to hold all information, although most players supporting MPEG-2 don't support subtitle tracks. In order to burn the VOB files to a DVD-R disc, other standard DVD-Video files are needed as well, including IFO and BUP files."
MOD is a file format used in JVC, Panasonic and Canon tapeless video cameras. According to the Wikipedia entry MOD files "are file-based formats that are stored on a random-access media. Standard definition video is stored in MPEG program stream container files with MOD extension; in most other systems these files have extension MPG or MPEG. MOD video can be viewed on a computer with a player that is capable of reproducing MPEG-2 video. This video can be easily authored for watching on a DVD player without recompression, because it is fully compliant with DVD-video standard." Most nonlinear editing software cannot natively ingest MOD files. These files must first be converted using transcoding software like FFmpeg.
From zatznotfunny: "TiVoToGo files, having the .tivo extension, are essentially encrypted and fingerprinted mpeg [MPEG-2] files. MPEG is a common video format. Your unique Media Access Key (MAK) is appended to all shows as text, and perhaps embedded as a watermark in other ways. The TiVo Desktop software includes a .dll that is used to decrypt, or unlock, your show using your MAK. TiVo files can be viewed, converted, edited, transferred, and/or burned."
MPEG transport stream (transport stream, MPEG-TS, MTS or TS) is a standard digital container format for transmission and storage of audio, video, and Program and System Information Protocol (PSIP) data. It is used in broadcast systems such as DVB, ATSC and IPTV.
Transport stream specifies a container format encapsulating packetized elementary streams, with error correction and synchronization pattern features for maintaining transmission integrity when the communications channel carrying the stream is degraded.
Transport streams differ from the similarly-named MPEG program stream in several important ways: program streams are designed for reasonably reliable media, such as discs (like DVDs), while transport streams are designed for less reliable transmission, namely terrestrial or satellite broadcast. Further, a transport stream may carry multiple programs.
Transport stream is specified in MPEG-2 Part 1, Systems, formally known as ISO/IEC standard 13818-1 or ITU-T Rec. H.222.0.
Layers of communication
A transport stream encapsulates a number of other substreams, often packetized elementary streams (PES) which in turn wrap the main data stream of an MPEG codec, as well as any number of non-MPEG codecs (such as AC3 or DTS audio, and MJPEG or JPEG 2000 video), text and pictures for subtitles, tables identifying the streams, and even broadcaster-specific information such as an electronic program guide. Many unrelated streams are often mixed together, such as several different television channels, or multiple angles of a movie. Each stream is chopped into (at most) 188-byte sections and interleaved together; because of the tiny packet size, streams can be interleaved with less latency and greater error resilience compared to program streams and common containers such as AVI, MOV/MP4, and MKV, which generally wrap each frame into one packet. This is particularly important for videoconferencing, where even one large frame may introduce unacceptable audio delay.
Transport streams tend to be broadcast as constant bitrate (CBR) to maintain a consistent broadcast rate, filled with padding bytes when not enough data exists, although the Blu-Ray format does not require CBR.
Important elements of a transport stream
A packet is the basic unit of data in a transport stream, and a transport stream is merely a sequence of packets, without any global header. Each packet starts with a sync byte and a header, that may be followed with optional additional headers; the rest of the packet consists of payload. All header fields are read as big-endian. Packets are 188 bytes in length, but the communication medium may add additional information: Forward error correction is added by ISDB & DVB (16 bytes) and ATSC (20 bytes), while the M2TS format prefixes packets with a 4-byte copyright and timestamp tag. The 188-byte packet size was originally chosen for compatibility with ATM systems.
|4-byte Transport Stream Header|
|Sync byte||8||Bit pattern of 0x47 (ASCII char 'G')|
|Transport Error Indicator (TEI)||1||Set when a demodulator can't correct errors from FEC data; indicating the packet is corrupt.|
|Payload Unit Start Indicator (PUSI)||1||Set when a PES, PSI, or DVB-MIP packet begins immediately following the header.|
|Transport Priority||1||Set when the current packet has a higher priority than other packets with the same PID.|
|PID||13||Packet Identifier, describing the payload data.|
|Transport Scrambling Control (TSC)||2||'00' = Not scrambled. |
For DVB-CSA and ATSC DES only:
|Adaptation field control||2||01 – no adaptation field, payload only,|
10 – adaptation field only, no payload,
|Continuity counter||4||Sequence number of payload packets (0x00 to 0x0F) within each stream (except PID 8191)|
Incremented per-PID, only when a payload flag is set.
|Adaptation field||variable||If Adaptation field flag is set in the Adaptation field control, see below.|
|Payload Data||variable||If Payload flag is set in the Adaptation field control. Payload may be PES packets, program specific information (below), or other data.|
|Adaptation Field Length||8||Number of bytes in the adaptation field immediately following this byte|
|Discontinuity indicator||1||Set if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference|
|Random Access indicator||1||Set when the stream may be decoded without errors from this point|
|Elementary stream priority indicator||1||Set when this stream should be considered "high priority"|
|PCR flag||1||Set when PCR field is present|
|OPCR flag||1||Set when OPCR field is present|
|Splicing point flag||1||Set when splice countdown field is present|
|Transport private data flag||1||Set when private data field is present|
|Adaptation field extension flag||1||Set when extension field is present|
|PCR||48||Program clock reference, stored as 33 bits base, 6 bits reserved, 9 bits extension.|
The value is calculated as base * 300 + extension.
|OPCR||48||Original Program clock reference. Helps when one TS is copied into another|
|Splice countdown||8||Indicates how many TS packets from this one a splicing point occurs (Two's complement signed; may be negative)|
|Transport private data length||8||The length of the following field|
|Transport private data||variable||Private data|
|Adaptation extension||variable||See below|
|Stuffing bytes||variable||Always 0xFF|
|Adaptation extension length||8||The length of the header|
|Legal time window (LTW) flag||1|
|Piecewise rate flag||1|
|Seamless splice flag||1|
|LTW flag set (2 bytes)|
|Legal time window valid flag||1|
|Legal time window offset||15||Extra information for rebroadcasters to determine the state of buffers when packets may be missing.|
|Piecewise flag set (3 bytes)|
|Piecewise rate||22||The rate of the stream, measured in 188-byte packets, to define the end-time of the LTW.|
|Seamless splice flag set (5 bytes)|
|Splice type||4||Indicates the parameters of the H.262 splice.|
|DTS next access unit||36||The PES DTS of the splice point.|
Split up as 3 bits, 1 marker bit (0x1), 15 bits, 1 marker bit, 15 bits, and 1 marker bit, for 33 data bits total.
Packet Identifier (PID)
Each table or elementary stream in a transport stream is identified by a 13-bit packet identifier (PID). A demultiplexer extracts elementary streams from the transport stream in part by looking for packets identified by the same PID. In most applications, time-division multiplexing will be used to decide how often a particular PID appears in the transport stream.
|0||0x0000||Program Association Table (PAT) contains a directory listing of all Program Map Tables|
|1||0x0001||Conditional Access Table (CAT) contains a directory listing of all ITU-T Rec. H.222 entitlement management message streams used by Program Map Tables|
|2||0x0002||Transport Stream Description Table (TSDT) contains descriptors relating to the overall transport stream|
|3||0x0003||IPMP Control Information Table contains a directory listing of all ISO/IEC 14496-13 control streams used by Program Map Tables|
|4-15||0x0004-0x000F||Reserved for future use|
|16-31||0x0010-0x001F||Used by DVBmetadata|
|32-8186||0x0020-0x1FFA||May be assigned as needed to Program Map Tables, elementary streams and other data tables|
|8187||0x1FFB||Used by DigiCipher 2/ATSC MGT metadata|
|8188-8190||0x1FFC-0x1FFE||May be assigned as needed to Program Map Tables, elementary streams and other data tables|
|8191||0x1FFF||Null Packet (used for fixed bandwidth padding)|
Transport stream has a concept of programs. Every single program is described by a Program Map Table (PMT) which has a unique PID, and the elementary streams associated with that program have PIDs listed in the PMT. For instance, a transport stream used in digital television might contain three programs, to represent three television channels. Suppose each channel consists of one video stream, one or two audio streams, and any necessary metadata. A receiver wishing to decode a particular "channel" merely has to decode the payloads of each PID associated with its program. It can discard the contents of all other PIDs. A transport stream with more than one program is referred to as MPTS - Multi Program Transport Stream. A single program transport stream is referred to as SPTS - Single Program Transport Stream.
Program specific information (PSI)
Main article: Program-specific information
There are 4 program specific information (PSI) tables: program association (PAT), program map (PMT), conditional access (CAT), and network information (NIT). The MPEG-2 specification does not specify the format of the CAT and NIT.
The program association table lists all programs available in the transport stream. Each of the listed programs is identified by a 16-bit value called program_number. Each of the programs listed in PAT has an associated value of PID for its program map table (PMT).
The value 0x0000 for program_number is reserved to specify the PID where to look for network information table. If such a program is not present in PAT the default PID value (0x0010) shall be used for NIT.
TS packets containing PAT information always have PID 0x0000.
Program Map Tables (PMTs) contain information about programs. For each program, there is one PMT. While the MPEG-2 standard permits more than one PMT section to be transmitted on a single PID (Single Transport stream PID contains PMT information of more than one program), most MPEG-2 "users" such as ATSC and SCTE require each PMT to be transmitted on a separate PID that is not used for any other packets. The PMTs provide information on each program present in the transport stream, including the program_number, and list the elementary streams that comprise the described MPEG-2 program. There are also locations for optional descriptors that describe the entire MPEG-2 program, as well as an optional descriptor for each elementary stream. Each elementary stream is labeled with a stream_type value.
To enable a decoder to present synchronized content, such as audio tracks matching the associated video, at least once each 100 ms a program clock reference (PCR) is transmitted in the adaptation field of an MPEG-2 transport stream packet. The PID with the PCR for an MPEG-2 program is identified by the pcr_pid value in the associated PMT. The value of the PCR, when properly used, is employed to generate a system_timing_clock in the decoder. The system time clock (STC) decoder, when properly implemented, provides a highly accurate time base that is used to synchronize audio and video elementary streams. Timing in MPEG2 references this clock. For example, the presentation time stamp (PTS) is intended to be relative to the PCR. The first 33 bits are based on a 90 kHz clock. The last 9 are based on a 27 MHz clock. The maximum jitter permitted for the PCR is +/- 500 ns.
Some transmission schemes, such as those in ATSC and DVB, impose strict constant bitrate requirements on the transport stream. In order to ensure that the stream maintains a constant bitrate, a Multiplexer may need to insert some additional packets. The PID 0x1FFF is reserved for this purpose. The payload of null packets may not contain any data at all, and the receiver is expected to ignore its contents.
Use in digital video cameras
Transport Stream had been originally designed for broadcast. Later it was adapted for usage with digital video cameras, recorders and players by adding a 4-byte timecode (TC) to standard 188-byte packets, which resulted in a 192-byte packet. This is what is informally called M2TS stream. The Blu-ray Disc Association calls it "BDAV MPEG-2 transport stream". JVC called it TOD (possibly an abbreviation for "Transport stream on disc") when used in HDD-based camcorders like GZ-HD7. The timecode allows quick access to any part of the stream either from a media player, or from a non-linear video editing system. It is also used to synchronize video streams from several cameras in a multi-camera shoot.
Use in Blu-ray
Filename extension .m2ts is used on Blu-ray Disc Video for files which contain an incompatible BDAV MPEG-2 transport stream due to the four additional octets added to every packet. Blu-ray Disc Video titles authored with menu support are in the BDMV (Blu-ray Disc Movie) format and contain audio, video, and other streams in a BDAV container, which is based on the MPEG-2 transport stream format. There is also the BDAV (Blu-ray Disc Audio/Visual) format, the consumer oriented alternative to the BDMV format used for movie releases. The BDAV format is used on BD-REs and BD-Rs for audio/video recording. Blu-ray Disc employs the MPEG-2 transport stream recording method. That enables transport streams of a BDAV converted digital broadcast to be recorded as they are with minimal alteration of the packets. It also enables simple stream cut style editing of a BDAV converted digital broadcast that is recorded as is and where the data can be edited just by discarding unwanted packets from the stream. Although it is quite natural, a function for high-speed and easy-to-use retrieval is built in. Blu-ray Disc Video uses these modified MPEG-2 transport streams, compared to DVD's program streams that don't have the extra transport overhead.
- ^"RFC 3555 - MIME Type Registration of RTP Payload Formats". July 2003. Retrieved 20 March 2010.
- ^ abcITU-T (October 2014). "Recommendation H.222.0 (10/14)".
- ^"MPEG-2 Transport Stream". AfterDawn.com. Retrieved 8 June 2010.
- ^"ATSC transmission". Broadcastengineering.com. 2005-06-20. Retrieved 2012-05-17.
- ^"MPEG Systems FAQ". Mpeg.chiariglione.org. Retrieved 2012-05-17.
- ^"ATSC MPEG Transport Stream Monitor". Tek.com. Retrieved 2012-05-17.
- ^"TSReader". Coolstf.com. 2008-04-07. Retrieved 2012-05-17.
- ^Support for use of the DVB Scrambling Algorithm version 3 within digital broadcasting systems Page 6
- ^"5.1.3 Coding of PID and table_id fields". Digital Video Broadcasting (DVB); Specification for Service Information (SI) in DVB systems(PDF). EN. 300 468 (v1.13.1 ed.). ETSI. 2012. p. 20. Retrieved 2016-10-13.
- ^ abcBlu-ray Disc Association (March 2005) BD ROM - Audio Visual Application Format Specifications (PDF) Page 15, Retrieved on 2009-07-26
- ^ abcBlu-ray Disc Association (March 2008) BD-RE - Audiovisual Application Format Specification for BD-RE 2.1Archived 30 July 2009 at WebCite (PDF), Technical White Papers - BD RE, Retrieved on 2009-07-28
- ^"Steve Mullen, M2TS primer".
- ^Working with JVC Everio MOD & TOD files, Retrieved on 2009-07-27
- ^"How MPEG-TS works, videohelp.com". Forum.videohelp.com. Retrieved 2012-05-17. [self-published source?]
- ^Videohelp.com What is Blu-ray Disc and HD DVD?Archived 29 July 2009 at WebCite, Retrieved on 2009-07-26
- ^AfterDawn.com Glossary - BD-MV (Blu-ray Movie) and BDAV containerArchived 29 July 2009 at WebCite, Retrieved on 2009-07-26
- ^ abAfterDawn.com Glossary - BDAV container, Retrieved on 2009-07-26
- ^Blu-ray Disc Association (August 2004) Blu-ray Disc Format, White paper (PDF) Page 22, Retrieved on 2009-07-28