h265获取解码头

vps、sps、pps信息见上图:

获取代码如下:

	void getH265Head(char* extradata,int len)
	{
		LOGD("getH265Head width : %d,height : %d,len : %d",mWidth,mHeight,len);
        if(extradata != NULL && len>22)
        {
        	char* vps=NULL;
        	char* sps=NULL;
			char* pps=NULL;
        	int vpsLen,spsLen,ppsLen;
            int numArrays = extradata[22];
            char* extraData = extradata;
            int offset =0;
            for (int j=0; j < numArrays; j++) {
                int currentNalOffset = offset;
                int array_completeness =(extraData[23+offset] & 0x80) >>7;
                unsigned int  reserved =(extraData[23+offset] & 0x40) >>6;
                unsigned int  NAL_unit_type = extraData[23+offset] & 0x3f;
                offset++;
                unsigned int numNalus = (extraData[23+offset] <<8) + (extraData[23+offset+1]);
                offset+=2;
                for (int i=0; i< numNalus; i++) {
                    unsigned int nalUnitLength = (extraData[23+offset] <<8) + (extraData[23+offset+1]);
                    offset+=2;
                    offset+=nalUnitLength;
                }
                currentNalOffset += 5;
                int nalLen = offset- currentNalOffset;
                LOGD("offset = %d, currentNalOffset = %d,nalLen = %d",offset,currentNalOffset,nalLen);
                if (NAL_unit_type == 32 && nalLen >0) {

                    vps = new char[nalLen];
                    vpsLen = nalLen;
                    memcpy(vps,(char*)extraData+23+currentNalOffset, nalLen);
                }
                else if (NAL_unit_type == 33 && nalLen>0)
                {
                    sps = new char[nalLen];
                    spsLen = nalLen;
                    memcpy(sps, (char*)extraData+23+currentNalOffset, nalLen);
                }
                else if (NAL_unit_type == 34 && nalLen>0)
                {
                    pps = new char[nalLen];
                    ppsLen = nalLen;
                    memcpy((char*)pps,(char*)extraData+23+currentNalOffset, nalLen);
                }
                else if (NAL_unit_type == 39 && nalLen>0)
                {
                	//preSEI
                }
                else if (NAL_unit_type == 40 && nalLen>0)
                {
                	//sufSEI
                }
            }

            if(vps != NULL && sps != NULL && pps != NULL){
            	mH265Len = vpsLen + spsLen + ppsLen + 4*3;
            	mH265Head = new char[mH265Len];
            	char header[4] = {0,0,0,1};
            	memcpy(mH265Head,header,4);
            	memcpy(mH265Head + 4,vps,vpsLen);
            	memcpy(mH265Head + vpsLen + 4,header,4);
            	memcpy(mH265Head + vpsLen + 8, sps, spsLen);
            	memcpy(mH265Head + vpsLen + spsLen + 8,header,4);
            	memcpy(mH265Head + vpsLen + spsLen + 12, pps, ppsLen);
            	LOGD("vps len : %d, sps len : %d, pps len: %d, total : %d",vpsLen,spsLen,ppsLen,mH265Len);
            	delete[] vps;
            	delete[] sps;
            	delete[] pps;

            }
        }
	}

阅读更多
文章标签: h265 编码头
个人分类: 音视频 c++
上一篇vs2015编译ffmpeg
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭