h264 reference frames

匆匆过客 提交于 2019-12-04 14:49:01
puffadder

H264 frames split up by a special tag, called the startcode prefix, which is either of 0x00 0x00 0x01 OR 0x00 0x00 0x00 0x01. All the data between two startcodes comprises a NAL unit in H264 speak. So what you want to do is search for the startcode prefix in your h264 stream. The byte following the startcode prefix immediately is the NAL header. The lowest 5 bits of the NAL header will give you the NAL unit type. If nal_unit_type = 5, that particular NAL unit is a reference frame.

Something like this:

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++;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!