Here we first explain the structure of the following H264:
01/00 01->nal (1bytes)->slice-> macro block, motion estimation vector, XX.
If a prefix appears in the body of the H264, it is changed from 00 00 00 01/00 00 01 to 00 03 00 00 01/00 03 00 01.
We see commonly used naltype like sps= 0x07 pps= 0x08 sei = 0x06 i/p/b= 0x01/0x05 that is to say only Naltype = 0x01/0x05 is not judged out i/p/b frame type, need to go to the slice layer to determine the use of "Entropy Code" specific "Entropy coding" content, please see: "H." Chinese version of "PDF".
Below is the deduction of the FFmpeg source to determine the implementation of the i/p/b frame type:
[CPP] View plain copy int getframetype (nalu_t * nal) { bs_t s; int frame_type = 0; unsigned char * OneFrameBuf_H264 = NULL ; if (oneframebuf_h264 = (unsigned char *) calloc (Nal->len + 4,sizeof (Unsigned char)) == null) { printf ("error malloc oneframebuf_h264\n"); return getchar (); } if (nal->startcodeprefix_len == 3) { oneframebuf_h264[0] = 0x00; OneFrameBuf_H264[1] = 0x00; OneFrameBuf_H264[2] = 0x01; memcpy (Oneframebuf_h264 + 3,nal->buf,nal->len); } else if (nal->startcodeprefix_ len == 4) { OneFrameBuf_H264[0] = 0x00; oneframebuf_h264[1] = 0x00; oneframebuf_ h264[2] = 0x00; OneFrameBuf_H264[3] = 0x01; memcpy (OneFrameBuf_H264 + 4, Nal->buf,nal-&gT;len); } else { printf ("H264 read error. \ n "); } bs_init ( &s,oneframebuf _h264 + nal->startcodeprefix_len + 1 ,nal->len - 1 ); if (Nal->nal_unit_type == nal_ slice | | nal->nal_unit_type == NAL_SLICE_IDR ) { /* i_first_mb */ bs_read_ue ( &s ); /* picture type */ frame _type =&Nbsp; bs_read_ue ( &s ); switch ( Frame_type) { case 0: case 5: /* P */ nal->Frametype = FRAME_P; break; case 1: case 6: /* B */ nal->Frametype = FRAME_B; break; case 3: case 8: /* SP */ nal->frametype = frame_p;