H264 frames are separated by a special tag called the initial code prefix, which has the value 0x00 0x00 0x01 OR 0x00 0x00 0x00 0x01 . All data between the two start codes includes a NAL block in H264. So what you want to do is search for the start code prefix in the h264 stream. The byte following the initial code prefix is the NAL header . The lowest 5 bits of the NAL header will give you the type of NAL unit. If nal_unit_type = 5, then this NAL block is the reference frame.
Something like that:
void h264_find_IDR_frame(char *buf)
{
while(1)
{
if (buf[0]==0x00 && buf[1]==0x00 && buf[2]==0x01)
{
if(buf[3] & 0x1F == 0x5)
{
}
break;
}
else if (buf[0]==0x00 && buf[1]==0x00 && buf[2]==0x00 && buf[3]==0x01)
{
if(buf[4] & 0x1F == 0x5)
{
}
break;
}
buf++;
}
}
source
share