我怎么能分辨H264 EN codeD的视频帧通过一些特殊的标签? [英] how can I distinguish H264 encoded Video frames by some special tag?

查看:183
本文介绍了我怎么能分辨H264 EN codeD的视频帧通过一些特殊的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有恩H264 codeD的视频文件从Android移动相机来了,我想要得到的框架,并将其保存为文件一个接一个。问题是,我怎么能分辨出帧,执行帧通过一些特殊的标签分手了?现在我有这个功能,可以通过获取字节帧的长度,也许有助于理解我的问题,THX:)

 公共静态INT h263Parse(字节[] buf中,诠释抵消,诠释nLen)
{
            INT vop_found,我;
    vop_found = 0;
    I = 0;
    如果(vop_found == 0)
        {
        为(ⅰ=(偏移+ 3);我≤(偏移+ nLen);我+ +)
                {
            如果(BUF [I-3] == 0×00)
                    如果(BUF [I-2] == 0×00)
                            如果((BUF [I-1]&安培; 0xff的)下;的0x84)
                                    如果((BUF [I-1]&安培; 0xff的)GT; = 0x80的)
                        {
                我++;
                vop_found = 1;
                打破;
            }
        }
    }    如果(vop_found == 1)
        {
        为(;我≤(偏移+ nLen);我++)
                {
                如果(BUF [I-3] == 0×00)
                    如果(BUF [I-2] == 0×00)
                            如果((BUF [I-1]&安培; 0xff的)下;的0x84)
                                    如果((BUF [I-1]&安培; 0xff的)GT; = 0x80的)
                        {
                回到I-3偏移;
            }
        }
    }
    返回-1;
}


解决方案

我严重不知道你的code是做什么的(因为它被命名为 h263parse )和你是问H264。

不管怎么说,H264帧做一个特殊的标记分头行动,称为启动code preFIX,这是任 0×00 0×00 0×01 0×00 0×00 0×00 0×01 结果
所有两种启动codeS之间的数据包括 NAL单元在H264说话。因此,也许你想要做的是搜索的开始code $ P $在您的h264码流PFIX,做一些与如下(直到下一个启动code preFIX)流中NAL单元。

这样的事情也许:

 无效h264parse_and_process(字符* BUF)
{
    而(1)
    {
        如果(BUF [0] == 0×00和放大器;&放大器; BUF [1] == 0×00和放大器;&放大器; BUF [2] == 0x01)的
        {
            //发现3个字节开始code NAL单元,用它做什么
            do_something(BUF); //可能写入到文件
            打破;
        }
        否则如果(BUF [0] == 0×00和放大器;&放大器; BUF [1] == 0×00和放大器;&放大器; BUF [2] == 0×00和放大器;&放大器; BUF [3] == 0x01)的
        {
            //发现有4个字节的开始code NAL单元,用它做什么
            do_something(BUF); //可能写入到文件
            打破;
        }
        BUF ++;
    }
}

I have H264 encoded Video file came from Android mobile camera and I want to get the frames and store them as files one by one. The problem is, how can I distinguish the frames, do the frames split up by some special tag? Now I have this function which can get the frames length by bytes, maybe it helps to understand my questions,Thx:)

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

解决方案

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

Anyways, H264 frames do 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 perhaps what you want to do is search for the startcode prefix in your h264 stream and do something with the NAL unit that follows (until the next startcode prefix) in the stream.

Something like this perhaps:

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

这篇关于我怎么能分辨H264 EN codeD的视频帧通过一些特殊的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆