代码拉取完成,页面将自动刷新
#include "h264_nalu.h"
int getOneH264Nalu(FILE *fp, uint8_t *pNaluData, T_NaluInfo *ptNaluInfo)
{
uint32_t readBytes = 0;
uint32_t pos = 0;
if(!fp || !pNaluData || !ptNaluInfo)
return -1;
if((readBytes = fread(pNaluData, 1, 4, fp)) <= 0)
return -2;
// judge the type of NALU start code
if(pNaluData[0] == 0 && pNaluData[1] == 0 && pNaluData[2] == 0 && pNaluData[3] == 1)
{
pos = 4; // start by pNaluData[4]
ptNaluInfo->startcode_len = 4;
}
else if(pNaluData[0] == 0 && pNaluData[1] == 0 && pNaluData[2] == 1)
{
pos = 3;
ptNaluInfo->startcode_len = 3;
fseek(fp, -1, SEEK_CUR); // if start code type is 3, need to adapt point
}
else
return -3;
// find next NALU
while(1)
{
int val = 0;
if((val = fgetc(fp)) != EOF)
{
pNaluData[pos] = (unsigned char)val;
}
else
{
// file end,pos should not add 1 in last loop
pos -= 1;
break;
}
/* judge the start code type of "00 00 00 01" or "00 00 01",
* and must judge the "00 00 00 01", as it include the position of "00 00 01"
*/
if(pNaluData[pos-3] == 0 && pNaluData[pos-2] == 0 && pNaluData[pos-1] == 0 && pNaluData[pos] == 1)
{
fseek(fp, -4, SEEK_CUR);
pos -= 4;
break;
}
else if(pNaluData[pos-2] == 0 && pNaluData[pos-1] == 0 && pNaluData[pos] == 1)
{
fseek(fp, -3, SEEK_CUR);
pos -= 3;
break;
}
pos++;
}
// NALU length = array index + 1
ptNaluInfo->data_len = pos+1;
ptNaluInfo->nalu_type = pNaluData[ptNaluInfo->startcode_len] & 0x1F;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。