bool h264_is_keyframe(const char buffer, int len) {
if(!buffer || len < 6)
return FALSE;
/ Parse H264 header now */
uint8_t fragment = *buffer & 0x1F;
uint8_t nal = (buffer+1) & 0x1F;
if(fragment == 7 || ((fragment == 28 || fragment == 29) && nal == 7)) {
printf(“Got an H264 key frame\n”);
return TRUE;
} else if(fragment == 24) {
/ May we find an SPS in this STAP-A? /
buffer++;
len–;
uint16_t psize = 0;
/ We’re reading 3 bytes */
while(len > 2) {
memcpy(&psize, buffer, 2);
psize = ntohs(psize);
buffer += 2;
len -= 2;
int nal = buffer & 0x1F;
if(nal == 7) {
printf(“Got an SPS/PPS\n”);
return TRUE;
}
buffer += psize;
len -= psize;
}
}
/ If we got here it’s not a key frame */
return FALSE;
}
判断H264 Keyframe实现
最新推荐文章于 2022-05-28 10:41:32 发布