当前位置:网站首页>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 .
边栏推荐
- What is data leakage
- 【数字IC验证快速入门】23、SystemVerilog项目实践之AHB-SRAMC(3)(AHB协议基本要点)
- MySQL bit类型解析
- Starting from 1.5, build a microservice framework link tracking traceid
- Do not use memset to clear floating-point numbers
- Use cpolar to build a business website (2)
- [understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
- HW初级流量监控,到底该怎么做
- Ctfshow, information collection: web4
- 如何在opensea批量发布NFT(Rinkeby测试网)
猜你喜欢

如何在opensea批量发布NFT(Rinkeby测试网)

【數字IC驗證快速入門】26、SystemVerilog項目實踐之AHB-SRAMC(6)(APB協議基本要點)

OpenGL's distinction and understanding of VAO, VBO and EBO

Ctfshow, information collection: web4

Ctfshow, information collection: web14

Super simple and fully automated generation super signature system (cloud Xiaoduo minclouds.com cloud service instance), free application in-house test app distribution and hosting platform, maintenan
Introduction of mongod management database method

【OBS】RTMPSockBuf_Fill, remote host closed connection.

【搞船日记】【Shapr3D的STL格式转Gcode】

HW primary flow monitoring, what should we do
随机推荐
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
What is Base64?
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
Keil5 does not support online simulation of STM32 F0 series
15. Using the text editing tool VIM
Pit avoidance: description of null values in in and not in SQL
众昂矿业:萤石继续引领新能源市场增长
【数字IC验证快速入门】18、SystemVerilog学习之基本语法5(并发线程...内含实践练习)
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering
Unity之ASE实现全屏风沙效果
2022全开源企业发卡网修复短网址等BUG_2022企业级多商户发卡平台源码
Steps to create P8 certificate and warehousing account
Guangzhou Development Zone enables geographical indication products to help rural revitalization
A need to review all the knowledge, H5 form is blocked by the keyboard, event agent, event delegation
微信小程序 01
Getting started with webgl (2)
Cocos makes Scrollview to realize the effect of zooming in the middle and zooming out on both sides
2. 堆排序『较难理解的排序』
PAT 甲级 1103 Integer Factorizatio
Do not use memset to clear floating-point numbers