ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:17.11KB ,
资源ID:11904870      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11904870.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(解析TS流PAT和PMT 代码.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

解析TS流PAT和PMT 代码.docx

1、解析TS流PAT和PMT 代码#include#include#include#define ts_path /home/huohuo/huangwork/work/birds.ts /TS文件的绝对路径void Read_Ts_Packet(FILE *file_handle,unsigned char *packet_buf,int len); /读一个TS流的packetint parse_TS(unsigned char *buffer,int FileSize); /分析TS流,并找出PAT的PID和PAT的tablevoid parse_PAT(unsigned char *buf

2、fer,int len); /分析PAT,并找出所含频道的数目和PMT的PIDvoid pronum_pmtid_printf(); /打印PMT的PIDunsigned char* Find_PMT(unsigned short pmt_pid); /找出PMT的tablevoid parse_PMT(unsigned char *buffer,int len,unsigned short pmt_pid); /解析PMT,找出其中的Video和Audio的PIDvoid printf_program_list(); /打印PMT table中包含的stream的类型和PIDunsigned

3、 char* Find_video_audio(unsigned short program_pid,unsigned char type); /找出Video或者Audio的tabletypedef struct unsigned short program_num; /programs num unsigned short pmt_pid; /PROGRAM;typedef struct unsigned char stream_type; unsigned short elementary_pid;PRO_LIST;PROGRAM programs10 = 0,0; /用来存储PMT的P

4、ID和数量unsigned int num = 0; /total programPRO_LIST program_list10 = 0,0; /用来存储PMT中stream的类型和PIDunsigned int program_list_num = 0;FILE *file_handle; /指向TS流的指针unsigned int FileSize = 0;int main() unsigned char buffer188 = 0; unsigned char *pmt_buffer, *Video_or_Audio_buffer; unsigned int i=0,j=0,ret=0;

5、 pmt_buffer = (unsigned char*)malloc(sizeof(char)*188); /给buffer分配空间 memset(pmt_buffer,0,sizeof(char)*188); /清空buffer Video_or_Audio_buffer = (unsigned char*)malloc(sizeof(char)*188); memset(Video_or_Audio_buffer,0,sizeof(char)*188); file_handle = fopen(ts_path,rb+); /以二进制方式打开TS文件 if(NULL = file_han

6、dle) /判断是否打开文件 perror(fopen); printf(open file error!n); return 0; else printf(open file success!n); fseek(file_handle,0,SEEK_END); /指针file_handle将以SEEK_END位置偏移0个位置,即将指针移动到文件尾 FileSize = ftell(file_handle); / 计算file_handle到文件头的偏移字节数,即计算文件的大小 printf(file size = %dn,FileSize); rewind(file_handle); / e

7、quivalent (void) feek(file_handle,0L,SEEK_SET) 将file_handle指针移动到文件头位置 printf(find PAT begin-n); for(i=0;in); for(i=0;in); for(j=0;jn); for(i=0;in); for(j=0;j188;j+) printf(0x%x ,Video_or_Audio_bufferj); /打印elementarys table memset(Video_or_Audio_buffer,0,sizeof(char)*188); printf(n); free(pmt_buffer

8、); free(Video_or_Audio_buffer); pmt_buffer = NULL; Video_or_Audio_buffer = NULL; fclose(file_handle); printf(n); return 1; /* * read one TS packets data * */void Read_Ts_Packet(FILE *file_handle,unsigned char *packet_buf,int len) fread(packet_buf,188,1,file_handle);int parse_TS(unsigned char *buffer

9、,int FileSize) unsigned char *temp = buffer; short pat_pid; int i = 0; if(buffer0 != 0x47) printf(its not a ts packet!n); return 0; while(temp buffer + FileSize) pat_pid = (temp1 & 0x1f)n); for(i=0;i=187;i+) printf(0x%x ,bufferi); printf(n); return 1; temp = temp + 188; return 0;/* * parse PAT table

10、, get the PMTs PID * */void parse_PAT(unsigned char *buffer,int len) unsigned char *temp, *p; char adaptation_control; int adaptation_length,i=0; unsigned short section_length,prg_No,PMT_Pid; temp = buffer; adaptation_control = temp3 & 0x30; if(adaptation_control = 0x10) temp = buffer + 4 + 1; else

11、if (adaptation_control = 0x30) adaptation_length = buffer4; temp = buffer + 4 + 1 +adaptation_length + 1; else return ; section_length = (temp1&0x0f)8 | temp2; p = temp + 1 +section_length; temp = temp + 8; while(temp p - 4) prg_No = (temp08) | (temp1); if(prg_No = 0) temp = temp + 4; continue; else

12、 PMT_Pid = (temp2&0x1f)8 | temp3; programsnum.program_num = prg_No; programsnum.pmt_pid = PMT_Pid;/ printf(pmt_pid is ox%xn, PMT_Pid); num +; temp = temp + 4; void pronum_pmtid_printf() unsigned int i; printf(PAT tables program_num and PMTs PID:n); for(i=0;inum;i+) printf(program_num = 0x%x (%d),PMT

13、_Pid = 0x%x (%d)n, programsi.program_num,programsi.program_num, programsi.pmt_pid,programsi.pmt_pid); void printf_program_list() unsigned int i; printf(All PMT Tables program list: n); for(i=0;iprogram_list_num;i+) printf(stream_type = 0x%x, elementary_pid = 0x%xn,program_listi.stream_type,program_l

14、isti.elementary_pid); printf(n);unsigned char* Find_PMT(unsigned short pmt_pid) unsigned int i=0,j=0; int pid; unsigned char *buffer; buffer = (unsigned char *)malloc(sizeof(char)*188); memset(buffer,0,sizeof(char)*188); rewind(file_handle); for(j=0;jFileSize/188;j+) Read_Ts_Packet(file_handle,buffe

15、r,188); if(buffer0 != 0x47) printf(Its not TS packet !n); else pid = (buffer1 & 0x1f) 8 | buffer2; if(pid = pmt_pid) printf(PMT Table already find!n); return buffer; else printf(finding PMT table.n); unsigned char* Find_video_audio(unsigned short program_pid,unsigned char type) unsigned int i = 0, j

16、 = 0 ; int pid; unsigned char *buffer; buffer = (unsigned char *)malloc(sizeof(char)*188); memset(buffer,0,sizeof(char)*188); rewind(file_handle); for(j=0;jFileSize/188;j+) Read_Ts_Packet(file_handle,buffer,188); if(buffer0 != 0x47) printf(Its not TS packet !n); else pid = (buffer1 & 0x1f) 8 | buffe

17、r2; if(program_pid = pid) if(type = 0x02) printf(Find a program and this program is Video type!n); else if(type = 0x03) printf(Find a program and this program is Audio type!n); else printf(Find a program but this program is other type !n); return buffer; else printf(finding Video or Audio table.n );

18、 void parse_PMT(unsigned char *buffer,int len,unsigned short pmt_pid) unsigned char *temp, *p; char adaptation_control; int adaptation_length,i=0; int program_info_length; int ES_info_length; unsigned short section_length,pid; temp = buffer; adaptation_control = temp3 & 0x30; if(adaptation_control =

19、 0x10) temp = buffer + 4 +1; else if (adaptation_control = 0x30) adaptation_length = buffer4; temp = buffer + 5 + adaptation_length + 1; else return; section_length = (temp1&0x0f)8 | temp2; p = temp + 1 + section_length;/ temp = temp + 10; program_info_length = (temp10 & 0x0f) 8 | temp11; temp = temp + 12 + program_info_length ; for(;temp p - 4;) program_listprogram_list_num.stream_type = temp0, program_listprogram_list_num.elementary_pid = (temp1&0x1f) 8 | temp2; ES_info_length = (temp3&0x0f) 8 | temp4; temp = temp + 4 + ES_info_length + 1; program_list_num + ;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1