H264 i/p/b Frame Type Judging

Source: Internet
Author: User
Tags printf

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;  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.