h264 reference frames

感情迁移 提交于 2019-12-21 19:51:26

问题


I'm looking for a algorithm of finding reference frames in h264 stream. The most common metod I saw in different solutions was finding access unit delimiters and NAL of IDR type. Unfortunatelly most streams I checked didn't have NAL of IDR type. I'll be gratefull for help. Regards Jacek


回答1:


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++;
    }
}


来源:https://stackoverflow.com/questions/10946496/h264-reference-frames

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