现在的位置: 首页 > 综合 > 正文

多节目的解复用和再复用之二——读取本地TS流文件

2013年10月16日 ⁄ 综合 ⁄ 共 1399字 ⁄ 字号 评论关闭

直接上代码,内有详细注释:

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include "stdlib.h"
#include "string"
#include "fstream"
#include "DeclaredFile.h"

using namespace std;

//////////////////////////////////////////////////////////////////////////
//读取本地TS文件
void ReadAnyFile()
{
	cout<<"请输入要读取的文件的地址......"<<endl;
	char buf[200];
	cin.get(buf, 200);

	FILE *file=NULL;
	unsigned char *pBuffer;
	unsigned long int iFileSize=0;
	if ((file = fopen(buf, "rb")))
	{
		cout<<"文件读取成功"<<endl;

		fseek(file ,0L, SEEK_END);
		iFileSize = ftell(file);
		cout<<"该文件的大小为:"<<iFileSize<<" 字节"<<endl;

		pBuffer=(unsigned char*)malloc(iFileSize);
		fseek(file,0,SEEK_SET);
		fread(pBuffer,iFileSize,1,file);
		fclose(file);			
	} 
	else
	{
		cout<<"文件读取失败"<<endl;
		fclose(file);
	}

	//free(pBuffer);
	//if (pBuffer==NULL)
	//{
	//	cout<<"内存释放成功"<<endl;
	//}
	//////////////////////////////////////////////////////////////////////////
	//打印部分字符
	cout<<endl<<"是否打印部分字符: Y/N "<<endl;
	char c1;
	cin>>c1;
	if (c1=='Y'||c1=='y')
	{
		cout<<"//////////////////////////////////////////////////////////////////////////"<<endl;
		cout<<"文件前400字节的十六进制形式如下............."<<endl;
		for(int j=0;j<400;j++)
		{
			printf("[0x%x]=0x%x ",j,pBuffer[j]);
			if ((j+1)%4==0)
			{
				cout<<endl;
			}
		}
	}


	//////////////////////////////////////////////////////////////////////////
	//提取TS流中的PSI信息
	cout<<endl<<"输入A或a提取TS流信息"<<endl;
	char c2;
	cin>>c2;
	if ((c2=='a')||(c2=='A'))
	{
		cout<<"//////////////////////////////////////////////////////////////////////////"<<endl;
		GetMptsPat(pBuffer,iFileSize);
	}
	cout<<endl;
}

抱歉!评论已关闭.