#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "h264_rbsp.h"
#include "sps_parse.h"
#include "pps_parse.h"
#define SUCCESS 0
#define FAILURE ~0
#define RETRY 1 //return retry, value 1;
int substr(char* str, unsigned int start, unsigned int end,char * o_buf)
{
unsigned int n = end - start;
strncpy(o_buf, str + start, n);
o_buf[n] = '\0'; //字串最后加上0
return SUCCESS;
}
int sps_prase(char *i_sps,int sps_length)
{
if(!i_sps || sps_length<=0)
return FAILURE;
char rbspbuffer[512] ={0,};
rbsp spsrsbp(i_sps,sps_length,rbspbuffer,512);
int bufl = spsrsbp.torbsp();
sps tempsps((unsigned char *)rbspbuffer,bufl);
tempsps.sps_parse();
unsigned char frame_mbs_only_flag = tempsps.get_frame_mbs_only_flag();
unsigned int log2_max_frame_num_minus4 = tempsps.get_log2_max_frame_num_minus4();
unsigned int pic_order_cnt_type = tempsps.get_pic_order_cnt_type();
unsigned int num_units_in_tick = tempsps.get_num_units_in_tick();
unsigned int time_scale = tempsps.get_time_scale();
unsigned char separate_colour_plane_flag = tempsps.get_separate_colour_plane_flag();
unsigned int log2_max_pic_order_cnt_lsb_minus4 = tempsps.get_log2_max_pic_order_cnt_lsb_minus4();
printf("----------------------------------------------------------------\n");
printf("@@ frame_mbs_only_flag =%d \n",frame_mbs_only_flag);
printf("@@ log2_max_frame_num_minus4 =%d \n",log2_max_frame_num_minus4);
printf("@@ pic_order_cnt_type =%d \n",pic_order_cnt_type);
printf("@@ num_units_in_tick =%d \n",num_units_in_tick);
printf("@@ time_scale =%d \n",time_scale);
printf("@@ separate_colour_plane_flag =%d \n",separate_colour_plane_flag);
printf("@@ log2_max_pic_order_cnt_lsb_minus4 =%d \n",log2_max_pic_order_cnt_lsb_minus4);
printf("----------------------------------------------------------------\n");
}
int pps_prase(char *i_pps,int pps_length)
{
if(!i_pps || pps_length<=0)
return FAILURE;
char rbspbuffer[512] ={0,};
rbsp ppsrsbp(i_pps,pps_length,rbspbuffer,512);
int bufl = ppsrsbp.torbsp();
pps temppps((unsigned char *)rbspbuffer,bufl);
temppps.pps_parse();
}
int parame_prase(char *buf,int buflen)
{
if(!buf || buflen<=0)
return FAILURE;
int post =0;
printf("<><><><><><><><><><><>buflen=%d<><><><><><><><><><><><><><>\n",buflen);
int test =0;
for(test =post;test<buflen+post;test++)
{
printf("0x%02x ",buf[test]&0xff);
}
printf("\n");
printf("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>\n");
//configurationVersion
unsigned char configurationVersion = buf[post++] & 0xff ;
//AVCProfileIndication
unsigned char AVCProfileIndication = buf[post++] & 0xff ;
//profile_compatibility
unsigned char profile_compatibility = buf[post++] & 0xff ;
//AVCLevelIndication
unsigned char AVCLevelIndication = buf[post++] & 0xff ;
//lengthSizeMinusOne H.264 视频中 NALU 的长度,计算方法是 1 + (lengthSizeMinusOne & 3),实际测试时发现总为ff,计算结果为4,
unsigned char lengthSizeMinusOne = 1 + (buf[post++] & 3 );
//numOfSequenceParameterSets ,SPS 的个数,计算方法是 numOfSequenceParameterSets & 0x1F,实际测试时发现总为E1,计算结果为1
unsigned char numOfSequenceParameterSets = buf[post++] & 0x1f ;
//sequenceParameterSetLength ,SPS 的长度
unsigned char sequenceParameterSetLength = ((buf[post++] & 0xff)<<8|(buf[++post] & 0xff));
//sequenceParameterSetNALUnits ,sps
int sps_length = sequenceParameterSetLength;
printf("<><><><><><><><><><><>sps sps_length=%d<><><><><><><><><><><><><><>\n",sps_length);
for(test =post;test<sps_length+post;test++)
{
printf("0x%02x ",buf[test]&0xff);
}
printf("\n");
printf("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>\n");
char *sps = (char *)malloc(sps_length);
memset(sps,0x00,sps_length);
memcpy(sps,&buf[post],sps_length);
post += sps_length;
//解析sps
sps_prase(sps,sps_length);
//numOfPictureParameterSets ,PPS 的个数,计算方法是 numOfPictureParameterSets & 0x1F,实际测试时发现总为E1,计算结果为1
unsigned char numOfPictureParameterSets = buf[post++] & 0x1f ;
//pictureParameterSetLength ,PPS 的长度
unsigned char pictureParameterSetLength = ((buf[post++] & 0xff)<<8|(buf[++post] & 0xff));
//pps
int pps_length = pictureParameterSetLength;
char *pps = (char *)malloc(pps_length);
memset(pps,0x00,pps_length);
memcpy(pps,&buf[post],pps_length);
printf("<><><><><><><><><><><>pps pps_length=%d<><><><><><><><><><><><><><>\n",pps_length);
for(test =post;test<pps_length+post;test++)
{
printf("0x%02x ",buf[test]&0xff);
}
printf("\n");
printf("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>\n");
pps_prase(pps,pps_length);
if(sps)
free(sps);
if(pps)
free(pps);
}
int h264_prase(char *filename)
{
if(!filename)
return FAILURE;
FILE *fin =NULL;
fin = fopen(filename,"rb");
if (!fin)
{
perror("file open error ");
exit(1);
}
char *buf =NULL;
buf =(char *)malloc(sizeof(char)*512);
memset(buf,0,sizeof(char)*512);
int nb_read = fread(buf, sizeof(char), 512, fin);
if(nb_read<=0)
return FAILURE;
parame_prase(buf,nb_read);
if(buf)
free(buf);
}
int main(int argc, char **argv)
{
if(argc>1)
{
if(argv[1])
{
char *ptr =NULL;
char fileExt[256];
char filename[256];
sprintf(filename,"%s",argv[1]);
ptr = strrchr(filename+1,'.');
if(!ptr)
{
printf("ptr ==NULL\n");
return FAILURE;
}
int pos = ptr-filename;//用指针相减 求得索引
substr(filename+1,pos,strlen(filename)-1,fileExt);
if(!strcmp(fileExt,"h264")||!strcmp(fileExt,"H264"))
{
h264_prase(filename);
}
else
return FAILURE;
}
else
{
return FAILURE;
}
}
else
{
return FAILURE;
}
}
H264 sps pps解析
5星 · 超过95%的资源 需积分: 50 172 浏览量
2013-01-18
16:35:24
上传
评论 5
收藏 59KB RAR 举报
simon-扬
- 粉丝: 205
- 资源: 37
最新资源
- 全卷积网络基于voc2012数据集简单pytorch实现
- pycharm的一些介绍-用于更好的学习python
- 基于C++的程序设计大赛天梯赛L2答案(天梯赛)
- 基于python实现的三次样条插值和均值插值法实现
- Python语言教程2-python批量图片大小处理-多文件夹
- Python语言教程1-python批量图片重命名,将后缀某几个不想要的字去除
- Space Combat Kit 太空战斗套件Unity游戏开发插件资源unitypackage C#
- Universal Device Preview 通用设备预览Unity游戏开发插件资源unitypackage
- Paladin Anim Set 圣骑士动画集Unity游戏动作动画插件资源unitypackage
- 计算机财务管理期末考报表部分题目及答案.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页