TS Stream parsing Three

Source: Internet
Author: User

Should say really understand TS, or read a friend recommended "digital television business information and its code" after a book, MPEG2 TSand digital television is closely inseparable, it is worth summing up some of the relationship.

Iso/iec-13818-1: System part;
Iso/iec-13818-2: Video;
Iso/iec-13818-3: Audio;
ISO/IEC-13818-4: Conformance testing;
ISO/IEC-13818-5: Software part;
ISO/IEC-13818-6: Digital Storage media command and control;
ISO/IEC-13818-7: Advanced Audio coding;
Iso/iec-13818-8: System decoding real-time interface;

MPEG2 system tasks include:
1. A protocol that provides for the transmission of data by packet;
2. The protocol that specifies the synchronization of data flow between two ends;
3. Provide multiplexing and multiplexing protocols for multiple data streams;
4. Provide the protocol for data stream encryption.

Storing and transmitting data streams in package form is a key point of MPEG2 system.

es is a data stream elementary stream directly from the encoder, which can be a generic term for encoded video streams, audio streams, or other encoded data streams .

After the ES stream passes through the PES packager, it is converted into a PES package . The PES package consists of Baotou and payload , and the specific format is summarized as follows:

You can see that Pts/dts is in the PES package , these two parameters is the key to solve the video-audio synchronization display, to prevent the decoder input cache overflow or underflow.

PTS indicatesDisplay Unitappear inSystem Target Decoder(Std:system target decoder), DTS represents the timeAccess UnitAll bytestime to remove from STD's ES decoder cache。 EachI、P、Bof the frameBaotou has a PTS and DTS But PTS vs. DTS to B The frames are all the same.no need to mark out B -Frame DTS 。 RightIFrames andPFrame, must be stored before the displayreorder buffers for video decodersAfter a delay (reorder), be sure toindicated separately PTS and DTS

As described above,es first need to be packaged into PES streaming package , then PES packaged into PS or TS package for storage or transmission . Each of its ES contains only the encoded data stream of one source , so each PES also contains only the data stream relative to the source .

For PS streams, each PES header contains pts and DTS, stream identification codes , which are used to differentiate es in different properties. the PES package is then re-used into PS package via PS multiplexer . The fact is that the PES package is decomposed into a smaller PS package .

at the time of decoding, the multiplexer decomposes PS into a PES package, unpacking and then splitting the PES package into ES of video and audio, and then decoding it into the respective decoder .

One problem is: How to ensure the synchronization of audio and video when each es is decoded ? in addition to working with PTS and DTS, an important parameter is SCR (System clock Reference). at the time of encoding,both Pts,dts and SCRare generated by the STC (System time Clock), and when Decoded, the STC regenerates and passes through the PLL (Pll-phase lock Loop), The local SCR phase is compared with the instantaneous SCR phase lock of the input to determine if the decoding process is synchronous and, if not, the 27MHz Local clock frequency is adjusted with this instantaneous SCR. Finally,Pts,dts and SCR work together to solve the problem of video-audio synchronization playback . The PS format excerpt is as follows:

PS Package length is longer and variable , mainly used in the error -prone environment, because the longer the more difficult synchronization, and in the case of packet loss, reorganization is also more difficult. Therefore,PS is suitable for the editing of program information and the application of local content application.


TS Stream is also a combination of one or more PEs , they can have the same time base, or can be different . The basic reuse idea is that multiple PES with the same time benchmark are now re-used for program reuse , and then Multiplexing each PS with independent time benchmarks to produce TSeventually.

The TS package consists of 2 parts of Baotou and packet data, of which Baotou can also include extended self-applicability zones . Baotou length accounted for 4bytes, since the use of the zone and the package data accounted for 184bytes, the entire TS package length equivalent to 4 ATM packets long . The packet header of the TS package is provided by the synchronization byte, transmission error indicator, Payload unit start indicator, transmission priority, packet identification (pid-packet identification), transmission scrambling control, The Adaptive Zone control and the continuous counter are composed of 8 parts.


among them, the automatic correlation characteristic of the synchronized byte bit string can be used to detect the packet limit in the data stream and set up the packet synchronization ; Transmission error indicator, refers to the error can not be eliminated, the use of error correction decoder can represent 1bit error, but can not be corrected;The starting indicator of the payload unit, indicating whether the packet has a definite starting information;transmission priority, is to assign priority to the TS packet, the PID value is determined by the user, the decoder according to the PID will never be the TS with ES from the TS package, to reconstruct the original ES;the transmission scrambling control can indicate whether the packet content is scrambling, but the Baotou and adaptive zone will never be disturbed;Adaptive Zone control, with 2 bit indicating whether there is an adaptive zone,i.e. (01) indicates that there is no adaptive zone for useful information,(10) indicates that no useful information has an adaptive zone,(11) indicates that there is an adaptive zone for useful information,(00) No definition, continuous counter can count the PID packet delivery order, according to the counter readings, the receiver can determine if there is packet loss and packet delivery sequence error. Obviously, Baotou has synchronization, identification, error detection and encryption function for TS packets.

The TS packet Adaptive Zone consists of an adaptive warden, various flag indicators, information related to the insertion mark, and 4 parts of the fill data . The symbol part consists of 8 parts, such as discontinuous indicator, random access indicator, ES optimization indicator, PCR mark, contact sign, transmission special data mark, original PCR mark, Adaptive Zone extension flag . What's important is the PCR of the sign part. field , the 27MHz clock of the codec can be provided with synchronization data for synchronization. The process is that through the PLL, the phase lock loop is used to decode the local PCR phase with the input instantaneous PCR phase lock comparison, to determine whether the decoding process is synchronous, if not synchronized, then use this instantaneous PCR to adjust the clock frequency. Because, the digital image uses the complex and different compression coding algorithm, causes each image the data to be different, causes the clock information to obtain directly from the compression encoded image data the beginning part to be impossible. To do this, some, but not all, TS packages have been selected for adaptive zones to transmit timing information . Therefore, the adaptive zone of the selected TS package can be used to determine the control bit and important control information of the packet information. The adaptive zone does not need to accompany each package to send, how much is determined by the transport-specific time-scale parameters of the selected TS package. The random access indicator and the contact sign in the flag provide random entry points for randomly entering the data stream of the I-frame compression, as well as facilitating the insertion of local programs. The padding data in the adaptive zone is due to the fact that the PES packet length cannot be converted to an integer multiple of the TS package, and the last TS Packet retains a small amount of usable capacity, filled by padding bytes, which prevents the buffer from underflow and keeps the total bitrate constant.



The basic format of MPEG2 TS is summarized in section 3 above, including Pes,ps and ts, as well as descriptions of related fields . Then, as a transport stream , TS Packages/re-uses the content to turn its media content into TS transmission and eventually decodes it on the decoding side. In simple terms, TS is a transport layer of the protocol stack, it can host a variety of content transmission, such as mpeg,wmv,h264, or even IP, then how is the transport specifications defined? This is what PSI (program-specific information) is going to do.

The PSI consists of four tables: Pat,pmt,cat and NIT, each of which describes the transmission structure of all ES streams included in a TS . One of the first concepts is that TS is propagated as packets, and at the codec end It is necessary to identify the contents of the TS stream with a certain package ID, for example, the Pat table will exist in one or more TS packages, Therefore, a special package ID is used to indicate, in addition, different ES streams need different package IDs to identify. We have the two tables of Pat and PMT, the decoder can be based on the PID, TS from the same es from the TS package to distinguish from the decoding.

ts decoding in two steps, one, is from the PID 0 ts package, the analysis of the Pat table, and then from the Pat list to find the various program source PID, generally such program sources are Dry an ES stream composition, and described in the Pmt table, and then through the program source of the PID, you can in the PMT table to retrieve the PID of each ES. Second, the decoder is based on the PID of the ES stream in the PMT table , which differentiates the packets on the TS stream and decodes them according to different ES streams. Therefore, TS is through the program reuse and transmission multiplexing two layers, that is, when the program is re-use, added PMT, in the transmission, joined PAT. Similarly, when the program is re-used, the PMT can be obtained and pat can be obtained when the transmission solution is reused. A good overview of its ideas.

TS is multiplexing -enabled, so it can be used to transmit multi-layered programs after reuse . In the process of reuse, it should be noted that the decoding process needs to face the time reference and synchronization problems, because de-multiplexing is required to synchronize the various information, so in the reuse process, it is necessary to insert the relevant time information: PTS,DTS,PCR.

In the TS formation process, pts and DTS are packaged into PEs in Es , and the clock information is injected into the PES package according to the STC reference, and then the PID and PCR information is injected into the TS Package, when multiplexing TS re-use, the various TS of the PCR will be extracted, then analyzed, and then according to the Unified STC reference, the new PCR is generated and injected into TS , and finally, Since the original Pat table information is not applicable, the new Pat table needs to be regenerated and appended to the new TS stream. After this multi-layer multiplexing, the new TS stream can enter the modulation, transmission phase. Procedures can be found in:

Decoding process to face the problem is: de-multiplexing, audio-visual synchronization, decoding buffer without overflow . The re-use is to separate TS in the same channel of different timing transmission of the program; AV synchronization is performed by DTS, Pts, and PCR , and PCR is the time base for rebuilding the system. Absolute time-scales , while DTS and PTS are relative time-scales for decoding and reproducing the moment , and the problem of no overflow of the decoding buffer must be realized by means of the system target decoder (STD) model, the basic idea is as follows:

      1. After the TS stream enters the decoder , the various ES streams are decomposed (including the PSI information flow) by the commutator , according to a certain timing relationship .
      2. After the decomposition of the ES stream into the respective transmission buffer, after which the PES stream into their main memory, note that the PSI flow will enter the system cache, and finally reach the main memory.
      3. Finally, according to DTS information, the decoder extracts media or system information from each main memory, decodes it, and displays the media content according to the PTS information.

TS Stream parsing Three

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.