PS流格式
概念:
將具有共同時間基準的一個或多個PES組合(復合)而成的單一的數據流稱為節目流(Program Stream)。
ES是直接從編碼器出來的數據流,可以是編碼過的視頻數據流,音頻數據流,或其他編碼數據流的統稱。ES流經過PES打包器之后,被轉換成PES包。
構成:
PS包由包頭、系統頭、PES包3部分構成。包頭由PS包起始碼、系統時鐘基準(SCR-System Clock Reference)的基本部分、SCR的擴展部分和PS復用速率4部分組成。
維基百科對應的圖表(包頭、系統頭):
字節順序,如下所示:
4B的包起始碼:
byte 0
byte 1
byte 2
byte 3
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
0000 0000 0000 0000 0000 0001
start code
1011 1010
PACK identifier
PACK identifier -- 0xBA
系統時鐘基準(SCR-System Clock Reference)的基本部分、SCR的擴展部分:
byte 4
byte 5
byte 6
byte 7
byte 8
byte 9
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
01
SCR 32..30
1
SCR 29..15
1
SCR 14..00
1
SCR_ext
1
PS復用速率:
byte 10
byte 11
byte 12
byte 13
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
Program_Mux_Rate
1
1
reserved
pack_stuffing_length
- SCR and SCR_ext together are the System Clock Reference, a counter driven at 27MHz, used as a reference to synchronize streams. The clock is divided by 除以300 (to match the 90KHz clocks such as PTS/DTS), the quotient 商 is SCR (33 bits), the remainder 余數 is SCR_ext (9 bits)
- Program_Mux_Rate -- This is a 22 bit integer specifying the rate at which the program stream target decoder receives the Program Stream during the pack in which it is included. The value of program_mux_rate is measured in units of 50 bytes/second. The value 0 is forbidden.
- pack_stuffing_length -- A 3 bit integer specifying the number of stuffing bytes which follow this field.
- stuffing byte -- This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder, for example to meet the requirements of the channel. It is discarded by the decoder.
兩個頭之后便是PES包(payload):
參考一段代碼理解:http://read.pudn.com/downloads104/sourcecode/multimedia/mpeg/427188/PESdecode/pesdecode.cpp__.htm
可以看到PTS/DTS(流識別碼,用于區別不同性質ES)是打在PES包里面的,這兩個參數是解決視音頻同步顯示,防止解碼器輸入緩存上溢或下溢的關鍵。PTS表示顯示單元出現在系統目標解碼器(STD: system target decoder)的時間,DTS表示將存取單元全部字節從STD的ES解碼緩存器移走的時刻。每個I、P、B幀的包頭都有一個PTS和DTS,但PTS與DTS對B幀都是一樣的,無須標出B幀的DTS。對I幀和P幀,顯示前一定要存儲于視頻解碼器的重新排序緩存器中,經過延遲(重新排序)后再顯示,一定要分別標明PTS和DTS。
關于音視頻的同步:
除了PTS和DTS的配合工作外,還有一個重要的參數是SCR(system clock reference)。在編碼的時候,PTS,DTS和SCR都是由STC(system time clock)生成的,在解碼時,STC會再生,并通過鎖相環路(PLL-phase lock loop),用本地SCR相位與輸入的瞬時SCR相位鎖相比較,以確定解碼過程是否同步,若不同步,則用這個瞬時SCR調整27MHz的本地時鐘頻率。最后,PTS,DTS和SCR一起配合,解決視音頻同步播放的問題。
RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成