网上的代码多数是从本地h264文件中解析nalu数据,
如果想要处理从x264编码器中出来的实时流数据,可以这样做:
// 定义NALU单元
typedef struct _NaluUnit
{ int type;
int size;
unsigned char *data;
}NaluUnit;
用法:
//
int SendH264Buff( unsigned char *data,unsigned int size)
{
NaluUnit naluUnit;
int nOffset = 0;
int nPos =0;
while(1)
{
nPos = ReadOneNaluFromBuf(naluUnit, data + nOffset, size);
nOffset += nPos;
int bKeyframe = (naluUnit.type == 0x05) ? TRUE : FALSE;
SendH264Packet(naluUnit.data,naluUnit.size,bKeyframe,tick);
if (nOffset>=size)
break;
}
return 0;
}