Transport stream (TS) is a standard format for transmission and storage of audio, video, and data, and is used in broadcast systems such as DVB and ATSC.

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).

Transport stream specifies a container format encapsulating packetized elementary streams, with error correction and stream synchronization features for maintaining transmission integrity when the signal is degraded.

The connection of Transport Stream to Program Stream is as follows. Firstly, PS is designed for reasonably reliable media, such as disks (like DVDs), while TS is designed for less reliable transmission, namely broadcast. Further, Transport Stream transmissions may carry multiple Program Streams.


Layers of communication

Similar to the OSI network protocol stack, a transport stream is processed by the receiver in layers.

An example stream containing video may be processed as follows:
Composition of the various programs
Packetized Elementary Stream (PES)
Elementary stream (ES) — audio or video (the below is for video only)
Group of pictures (GOP) — providing random access points
Slice — preventing an error from being propagated through intra prediction
Macroblock—consisting of 6 to 12 DCT blocks
Encoding block or just block—a DCT encoding block, 8x8 pixels

4.JPG

1.png

2.png

3.JPG

1.bmp

mpeg-ts-header.gif

2.bmp

Important elements of a transport stream

Packet
A packet is the basic unit of data in a transport stream.
It consists of a sync byte, whose value is 0x47, followed by three one-bit flags and a 13-bit Packet Identifier (PID).
This is followed by a 4-bit continuity counter.
Additional optional transport fields, as signaled in the optional adaptation field, may follow.
The rest of the packet consists of payload.
Packets are 188 bytes in length, but the communication medium may add some error correction bytes to the packet.
ISDB-T and DVB-T/C/S uses 204 bytes and ATSC 8-VSB, 208 bytes as the size of emission packets (transport stream packet + FEC data).
ATSC transmission adds 20 bytes of Reed-Solomon forward error correction to create a packet that is 208 bytes long.
The 188-byte packet size was originally chosen for compatibility with ATM systems.














Partial Transport Stream Packet Format
NameNumber of bitsDescription
sync byte 8 0x47
Transport Error Indicator (TEI) 1 Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error
Payload Unit Start Indicator 1 1 means start of PES data or PSI otherwise zero only.
Transport Priority 1 1 means higher priority than other packets with the same PID.
PID 13 Packet ID
Scrambling control 2 '00' = Not scrambled.
The following per DVB spec:
'01' = Reserved for future use,
'10' = Scrambled with even key,
'11' = Scrambled with odd key
Adaptation field exist 2
01 = no adaptation fields, payload only
10 = adaptation field only
11 = adaptation field and payload
Continuity counter 4  
    Note: the total number of bits above is 32 and is called the transport stream 4-byte prefix.
Adaptation field 0 or more Depends on flags
Payload Data 0 or more Depends on flags

















Adaptation Field Format
NameNumber
of bits
Description
Adaptation Field Length 8 Number of bytes in the adaptation field immediately following this byte
Discontinuity indicator 1 Set to 1 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 to 1 if the PES packet in this TS packet starts a video/audio sequence
Elementary stream priority indicator 1 1 = higher priority
PCR flag 1 1 means adaptation field does contain a PCR field
OPCR flag 1 1 means adaptation field does contain a OPCR field
Splicing point flag 1 1 means presence of splice countdown field in adaptation field
Transport private data flag 1 1 means presence of private data bytes in adaptation field
Adaptation field extension flag 1 1 means presence of adaptation field extension
Below fields are optional variable Depends on flags
PCR 33+9 Program clock reference
OPCR 33+9 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 (may be negative)
stuffing bytes variable  



Packetized Elementary Stream (PES) is a specification in the MPEG-2 Part 1 (Systems) (ISO/IEC 13818-1) and ITU-T H.222.0 that defines carrying of elementary streams in packets within MPEG program stream and MPEG transport stream.
The elementary stream is packetized by encapsulating sequential data bytes from the elementary stream inside PES packet headers.
A typical method of transmitting elementary stream data from a video or audio encoder is to first create PES packets from the elementary stream data and then to encapsulate these PES packets inside Transport Stream (TS) packets or Program Stream (PS).
The TS packets can then be multiplexed and transmitted using broadcasting techniques, such as those used in an ATSC and DVB.
Transport Streams and Program Streams are each logically constructed from PES packets. PES packets shall be used to convert between Transport Streams and Program Streams.
In some cases the PES packets need not be modified when performing such conversions.
PES packets may be much larger than the size of a Transport Stream packet.









PES packet header
NameSizeDescription
Packet start code prefix 3 bytes 0x000001
Stream id 1 byte Examples: Audio streams (0xC0-0xDF), Video streams (0xE0-0xEF)
    Note: The above 4 bytes is called the 32 bit start code.
PES Packet length 2 bytes Can be zero.If the PES packet length is set to zero, the PES packet can be of any length. A value of zero for the PES packet length can be used only when the PES packet payload is a video elementary stream.
Optional PES header variable length  
Stuffing bytes variable length  
Data   See elementary stream. In the case of private streams the first byte of the payload is the sub-stream number.



















Optional PES header
NameNumber of BitsDescription
Marker bits 2 10 binary or 0x2 hex
Scrambling control 2 00 implies not scrambled
Priority 1  
Data alignment indicator 1 1 indicates that the PES packet header is immediately followed by the video start code or audio syncword
Copyright 1 1 implies copyrighted
Original or Copy 1 1 implies original
PTS DTS indicator 2 11 = both present, 10 = only PTS
ESCR flag 1  
ES rate flag 1  
DSM trick mode flag 1  
Additional copy info flag 1  
CRC flag 1  
extension flag 1  
PES header length 8 gives the length of the remainder of the PES header
Optional fields variable length presence is determined by flag bits above
Stuffing Bytes variable length 0xff




Packetized Elementary Stream Headers

Depending on the Stream ID, a Packetized Elementary Stream (PES) header may contain various components.

The header

byte 0byte 1byte 2byte 3byte 4byte 5
0000 0000 0000 0000 0000 0001
Start code
Stream ID PES packet length

Stream ID's which pertain to DVD

Stream IDStream typeextension present?
1011 1101
0xBD
Private stream 1 (non MPEG audio, subpictures) Yes
1011 1110
0xBE
Padding stream No
1011 1111
0xBF
Private stream 2 (navigation data) No
110x xxxx
0xC0 - 0xDF
MPEG-1 or MPEG-2 audio stream number x xxxx
note: DVD allows only 8 audio streams
Yes
1110 xxxx
0xE0 - 0xEF
MPEG-1 or MPEG-2 video stream number xxxx
note: DVD allows only 1 video stream
Yes

The extension

byte 6byte 7byte 8
765432107654321076543210
10 PES scrambling control PES priority data alignment indicator copyright original or copy PTS DTS flags ESCR flag ES rate flag DSM trick mode flag additional copy info flag PES CRC flag PES extension flag PES header data length

The bit fields of the basic extension:

PES scrambling control -- 00 = not scrambled, others are user defined.

PES priority -- provides 2 priority levels, 0 and 1.

data alignment indicator -- if set to 1 indicates that the PES packet header is immediately followed by the video start code or audio syncword.

copyright -- 1 = packet contains copyrighted material.

original or copy -- 1 = original, 0 = copy.

PTS DTS flags -- Presentation Time Stamp / Decode Time Stamp. 00 = no PTS or DTS data present, 01 is forbidden.
if set to 10 the following data is appended to the header data field:

7654321076543210765432107654321076543210
0010 PTS 32..30 1 PTS 29..15 1 PTS 14..00 1
PTS DTS flags -- if set to 11 the following data is appended to the header data field:
7654321076543210765432107654321076543210
0011 PTS 32..30 1 PTS 29..15 1 PTS 14..00 1
0001 DTS 32..30 1 DTS 29..15 1 DTS 14..00 1
presentation and decoder time stamps use the 90KHz clock (SCR / 300)

ESCR -- if set to 1 the following data is appended to the header data field:

765432107654321076543210765432107654321076543210
00 ESCR base 32..30 1 ESCR base 29..15 1 ESCR base 14..00 1 ESCR ext 1
This is the Elementary Stream Clock Reference, used if the stream and system levels are not synchronized (i.e. ESCR differs from SCR in the PACK header).

ES rate -- if set to 1 the following data is appended to the header data field:

765432107654321076543210
1 ES rate 1
The rate at which data is delivered for this stream, in units of 50 bytes/second.

DSM trick mode - not used by DVD

additional copy info -- if set to 1 the following data is appended to the header data field:

76543210
1 additional copy info

PES CRC flag -- if set to 1 the following data is appended to the header data field:

7654321076543210
previous PES packet CRC
The polynomial used is X16 + X12 + X5 + 1

PES extension flag -- if set to 1 the following data is appended to the header data field:

76543210
PES private data flag pack header field flag program packet sequence counter flag P-STD buffer flag 111 PES extension flag 2
The bit fields of the first extension:

PES private data flag -- if set to 1 16 bytes of user defined data is appended to the header data field.

pack header field flag -- if set to 1 the 8-bit pack field length value is appended to the header data field.

program packet sequence counter flag -- if set to 1 the following data is appended to the header data field:

7654321076543210
1 packet sequence counter 1 MPEG1_MPEG2 identifier original stuffing length

P-STD buffer flag -- if set to 1 the following data is appended to the header data field:

7654321076543210
01 P-STD buffer scale
0 = 128 bytes
1 = 1024 bytes
P-STD buffer size

PES extension flag 2 -- if set to 1 the following data is appended to the header data field:

7654321076543210
1 PES extension field length reserved
Which is then followed by the indicated number of bytes.

arrow
arrow
    全站熱搜

    BB 發表在 痞客邦 留言(0) 人氣()