PES包格式:
分組開始碼前綴:0x00 0x00 0x01
流ID:視頻爲0x0E,音頻爲0x0C
PES分組長度:這個包中此後數據的長度,包括此後剩餘的PES包頭長度和幀數據長度。
PES首部數據長度:可選字段長度+填充字節長度。
其中PTS/DTS標誌位的意義爲:
0x01:表示pes包頭長度後面跟一個DTS數據(一個DTS或PTS的長度爲5個字節。)
0x02:表示pes包頭長度後面跟一個PTS數據
0x03:表示pes包頭長度後面跟一個PTS數據和一個DTS數據。
代碼:
pes_head_buf[7] = (0x2<<(8-2));
另外,數據流識別那個字節,一般爲
#define PES_AUD_STREAM_ID 0xc0
#define PES_VID_STREAM_ID 0xe0
其他參數值見下:
pts共33bit,在PES中佔5個字節,具體格式見下:
'0011' 4 bslbf
PTS [32..30] 3 bslbf
marker_bit 1 bslbf
PTS [29..15] 15 bslbf
marker_bit 1 bslbf
PTS [14..0] 15 bslbf
marker_bit 1 bslbf
代碼如下
unsigned long GetPts(unsigned char *buf)
{
unsigned char ptsflag;
unsigned char peshdr_datalen;
int index = 0;
unsigned short pktlen = MKWORD(buf[index], buf[index+1]);
index += sizeof(unsigned short);
index ++;
ptsflag = (buf[index] & 0xc0) >> 6;
index ++;
peshdr_datalen = buf[index++];
if (ptsflag & 0x2)
{
unsigned long pts;
unsigned short pts29_15, pts14_0;
unsigned long pts32_30 = (buf[index] & 0x0e) >> 1;
index++;
pts29_15 = MKWORD(buf[index], buf[index+1] & 0xfe) >> 1;
index += 2;
pts14_0 = MKWORD(buf[index], buf[index+1] & 0xfe) >> 1;
pts = (pts32_30 << 30) | (pts29_15 << 15) | pts14_0;
//pts = pts / 90000;
return pts;
}
return 0;
}