I'm looking for a algorithm of finding reference frames in h264 stream. The most common metod I saw in different solutions was finding access unit delimiters and NAL of IDR type. Unfortunatelly most streams I checked didn't have NAL of IDR type. I'll be gratefull for help. Regards Jacek
Answer 1:
H264帧拆分这家由特殊的标记,称为起始码前缀,或者是为0x00为0x00 0×01或0×00 0×00 0×00 0×01。 所有2个起始码之间的数据包括在H264讲NAL单元。 所以,你想要做的是寻找你的h264码流的起始码前缀。 继起始码前缀字节立即NAL报头 。 NAL报头的最低5位会给你NAL单元类型。 如果nal_unit_type等于5,则该特定NAL单元为参考帧。
事情是这样的:
void h264_find_IDR_frame(char *buf)
{
while(1)
{
if (buf[0]==0x00 && buf[1]==0x00 && buf[2]==0x01)
{
// Found a NAL unit with 3-byte startcode
if(buf[3] & 0x1F == 0x5)
{
// Found a reference frame, do something with it
}
break;
}
else if (buf[0]==0x00 && buf[1]==0x00 && buf[2]==0x00 && buf[3]==0x01)
{
// Found a NAL unit with 4-byte startcode
if(buf[4] & 0x1F == 0x5)
{
// Found a reference frame, do something with it
}
break;
}
buf++;
}
}
文章来源: h264 reference frames