当前位置:网站首页>Annexb and avcc are two methods of data segmentation in decoding
Annexb and avcc are two methods of data segmentation in decoding
2022-07-07 15:41:00 【When can Xiaobai advance to success】
at present H.264 There are two popular ways of packaging , One is called AnnexB, One is called avcC. For both formats , The degree of support of each family is also different , for example ,Android Hard decoding MediaCodec We only accept AnnexB Formatted data , and Apple Of VideoToolBox, Only support avcC The format of . So this requires our practitioners to have an understanding of both formats . This chapter , Let's introduce AnnexB
1、AnnexB
1.1 Introduce
If we put more NALU Write it in a file , Multiple NALU The first one is connected and threaded into a string , because NALU Its length is different , There is no specific identifier to indicate that you are an independent NALU, When we read this file, there is no way to write it together NALU Effectively distinguish . To solve this problem , We have to give NALU Add some data , Will all NALU Segmentation . AnnexB It's used to deal with NALU A format in which layers are packed .
AnnexB The principle of format is very simple , It's in one NALU Add three or four bytes to the front , The contents of these bytes are 0 0 0 1 perhaps 0 0 1. When we read a H264 When it's flowing , Once encountered 0 0 0 1 perhaps 0 0 1, We think of a new NALU Here we go , therefore , These bytes used as separators , It is also commonly known as start code, Start code .
1.2 Anti contention byte (Emulation Prevention Bytes)
But only in NALU Adding the start code in front of it will cause problems , Because in the original code stream , It is possible that 0 0 0 1 perhaps 0 0 1 Of , This will cause the reader to send a NALU Wrong segmentation into multiple NALU. To prevent this from happening ,AnnexB Anti contention bytes are introduced (Emulation Prevention Bytes) The concept of .
The so-called anti contention byte (Emulation Prevention Bytes), It's just for you NALU Before adding the start code , First traverse the code stream , Find the existing in the code stream 0 0 0,0 0 1,0 0 2,0 0 3 Bytes of , Then modify it as follows
0 0 0 => 0 0 3 0
0 0 1 => 0 0 3 1
0 0 2 => 0 0 3 2
0 0 3 => 0 0 3 3
Copy code
That is, above 4 Under different circumstances , stay 0 0 after , Insert a byte , The content is 3. The code stream processed in this way , No longer with the start code (0 0 1, 0 0 0 1) Conflict due to repetition .
Of course , During decoding , Successfully split through the start code NALU After the data , Also remove the anti contention bytes .
0 0 3 0 => 0 0 0
0 0 3 1 => 0 0 1
0 0 3 2 => 0 0 2
0 0 3 3 => 0 0 3
Copy code
Only in this way can we get real NALU stream .
Two 、avcC
AnnexB The principle is in every NALU Write a special start code in front , Use this starting code as NALU The delimiter , Thus dividing each NALU. and avcC In another way . That is in NALU Write a few bytes in front , These bytes form an integer ( Big endian byte order ) This integer represents the whole NALU The length of . When reading , First read out this integer , Get this NALU The length of , Then read the whole by length NALU.
2.1 avcC Detailed explanation
Introducing avcC Before the format , Let's first introduce two special NALU, these two items. NALU Namely SPS and PPS,SPS and PPS Stored decoding all the way H.264 Necessary parameter information of code stream , in other words , You want to decode all the way H.264, You must first get SPS and PPS. In a later lesson , We will introduce in detail SPS and PPS, Now all you need to know is ,SPS and PPS Are two special and important NALU.
stay AnnexB in ,SPS and PPS It is regarded as ordinary NALU To deal with ; And in the avcC in ,SPS and PPS Information is treated as special information .
Adopt in one way avcC packaged H.264 In the stream , The first thing we will see is a passage called extradata The data of , This data defines this H.264 Basic attribute data of flow , Of course , Also includes SPS and PPS data .
Let's take a look extradata data format
bits
8 version ( always 0x01 )
8 avc profile ( sps[0][1] )
8 avc compatibility ( sps[0][2] )
8 avc level ( sps[0][3] )
6 reserved ( all bits on )
2 NALULengthSizeMinusOne // This value is ( Prefix length -1)
3 reserved ( all bits on )
5 number of SPS NALUs (usually 1)
repeated once per SPS:
16 SPS size
variable SPS NALU data
8 number of PPS NALUs (usually 1)
repeated once per PPS
16 PPS size
variable PPS NALU data
Copy code
Let's take a look at this value NALULengthSizeMinusOne, By adding this value to 1 , We've come to the conclusion that each of the following NALU Prefix before ( It's an integer that represents the length ) Bytes of
for example , This NALULengthSizeMinusOne yes 3, Then each NALU The length of the prefix is 4 Bytes . When we read subsequent data , You can read it first 4 Bytes , And then turn these four bytes into integers , This is this. NALU The length of the , Be careful , This length does not include the starting 4 Bytes , It's simple NALU The length of .
边栏推荐
- OpenGL's distinction and understanding of VAO, VBO and EBO
- 2.Golang基础知识
- 2. Heap sort "hard to understand sort"
- [机缘参悟-40]:方向、规则、选择、努力、公平、认知、能力、行动,读3GPP 6G白皮书的五层感悟
- 【原创】一切不谈考核的管理都是扯淡!
- Steps to create P8 certificate and warehousing account
- 避坑:Sql中 in 和not in中有null值的情况说明
- There is a cow, which gives birth to a heifer at the beginning of each year. Each heifer has a heifer at the beginning of each year since the fourth year. Please program how many cows are there in the
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
- [target detection] yolov5 Runtong voc2007 data set
猜你喜欢
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
[server data recovery] data recovery case of raid failure of a Dell server
【数字IC验证快速入门】20、SystemVerilog学习之基本语法7(覆盖率驱动...内含实践练习)
Guangzhou Development Zone enables geographical indication products to help rural revitalization
How to release NFT in batches in opensea (rinkeby test network)
[deep learning] image hyperspectral experiment: srcnn/fsrcnn
Actually changed from 408 to self proposition! 211 North China Electric Power University (Beijing)
[quick start for Digital IC Validation] 26. Ahb - sramc (6) for system verilog project practice (Basic Points of APB Protocol)
【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
Steps to create P8 certificate and warehousing account
随机推荐
【OBS】RTMPSockBuf_ Fill, remote host closed connection.
Ida Pro reverse tool finds the IP and port of the socket server
Wechat applet 01
[Data Mining] Visual Pattern Mining: Hog Feature + cosinus Similarity / K - means Clustering
[markdown grammar advanced] make your blog more exciting (IV: set font style and color comparison table)
写一篇万字长文《CAS自旋锁》送杰伦的新专辑登顶热榜
【Markdown语法高级】让你的博客更精彩(四:设置字体样式以及颜色对照表)
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering
Ctfshow, information collection: web9
Zhongang Mining: Fluorite continues to lead the growth of new energy market
2. Heap sort "hard to understand sort"
The difference between full-time graduate students and part-time graduate students!
一个需求温习到的所有知识,h5的表单被键盘遮挡,事件代理,事件委托
【数字IC验证快速入门】24、SystemVerilog项目实践之AHB-SRAMC(4)(AHB继续深入)
Points for attention in porting gd32 F4 series programs to gd32 F3 series
【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)
jacoco代码覆盖率
With 8 modules and 40 thinking models, you can break the shackles of thinking and meet the thinking needs of different stages and scenes of your work. Collect it quickly and learn it slowly
【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
【深度学习】语义分割实验:Unet网络/MSRC2数据集