#include
#include
#include
#include
typedef
unsigned
intuint
; 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; i
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)
} } /**
** @param buf sps資料內容
* @param nlen sps資料的長度
* @param width 影象寬度
* @param height 影象高度
* @成功則返回true , 失敗則返回false
*/bool
h264_decode_sps(
byte
* buf,unsigned
intnlen,
int&width,
int&height,
int&fps)
} } int
log2_max_frame_num_minus4=ue(buf,nlen,startbit);
intpic_order_cnt_type=ue(buf,nlen,startbit);
if( pic_order_cnt_type == 0 )
intlog2_max_pic_order_cnt_lsb_minus4=ue(buf,nlen,startbit);
else
if( pic_order_cnt_type == 1 )
intnum_ref_frames=ue(buf,nlen,startbit);
intgaps_in_frame_num_value_allowed_flag=u(1,buf,startbit);
intpic_width_in_mbs_minus1=ue(buf,nlen,startbit);
intpic_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;
intframe_mbs_only_flag=u(1,buf,startbit);
if(!frame_mbs_only_flag)
intmb_adaptive_frame_field_flag=u(1,buf,startbit);
intdirect_8x8_inference_flag=u(1,buf,startbit);
intframe_cropping_flag=u(1,buf,startbit);
if(frame_cropping_flag)
intvui_parameter_present_flag=u(1,buf,startbit);
if(vui_parameter_present_flag)
} intoverscan_info_present_flag=u(1,buf,startbit);
if(overscan_info_present_flag)
intint
video_signal_type_present_flag=u(1,buf,startbit);
if(video_signal_type_present_flag)
} intchroma_loc_info_present_flag=u(1,buf,startbit);
if(chroma_loc_info_present_flag)
inttiming_info_present_flag=u(1,buf,startbit);
if(timing_info_present_flag)
} } return
true
; }
else
return
false
; }
timing_info_present_flag等於1表示num_units_in_tick,time_scale和fixed_frame_rate_flag在位元流中存在。
timing_info_present_flag等於0表示num_units_in_tick,time_scale和fixed_frame_rate_flag在位元流中不存在。
因此,當timing_info_present_flag等於0時,無法得到位元速率,bool h264_decode_sps(byte * buf,unsigned int nlen,int &width,int &height,int &fps)引數fps返回值為0,可據此設定乙個預設幀率。
**:
H264解碼SPS獲取寬高和幀率
本篇文章講述了如何解碼sps獲取寬高和幀率資訊。include include include include typedef unsigned int uint typedef unsigned char byte typedef unsigned long dword uint ue byte ...
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幀的作用是立刻重新整理,使錯誤不致傳播...