TS流中從流解析出段和表詳細資訊

2021-06-23 01:27:22 字數 3634 閱讀 6683

ts流頭部資訊:

typedef struct ts_header

ts_header;

在解析ts流時要注意

1.transport_error_indicator欄位是否為1,這是個錯誤標識字段,如果為1,則表明接下來的這個段在傳輸過程中出現錯誤,解析時可以跳過這個段。

2.payload_unit_start_indicator欄位表明後面是否有個檔案指標,用來表明有效負載的。如果有則表明這個包是這個段的起始包,有效負載的開始位置在調整字段後面有個檔案指標來指定。這是判斷乙個段開始的唯一標識。

3.adaption_field_control欄位表明為控制調整字段,解析時,只要解析為01和10的包,因為其他的包裡面沒有有效字段,可以不解析。調整欄位是在頭部8位元組結束後的第乙個位元組(如果有調整字段)也就是第9個字段,這個字段數字表明從第10個字段開始及後面欄位為調整字段。所有調整欄位後的那個欄位為檔案指標(如果有檔案指標即有效標識為1),指定正真的有效字段的開始位置。

下面為相應**:

#include#include#include#include#include//ts流的頭部4個位元組字段

typedef struct ts_header

tsheader;

//網路資訊表nit

typedef struct networksection

networksection;

//網路描述

//only cx descriptor tag = 0x44

typedef struct descriptoy

netdescriptor;

//第二個for迴圈字段

typedef struct floop

floop;

//函式前置宣告

int read_file(int fd, int len, char buff [ ]);

int lseek_file(int fd, int len);

int close_file(int fd);

int adjust_ts_header(int fd);

int tssection(int len, unsigned char tssheader [ ], tsheader sheader);

int floop_descriptoy(int count, int length);

int descriptoy_cx(int count, int length);

void printfsection(int counter);

//開啟檔案

int open_file(char *url)

return fd;

}//讀取檔案

int read_file(int fd,int len,char buff)

lseek_file(fd,len);

return 0;

}//游標定位

int lseek_file(int fd,int len)

return 0;

}//關閉檔案

int close_file(int fd)

fd = -1;

return 0;

}//讀取ts流包的頭部

int adjust_ts_header(int fd)

;if(0 > read_file(fd,len,tsheadbuff))

return -1;

tsheader ts_header;

ts_header.sync_byte = tsheadbuff[0]; // :8;

ts_header.transport_error_indicator = tsheadbuff[1] >> 7;// :1;

ts_header.payload_unit_start_indicator = ((tsheadbuff[1] >> 6) & 0x01);// :1;

ts_header.transport_priority = ((tsheadbuff[1] >> 5) & 0x01);// : 1;

ts_header.pid = ((tsheadbuff[1] & 0x1f) << 8 ) | tsheadbuff[2];// :13;

ts_header.transport_scrambling_control = (tsheadbuff[3] >> 6);// :2;

ts_header.adaption_field_control = ((tsheadbuff[3] >> 4) & 0x03);// :2;

ts_header.continuity_counter = (tsheadbuff[3] & 0x0f);// : 4;

static int counter_pusi = 0;

//過濾pid為0x10的包,和有有效負載的包

if( (0x10 == ts_header.pid)&&((ts_header.adaption_field_control & 0x1) == 0x1)&&(ts_header.transport_error_indicator != 0x1) )

}adjust_ts_header(fd);

}static unsigned char sectionbuff[1024] = ;

//把各個ts 包 合成段

int tssection(int len,unsigned char tssheader,tsheader sheader)

counter_sect = counter_sect+ sheader.payload_unit_start_indicator;

//去除調整字段

int counter_adjust = 0;

if(0x11 == sheader.adaption_field_control)

//段開始的有效負載起始標誌

if(0x1 == sheader.payload_unit_start_indicator)

int i = 0;

for(;i < (184 - counter_adjust);i++ )

printf("\n\n");

counter_byte = counter_byte + (184 - counter_adjust);

return 1;//表示還沒有完成段的拼接

}//列印整個段的資訊

void printfsection(int counter)

//第二個迴圈解析

int floop_descriptoy(int count,int length)

return count;

}//網路描述

int descriptoy_cx(int count,int length)

printf("\n");

length = length - (2+tmp);

}return count;

}int main()

adjust_ts_header(fd);

return 0;

}

文章及**皆為原創,且**經過測試完全正確。

TS流中的音訊EB size

音訊的eb size對於不同的編碼型別有不同的固定值 define tsmux mp2 es buffer size 3584 define tsmux ac3 es buffer size 3584 define tsmux eac3 es buffer size 5184 define tsmu...

如何從TS流中找到OC資料

如何從ts流中找到oc資料 oc dsm cc object carousel 是將 物件結構 從廣播伺服器傳輸到客戶端的一種傳輸機制。oc object主要包括 1 directory objects 資料夾 2 file objects 檔案 3 stream objects.流檔案 不常用 o...

CMMB中的H264和AAC打包成ts流

cmmb中的h264和aac打包成ts流 南冠彤參照tstools這個開源專案完成了cmmb的merge aac with 264 to ts.在做的過程中,分成了幾個階段。先試著將h264打包成ts,這花了最大的精力和時間 接著將aac打包成ts 最後將其合併起來。一 處理h264 1 h264 ...