How can I distinguish video cards encoded by H264 with a special tag?

I have H264 encoded video files received from an Android Android camera and I want to receive frames and store them as files one at a time. The problem is, how can I distinguish between frames, is there a special tag to separate frames? Now I have this function, which can get the frame length by bytes, maybe this helps to understand my questions, thanks :)

  public static int h263Parse(byte[]buf, int offset, int nLen)
{
            int vop_found, i;          
    vop_found = 0;        
    i=0;
    if(vop_found == 0)
        {
        for(i=(offset + 3); i<(offset+nLen); i++)
                {
            if(buf[i-3] == 0x00)
                    if(buf[i-2] ==  0x00)
                            if((buf[i-1]&0xff) < 0x84)
                                    if((buf[i-1]&0xff) >= 0x80)
                        {
                i++;
                vop_found=1;
                break;
            }
        }
    }

    if(vop_found == 1)
        {
        for(; i<(offset+nLen); i++)
                {
                if(buf[i-3] == 0x00)
                    if(buf[i-2] ==  0x00)
                            if((buf[i-1]&0xff) < 0x84)
                                    if((buf[i-1]&0xff) >= 0x80)
                        {
                return i-3-offset;
            }
        }
    }
    return -1;
}
+3
source share
1 answer

I seriously don’t know what your code is doing (because it is called h263parse ) and you are asking about h264.

, H264 , , 0x00 0x00 0x01 0x00 0x00 0x00 0x01
NAL H264. , , h264 - NAL, ( ) .

- :

void h264parse_and_process(char *buf)
{
    while(1)
    {
        if (buf[0]==0x00 && buf[1]==0x00 && buf[2]==0x01)
        {
            // Found a NAL unit with 3-byte startcode, do something with it
            do_something(buf); // May be write to a file
            break;
        }
        else if (buf[0]==0x00 && buf[1]==0x00 && buf[2]==0x00 && buf[3]==0x01)
        {
            // Found a NAL unit with 4-byte startcode, do something with it
            do_something(buf); // May be write to a file
            break;
        }
        buf++;
    }
}
+6

All Articles