FLV文件分析 --2(提取h264数据)


首先得跳过 9字节的FLV文件头,然后在分析tag头 (11 字节)确定是否为视频 tag.   09:视频  08:音频


00 00 2D: tag data size:(并不全是h264裸流,还有些一下其他信息)

蓝色部分即为 tag data 区:

第一个字节分析 : 17   --视频格式信息

		c=fgetc(myopen);
		video_type=(c&0xf0);
		video_type =video_type>>4;

		switch(video_type){
			case 1:strcat(str,"key frame  ");break;
			case 2:strcat(str,"inter frame");break;
			case 3:strcat(str,"disposable inter frame");break;
			case 4:strcat(str,"generated keyframe");break;
			case 5:strcat(str,"video info/command frame");break;
			default:strcat(str,"UNKNOWN");break;
		}
		video_type=(c&0x0f);
		strcat(str,"| ");
		switch (video_type)
			{
				case 1:strcat(str,"JPEG (currently unused)");break;
				case 2:strcat(str,"Sorenson H.263");break;
				case 3:strcat(str,"Screen video");break;
				case 4:strcat(str,"On2 VP6");break;
				case 5:strcat(str,"On2 VP6 with alpha channel");break;
				case 6:strcat(str,"Screen video version 2");break;
				case 7:strcat(str,"AVC");break;
				default:strcat(str,"UNKNOWN");break;
			}
提取 h264代码:

void H264JIEXI(int datelength)//关键
{
	int info = 0;
	Read8(info, flvfile);         //     17
	int avctype = 0;
	Read8(avctype, flvfile); 	//第一个视频关键帧  tag :00
	FSEEK(3, flvfile);		// 跳过之后  3字节	
	int templength = 0;
	char*tempbuff = NULL;
	if (avctype == 0)		// 提取 sps  pps
	{
		FSEEK(6, flvfile);	// 后移6

		Read16(templength, flvfile);   // 读取 sps 长度  --2字节
		printf("sssize:%d\n", templength);

		tempbuff = (char*)malloc(templength);
		fread(tempbuff, 1, templength, flvfile);  //读sps
		fwrite(&h264space, 1, 4, h264file);		//nal 头  00 00 00 01
		fwrite(tempbuff, 1, templength, h264file);
		free(tempbuff);

		Read8(templength, flvfile);//ppsnum     // 读pps 个数

		Read16(templength, flvfile);//ppssize  // 读pps 长度  ----2字节
		printf("ppsize:%d\n", templength);

		tempbuff = (char*)malloc(templength);
		fread(tempbuff, 1, templength, flvfile);
		fwrite(&h264space, 1, 4, h264file);
		fwrite(tempbuff, 1, templength, h264file);
		free(tempbuff);
	}
	else     
	{
		//	Read32(templength,flvfile);
		//	tempbuff=(char*)malloc(templength);
		//	fread(tempbuff,1,templength,flvfile);
		//	fwrite(&h264space,1,4,h264file);
		//	fwrite(tempbuff,1,templength,h264file);
		//	free(tempbuff);
		//可能存在多个nal,需全部读取
		int countsize = 2 + 3;
		static int gg = 0;
		while (countsize < datelength)			
		{
			Read32(templength, flvfile);             //   四个字节长度      
			tempbuff = (char*)malloc(templength);
			printf("templength =%d\n", templength);
			fread(tempbuff, 1, templength, flvfile);
			fwrite(&h264space, 1, 4, h264file);
			fwrite(tempbuff, 1, templength, h264file);
			free(tempbuff);
			countsize += (templength + 4);
			
		}
	}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值