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一起配合,解決視音頻同步播放的問題。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章