H264解碼SPS獲取寬高和幀率

2021-08-03 20:58:25 字數 2539 閱讀 4696

本篇文章講述了如何解碼sps獲取寬高和幀率資訊。

#include #include #include #include typedef  unsigned int uint;

typedef unsigned char byte;

typedef unsigned long dword;

uint ue(byte *pbuff, uint nlen, uint &nstartbit)

nzeronum++;

nstartbit++;

}nstartbit ++;

//計算結果

dword dwret = 0;

for (uint i=0; i1;

if (pbuff[nstartbit / 8] & (0x80 >> (nstartbit % 8)))

nstartbit++;

}return (1

<< nzeronum) - 1 + dwret;

}int se(byte *pbuff, uint nlen, uint &nstartbit)

dword u(uint bitcount,byte * buf,uint &nstartbit)

nstartbit++;

}return dwret;

}/**

* h264的nal起始碼防競爭機制

* *@param buf sps資料內容

* * @無返回值

*/void de_emulation_prevention(byte* buf,unsigned int* buf_size)

}return;

}/**

* *@param buf sps資料內容

*@param nlen sps資料的長度

*@param width 影象寬度

*@param height 影象高度

* @成功則返回1 , 失敗則返回0

*/int h264_decode_sps(byte * buf,unsigned int nlen,int &width,int &height,int &fps)}}

int log2_max_frame_num_minus4=ue(buf,nlen,startbit);

int pic_order_cnt_type=ue(buf,nlen,startbit);

if( pic_order_cnt_type == 0 )

int log2_max_pic_order_cnt_lsb_minus4=ue(buf,nlen,startbit);

else

if( pic_order_cnt_type == 1 )

int num_ref_frames=ue(buf,nlen,startbit);

int gaps_in_frame_num_value_allowed_flag=u(1,buf,startbit);

int pic_width_in_mbs_minus1=ue(buf,nlen,startbit);

int pic_height_in_map_units_minus1=ue(buf,nlen,startbit);

width=(pic_width_in_mbs_minus1+1)*16;

height=(pic_height_in_map_units_minus1+1)*16;

int frame_mbs_only_flag=u(1,buf,startbit);

if(!frame_mbs_only_flag)

int mb_adaptive_frame_field_flag=u(1,buf,startbit);

int direct_8x8_inference_flag=u(1,buf,startbit);

int frame_cropping_flag=u(1,buf,startbit);

if(frame_cropping_flag)

int vui_parameter_present_flag=u(1,buf,startbit);

if(vui_parameter_present_flag)

}int overscan_info_present_flag=u(1,buf,startbit);

if(overscan_info_present_flag)

int video_signal_type_present_flag=u(1,buf,startbit);

if(video_signal_type_present_flag)

}int chroma_loc_info_present_flag=u(1,buf,startbit);

if(chroma_loc_info_present_flag)

int timing_info_present_flag=u(1,buf,startbit);

if(timing_info_present_flag)

}return

true;

}else

return

false;

}

H264解碼SPS獲取寬高和幀率

include include include include typedef unsigned intuint typedef unsigned char byte typedef unsigned long dword uint ue byte pbuff,uint nlen,uint nsta...

H264解析sps獲取解析度等資訊

include include include include typedef unsigned int uint typedef unsigned char byte typedef unsigned long dword uint ue byte pbuff,uint nlen,uint nst...

H264中I幀和IDR幀的區別

idr instantaneous decoding refresh 即時解碼重新整理。i和idr幀都是使用幀內 的。它們都是同乙個東西而已,在編碼和解碼中為了方便,要首個i幀和其他i幀區別開,所以才把第乙個首個i幀叫idr,這樣就方便控制編碼和解碼流程。idr幀的作用是立刻重新整理,使錯誤不致傳播...