当前位置:网站首页>H265 Nalu type judgment and SPS data analysis
H265 Nalu type judgment and SPS data analysis
2022-06-10 21:22:00 【User 3504492】
One ,Nalu analysis
First of all, let's introduce h265(HEVC)nal Unit head , And h264 Of nal Layer by layer ,h265 Of nal unit header It consists of two bytes , As shown in the figure below :
0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | F | Type | LayerId | TID | +------------ - +---------------- - +
Its syntax is defined in the following table :
nal_unit_header( ) { | Descriptor |
|---|---|
forbidden_zero_bit | f(1) |
nal_unit_type | u(6) |
nuh_reserved_zero_6bits | u(6) |
nuh_temporal_id_plus1 | u(3) |
} |
Nalu Type The definition of :
enum NalUnitType { NAL_UNIT_CODED_SLICE_TRAIL_N = 0, // 0 NAL_UNIT_CODED_SLICE_TRAIL_R, // 1 NAL_UNIT_CODED_SLICE_TSA_N, // 2 NAL_UNIT_CODED_SLICE_TLA, // 3 NAL_UNIT_CODED_SLICE_STSA_N, // 4 NAL_UNIT_CODED_SLICE_STSA_R, // 5 NAL_UNIT_CODED_SLICE_RADL_N, // 6 NAL_UNIT_CODED_SLICE_DLP, // 7 NAL_UNIT_CODED_SLICE_RASL_N, // 8 NAL_UNIT_CODED_SLICE_TFD, // 9 NAL_UNIT_RESERVED_10, NAL_UNIT_RESERVED_11, NAL_UNIT_RESERVED_12, NAL_UNIT_RESERVED_13, NAL_UNIT_RESERVED_14, NAL_UNIT_RESERVED_15, NAL_UNIT_CODED_SLICE_BLA, // 16 NAL_UNIT_CODED_SLICE_BLA, // 16 NAL_UNIT_CODED_SLICE_BLANT, // 17 NAL_UNIT_CODED_SLICE_BLA_N_LP, // 18 NAL_UNIT_CODED_SLICE_IDR, // 19 // Current name in the spec: IDR_W_DLP NAL_UNIT_CODED_SLICE_IDR_N_LP, // 20 NAL_UNIT_CODED_SLICE_CRA, // 21 NAL_UNIT_RESERVED_22, NAL_UNIT_RESERVED_23, NAL_UNIT_RESERVED_24, NAL_UNIT_RESERVED_25, NAL_UNIT_RESERVED_26, NAL_UNIT_RESERVED_27, NAL_UNIT_RESERVED_28, NAL_UNIT_RESERVED_29, NAL_UNIT_RESERVED_30, NAL_UNIT_RESERVED_31, NAL_UNIT_VPS, // 32 NAL_UNIT_SPS, // 33 NAL_UNIT_PPS, // 34 NAL_UNIT_ACCESS_UNIT_DELIMITER, // 35 NAL_UNIT_EOS, // 36 NAL_UNIT_EOB, // 37 NAL_UNIT_FILLER_DATA, // 38 NAL_UNIT_SEI, // 39 Prefix SEI NAL_UNIT_SEI_SUFFIX, // 40 Suffix SEI NAL_UNIT_RESERVED_41, NAL_UNIT_RESERVED_42, NAL_UNIT_RESERVED_43, NAL_UNIT_RESERVED_44, NAL_UNIT_RESERVED_45, NAL_UNIT_RESERVED_46, NAL_UNIT_RESERVED_47, NAL_UNIT_UNSPECIFIED_48, NAL_UNIT_UNSPECIFIED_49, NAL_UNIT_UNSPECIFIED_50, NAL_UNIT_UNSPECIFIED_51, NAL_UNIT_UNSPECIFIED_52, NAL_UNIT_UNSPECIFIED_53, NAL_UNIT_UNSPECIFIED_54, NAL_UNIT_UNSPECIFIED_55, NAL_UNIT_UNSPECIFIED_56, NAL_UNIT_UNSPECIFIED_57, NAL_UNIT_UNSPECIFIED_58, NAL_UNIT_UNSPECIFIED_59, NAL_UNIT_UNSPECIFIED_60, NAL_UNIT_UNSPECIFIED_61, NAL_UNIT_UNSPECIFIED_62, NAL_UNIT_UNSPECIFIED_63, NAL_UNIT_INVALID, };
By recording H265 Of ES flow , Analyze NALU head , Found in 6 The beginning of each species is :
1) 00 00 00 01 40 01
2) 00 00 00 01 42 01
3) 00 00 00 01 44 01
4) 00 00 00 01 4E 01
5) 00 00 00 01 26 01
6) 00 00 00 01 02 01
According to H265 Of NALU Type definition analysis ,
00 00 00 01 40 01 Of nuh_unit_type The value of is 32, The semantic is video parameter set
00 00 00 01 42 01 Of nuh_unit_type The value of is 33, Semantic sequence parameter set
00 00 00 01 44 01 Of nuh_unit_type The value of is 34, The semantic is the image parameter set
00 00 00 01 4E 01 Of nuh_unit_type The value of is 39, Semantics are supplementary and enhanced information
00 00 00 01 26 01 Of nuh_unit_type The value of is 19, Semantically, there may be RADL Graphic IDR Graphic SS Encoding data
00 00 00 01 02 01 Of nuh_unit_type The value of is 1, The semantic is the referenced post image , And not TSA、 Not STSA Of SS Encoding data
During coding , When getting the code stream from the encoder ,1、2、3、4、5 Is in a frame of data . amount to H264 Of I frame .
Two ,SPS analysis
a section HEVC The bitstream may contain one or more encoded video sequences CVS, Every CVS Start with a random access point , namely IDR/BLA/CRA. stay H.264 and HEVC in , Sequence parameter set SPS Include the CVS All in slice Information needed .SPS It can be divided into several parts :
1、 bootstrap ID;
2、 Decode relevant information , Such as grade level 、 The resolution of the 、 The number of sublayers, etc ;
3、 Function switch identification and function parameters in a certain grade ;
4、 Restriction information on the flexibility of structure and transform coefficient coding ;
5、 Time domain scalable information ;
6、VUI.
The following is a discussion of each grammatical element :
1、sps_video_parameter_set_id : Specifies the currently active VPS Of ID Number , The value of the current example is 0, This is also the same as the VPS The result of analysis has been ;
2、sps_max_sub_layers_minus1 : This value +1 Means to refer to the SPS Of CVS The maximum number of time domain sublayers included , Value range 0-6; The value in this example is 0, That is, only 1 Time domain sublayer ;
3、sps_temporal_id_nesting_flag : The restriction information identifying the inter prediction reference frame in the time domain scalability ; Here, the value is taken as 0【 It seems to contradict the standard document ……】;
4、sps_seq_parameter_set_id :【 In fact, before this parameter, there are still many data in the code stream that are not explained clearly , Save it for later 】 Ben SPS Of ID value , Take here 0;
5、chroma_format_idc: Chroma sampling format , The value here is 1, Representative adoption 4:2:0 Format ;
6、separate_colour_plane_flag : This parameter is 4:4:4 Format specific , In this case... Does not exist ;
7、pic_width_in_luma_samples and pic_height_in_luma_samples : Image resolution information , Code with exponential Columbus , This example takes 176*144;
8、conformance_window_flag : Indicates the consistent window crop offset parameter conformance cropping window offset parameters Information about ; The value here is 1, Indicates that the following digits are conf_win_left_offset、conf_win_right_offset、conf_win_top_offset、conf_win_bottom_offset Equal parameter ;
9、bit_depth_luma_minus8 : The bit depth of the luminance matrix and the luminance quantization parameter range offset are specified ; Take here 0, Each luminance pixel is represented by 8 To represent ,QpBdOffset Parameter is 0;
10、bit_depth_chroma_minus8 : And bit_depth_luma_minus8 similar , It's just for chromaticity ;
11、log2_max_pic_order_cnt_lsb_minus4 : Responsible for calculating variables MaxPicOrderCntLsb Value 【 What's this value for ……】;
12、sps_sub_layer_ordering_info_present_flag : Time domain sublayer sequence identification switch , This value takes 1, It means that the following digits are sps_max_dec_pic_buffering、sps_num_reorder_pics、sps_max_latency_increase Equal parameter ;
13、log2_min_coding_block_size_minus3 : Used to calculate the minimum brightness CB The size of the , Take here 0;
14、log2_diff_max_min_coding_block_size : Used to calculate the maximum and minimum brightness CB Difference in size , Take here 3;
15、log2_min_transform_block_size_minus2: Used to calculate the minimum TB Size , Take here 0;
16、log2_diff_max_min_transform_block_size : Used to calculate the maximum and minimum TB Difference in size , Take here 3;
17、max_transform_hierarchy_depth_inter : Interframe mode CB in TB Maximum level depth of , Here is 2;
18、max_transform_hierarchy_depth_intra :: In frame mode CB in TB Maximum level depth of , Here is 2;
19、scaling_list_enabled_flag: Identifies whether a quantization list is used in transform coefficient quantization , Take here 0;
20、amp_enabled_flag : Identify whether asymmetric motion division is used , Here is 1;
21、sample_adaptive_offset_enabled_flag : Identify whether to use SAO, Here is 1;
22、pcm_enabled_flag : Identify whether to use PCM, Here is 0, It's not practical PCM data ;
23、num_short_term_ref_pic_sets : instructions SPS in short_term_ref_pic_set( ) The number of this structure , Here is 1;
24、long_term_ref_pics_present_flag : Indicates whether a long-term reference frame is used in inter prediction , Here is 1, That is, the long-term reference frame ;
25、sps_temporal_mvp_enable_flag : identification CVS Central African IDR Whether the header of the frame contains slice_temporal_mvp_enabled_flag identification , Here is 1, It contains ;
26、sps_strong_intra_smoothing_enable_flag : Identify whether the bilinear difference method is used in the smoothing filtering process , Here is 1, That is to use ;
27、vui_parameters_present_flag : Whether the sign has
The following is the parsing code
1、 Redefine the type
typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned longuint32; typedef unsigned __int64uint64; typedef signed charint8; typedef signed shortint16; typedef signed longint32; typedef signed __int64int64;
2、 Definition Sps Relevant parameters required
struct vc_params_t
{
LONG width,height;
DWORD profile, level;
DWORD nal_length_size;
void clear()
{
memset(this, 0, sizeof(*this));
}
};3、 Define the network abstraction layer Nal class
class NALBitstream
{
public:
NALBitstream() : m_data(NULL), m_len(0), m_idx(0), m_bits(0), m_byte(0), m_zeros(0)
{
};
NALBitstream(void * data, int len)
{
Init(data, len);
};
void Init(void * data, int len)
{
m_data = (LPBYTE)data;
m_len = len;
m_idx = 0;
m_bits = 0;
m_byte = 0;
m_zeros = 0;
};
BYTE GetBYTE()
{
if ( m_idx >= m_len )
return 0;
BYTE b = m_data[m_idx++];
if ( b == 0 )
{
m_zeros++;
if ( (m_idx < m_len) && (m_zeros == 2) && (m_data[m_idx] == 0x03) )
{
m_idx++;
m_zeros=0;
}
}
else m_zeros = 0;
return b;
};
UINT32 GetBit()
{
if (m_bits == 0)
{
m_byte = GetBYTE();
m_bits = 8;
}
m_bits--;
return (m_byte >> m_bits) & 0x1;
};
UINT32 GetWord(int bits)
{
UINT32 u = 0;
while ( bits > 0 )
{
u <<= 1;
u |= GetBit();
bits--;
}
return u;
};
UINT32 GetUE()
{
int zeros = 0;
while (m_idx < m_len && GetBit() == 0 )
zeros++;
return GetWord(zeros) + ((1 << zeros) - 1);
};
INT32 GetSE()
{
UINT32 UE = GetUE();
bool positive = UE & 1;
INT32 SE = (UE + 1) >> 1;
if ( !positive )
SE = -SE;
return SE;
};
private:
LPBYTE m_data;
int m_len;
int m_idx;
int m_bits;
BYTE m_byte;
int m_zeros;
};
bool ParseSequenceParameterSet(BYTE* data,int size, vc_params_t& params)
{
if (size < 20)
return false;
NALBitstream bs(data, size);
// seq_parameter_set_rbsp()
bs.GetWord(4);// sps_video_parameter_set_id
int sps_max_sub_layers_minus1 = bs.GetWord(3);
if (sps_max_sub_layers_minus1 > 6)
return false;
bs.GetWord(1);
bs.GetWord(2);
bs.GetWord(1);
params.profile = bs.GetWord(5);
bs.GetWord(32);//
bs.GetWord(1);//
bs.GetWord(1);//
bs.GetWord(1);//
bs.GetWord(1);//
bs.GetWord(44);//
params.level = bs.GetWord(8);// general_level_idc
uint8 sub_layer_profile_present_flag[6] = {0};
uint8 sub_layer_level_present_flag[6] = {0};
for (int i = 0; i < sps_max_sub_layers_minus1; i++)
{
sub_layer_profile_present_flag[i]= bs.GetWord(1);
sub_layer_level_present_flag[i]= bs.GetWord(1);
}
if (sps_max_sub_layers_minus1 > 0)
{
for (int i = sps_max_sub_layers_minus1; i < 8; i++)
uint8 reserved_zero_2bits = bs.GetWord(2);
}
for (int i = 0; i < sps_max_sub_layers_minus1; i++)
{
if (sub_layer_profile_present_flag[i])
{
bs.GetWord(2);
bs.GetWord(1);
bs.GetWord(5);/
bs.GetWord(32);
bs.GetWord(1);
bs.GetWord(1);
bs.GetWord(1);
bs.GetWord(1);
bs.GetWord(44);
}
if (sub_layer_level_present_flag[i])
bs.GetWord(8);// sub_layer_level_idc[i]
}
uint32 sps_seq_parameter_set_id= bs.GetUE();
if (sps_seq_parameter_set_id > 15)
return false;
uint32 chroma_format_idc = bs.GetUE();
if (sps_seq_parameter_set_id > 3)
return false;
if (chroma_format_idc == 3)
bs.GetWord(1);//
params.width = bs.GetUE(); // pic_width_in_luma_samples
params.height = bs.GetUE(); // pic_height_in_luma_samples
if (bs.GetWord(1))
{
bs.GetUE();
bs.GetUE();
bs.GetUE();
bs.GetUE();
}
uint32 bit_depth_luma_minus8= bs.GetUE();
uint32 bit_depth_chroma_minus8= bs.GetUE();
if (bit_depth_luma_minus8 != bit_depth_chroma_minus8)
return false;
//...
}4、 Test code
边栏推荐
- 2台电脑共享一套键盘鼠标
- H265 Nalu类型判断及 sps 数据解析
- 冷酸灵,一个国产品牌IPO的30年曲折史
- LeetCode 进阶之路 - 加一
- Understanding deep learning attention
- Is it safe to buy funds on mobile phones? Will the principal be swallowed?
- Software definition boundary (SDP)
- 异步、线程池(CompletableFuture)
- Leetcode advanced path - the first unique character in a string
- 連接mysql報錯 errorCode 1129, state HY000, Host ‘xxx‘ is blocked because of many connection errors
猜你喜欢

Software definition boundary (SDP)

^30H5 Web Worker多线程

六级考试-商务英语-考前最后一背

Game compatibility test (general scheme)

Quick start to elastic job, three minutes to experience distributed scheduled tasks

冷酸灵,一个国产品牌IPO的30年曲折史

CET-6 - Business English - the last recitation before the test

Pytorch deep learning -- neural network convolution layer conv2d

Calculus review 1

View play and earn will lead crypto games astray
随机推荐
电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
H.264中NALU、RBSP、SODB的关系
Vissim仿真快速入门
轻便型FDW框架 for pb
torch. nn. Simple understanding of parameter / / to be continued. Let me understand this paragraph
What should be paid attention to when designing Multilayer PCB?
LeetCode 进阶之路 - 136.只出现一次的数字
详解MATLAB中与矩阵运算有关的算术运算符(加、减、乘、除、点乘、点除、乘方)
魔塔类游戏实现源码及关卡生成
Magic tower game implementation source code and level generation
Theoretical basis of distributed services
聊聊服务器性能优化~(建议收藏)
Niuke.com: numbers that appear more than half of the times in the array
72. 编辑距离 ●●●
数据库系统概论 ---- 第一章 -- 绪论(重要知识点)
Cas de test app
Is it safe to buy funds on mobile phones? Will the principal be swallowed?
在手机上买基金安全吗?会不会被吞本金?
pdf. Js----- JS parse PDF file to realize preview, and obtain the contents in PDF file (in array form)
What are the conditions for opening an account for agricultural futures? How much is the service charge for opening an account now?