TS Stream Introduction

Source: Internet
Author: User
Tags types of tables

In MPEG-II standards, in order to combine one or more audio, video, or other basic data streams into one or more data streams for storage and transfer, it must be re-packaged and encoded. In the code stream, it also needs to insert various time tags, system control and other information, and finally sent to the channel encoding and modulation. In this way, two types of data streams, TS and PS, can be formed, which are suitable for different applications. Figure 1 shows the multiplexing of the video/audio data streams of a single program.

Transport Stream (TS Stream) is based on the ITU-T rec. h.222.0 | a data stream defined by the ISO/IEC 13818-2 and ISO/IEC 13818-3 protocols, the purpose is to transfer and store data encoded by one or more programs in the event of a serious error. This error is manifested in bits or group loss. A stream is composed of one or more programs. Each program is composed of one or more original streams and other streams, including video streams, audio streams, and special program information streams (PSI) and other data packets. The PSI table has four types: Program Association Table (PAT), program ing table (PMT), network information table, and conditional access table. Stream Transfer is widely used, such as storage of audio and video data, non-linear editing systems for TV programs, and their networks. When developing a set-top box or video device, you sometimes need to have a clear understanding of the code stream encoding knowledge so that you can make a comprehensive
Analysis.

TS Stream Structure Analysis

As shown in figure 2, the TS package length is fixed to 188 bytes. Including synchronous byte (sync_byte) 0x47 and packet identification id pid. The PID is a 13-bit field that indicates the type of data stored in the group payload. The PID value 0x0000 indicates that the program associated table is retained, the 0x0001 indicates that the conditional access table is retained, and the 0x1fff indicates that the group is retained. The PID can determine whether the data type behind the load is video stream, audio stream, PSI or other data packets.

PSI description

Program-specific information (PSI) is defined in the MPEG-II, PSI is used to describe the composition of a stream, and plays an extremely important role in the MPEG-II system, in multiplexing, Pat and PMT tables are particularly important. The Pat table shows the number of programs in a MPEG-II code stream and the relationship between the program and the PMT table PID; the PMT table shows the relationship between the specific components of a set of programs and their video, audio, and other PID values. PSI provides information that can be automatically configured by the receiver for decoding and decoding different program streams in the multiplexing stream. PSI information consists of the following types of tables:

◆ Program Association Table (Pat program Association table)

The Pat table is indicated by the PID (00) specified by MPEG, which is usually expressed by PID = 0. Its main function is to provide the locations of programs, program numbers, and program ing tables (PMT) contained in the transmission streams for each multiplexing transmission stream, that is, the value of the Packet Identifier (PID) of the TS packet of the PMT, and the position of the network information table (NIT), that is, the value of the Packet Identifier (PID) of the TS packet of the nit.

◆ Cat Conditional Access Table)

The cat table is indicated by the PID (01) specified by MPEG, which is usually expressed by PID = 1. It provides information about the conditional Receiving System in the multiplexing stream, specifying the connection between the CA system and their corresponding authorization management information (EMM), and specifying the PID of EMM, and related parameters.

◆ Program ing table (PMT program map table)

The program ing table specifies the content of the program, that is, the streams that constitute the program, the types of these streams (audio, video, and data), and the position of the streams that constitute the program, that is, the PID value of the corresponding ts package, the position of the program clock reference (PCR) field of each program.

◆ Nit nerwork information table)

The network information table provides information about multiple sets of transmission streams and transmission networks, including transmission stream descriptors, channel frequencies, satellite transmitter numbers, modulation characteristics, and other information.

◆ Transmission stream description table (tsdt transport stream description table)

The transmission stream description table is transmitted by a TS packet whose PID is 2. It provides some main parameters for the transmission stream.

◆ Private section (private_section)

The MPEG-2 also defines a dedicated segment for transferring private data defined by the user.

◆ Descriptor (descripter)

In addition to the above expressions, MPEG-2 also defines many descriptors that provide information about video streams, audio streams, languages, layers, system clock, bit rates, and other aspects, in the PSI table, you can flexibly use these descriptors to further provide more information to the receiver.

During decoding, the receiver first finds the Pat table based on the PID value, finds the PID of the PMT table of the corresponding program, finds the PMT table by the PID, and then finds the corresponding code stream in the PMT table, then start decoding. Example 3 shows the relationship between the PSI structure and the TS stream.

PES package format description

The digital stream compressed by video and audio is called the es stream, and the es stream is output by the packer. The PES package is non-fixed-length. The audio PES package consists of no more than 64 KB. A video generally has one frame and one PES package. To achieve decoding synchronization, you also need to insert the relevant flag information. After multiple packaged digital streams are combined into a transfer stream (TS Stream), the structure of the PES package is shown in Figure 4.

Analysis of intercepted ts code stream in MPEG-II

Analysis of intercepted code streams containing PSI Information

Code stream 5 that contains PSI information captured from the MPEG-II TS stream source.

The search for ts data streams starts with the synchronization character 0x47 in the packet. Because the synchronization header is not unique, the data packet may have a codeword or its value. Therefore, to accurately detect synchronization, you must first find the first 0x47 in the input buffer, then push its pointer back to the position of 187 bytes, and then check whether it is 0x47, if yes, the packet synchronization signal is output. The packet synchronization signal is detected every 187 bytes. If yes, the packet synchronization signal is returned. If no, the system searches for 0x47 again.

The code stream that contains PSI information intercepted in the previous section is the starting data of a TS file. The ts header in the TS Stream file starts with 0x47, and the 3 bytes after 0x47 are the TS header information: 4 In 0x40 indicates that the payload_unit_start_indicator is 1, indicating that the first valid byte containing the TS Stream group contains the point_field field, which occupies one byte; the ID is 0x00, this indicates that the TS Stream contains PSI information, which is a pat packet. 1 In 0x1c indicates that only additional information is not included, and only valid load is contained. C indicates that continuity _ counter = C. After the 4-byte ts header, one-byte point_field = 0, followed by program_association _
Section () field information. Table_id = 0x00 indicates that the PSI content here is the information content of the program _ association_section () field; 0xb0 indicates that B is the synchronization header and Reserved Bit, and 0 is part of section_length; section_length = 0x00d (contains the first 0 of 0x0d); Transport _ stream _ id = 0x0000; 0xc1 contains reserved bits, vision_number, current _ next_indicator, and 11 in C is reserved bits, in C, the first three digits of 00 and 4 lower digits are vision_number, and the second digit is current_next_indicator.

Vision_number = 0x00; current_next_indicator = 1, indicating that the sent Pat table is currently valid; ection_number = 0x00, last _ section_number = 0x0000; program_number = 0x0001; in 0xe0, the third digit of E is the reserved digit. The second digit of E is the content of the program_map_pid field, and the last four digits are the values of program_map_pid. Therefore, program_map_pid = 0x032, that is, pmt pid is 0x32; CRC is 0xbcf11595. The 0xff value is the padding byte.

In the second TS stream, the 3 bytes after 0x47 are ts header information: 4 in 0x40 indicates that the payload_unit_start_indicator is 1, indicating that the first valid byte containing the TS Stream group contains the point_field field, occupies one byte. The ID is 0x32, indicating that the TS Stream contains the PSI Information PID 0x032, which is the PID in the Pat table, indicating that the TS Stream contains the PMT table information. Point_field = 0x00, (TS header and point_field1 are 5 bytes in total) after point_field is 0x02, the PID here is ts_program _
Map_section () field. 0xb0 indicates that B is the synchronization header and Reserved Bit, 0 is a part of section_length, section_length = 0x02d, specifies the number of bytes of this field, including the CRC part; program_number = 0x0001; 0xc1 contains reserved bits, vision_number, current_next_indicator, 11 in C is reserved bits, 00 in C and the first 3 in the 4 lower bits are vision_number, and the hidden bits are current_next_indicator; version_number = 0x0, current_next_indicator = 1, section_number = 0x00, last_section_number = 0x00; the third digit of E in 0xe0 is reserved, the forward bit of E, the last four digits 0, and the last eight digits are the content of the pcr_pid field. pcr_pid = 0x020; the 4-digit high in the later 0xf0 is the Reserved Bit, the four low bits and the last eight bits are the content of the program_info_length field, which indicates the number of bytes in the description field, program_info_length = 0x000, and stream_type = 0x03, which indicates that the subsequent PID is ISO/IEC.
11172 the PID of the audio data. The third digit of E in 0xe0 is the reserved digit, and the third digit of E is the element_pid field content, element_pid = 0x021, indicating that if the TS Stream contains the audio part, the PID of the TS stream is 0x21; the 4-bit height in 0xf0 is the Reserved Bit, the four lower bits and the last eight bits are the content of the es_info_length field, indicating the number of bytes of the description field. es_info_length = 0x006, the next six bytes are the description of the original stream. Stream_type = 0x02 after 6 bytes, indicating that the PID after it is ITU-T rec.
H.262 | PID of the ISO/IEC 13818-2 video data; the third digit of E in 0xe0 is reserved, E and the last 4 digits 0 and the last 8 digits are the content of the element_pid field. element_pid = 0x20 indicates that if the TS Stream contains the video part, the PID of the TS stream is 0x20, and the 4-bit high in 0xf0 is the Reserved Bit. The 4-bit low and the 8-bit later are the content of the es_info_length field, the number of bytes in the description field. es_info_length = 0x10 indicates that the last 16 bytes are the description of the original stream. The last 4 bytes are the CRC verification part, followed by the padding part.

Analysis of TS code stream in general MPEG-II

Code stream 6 captured from the MPEG-II TS stream source.

As shown in the code stream intercepted above: the TS header starts with 0x47, and the 3 bytes after 0x47 are ts header information: ID is the video ID, 0x20, field_point field 00, followed by the PES packet header: 00 01 E0 indicates the video PES packet header. The subsequent frame information is 5 bytes in total, and the 2-byte PES packet length is 27 6a, it indicates that the length of the PES data packet is 0x276a, that is, 10090 bytes. The 2-byte standard bit information is 85, and the last byte in the 5 bytes indicates that the length of the additional data is 0b, followed by the formal video data: the start value is 00 00 01 00, indicating that I, B, and P frames are identified on 9d, And the binary value is 10.
In 011 101, the middle 3 011 indicates what frame is like. In this example, 011 is the B frame. When 001 is the I frame and 010 is the P frame.

In a sense, the development of digital TV mainly depends on the development of digital compression technology and digital modulation and demodulation technology. At present, the MPEG-2 standard is more mature, although the bit rate compression method many, such as MPEG series (MPEG-1, MPEG-2, MPEG-4, MPEG-7) and wavelet compression technology. However, in practical aspects, MPEG-2 has been in the front, and follow the standard developed system products have been very mature, the actual business operations and results are also very successful.

In short, MPEG-II transmission stream has been widely used in digital television systems, in the application can be obtained through the analysis of the code stream of the transmission stream PID, PRC and other information, used to set decoder and other useful.

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.