当前位置:网站首页>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 .
边栏推荐
- [deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
- How to deploy the super signature distribution platform system?
- 【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
- What are the safest securities trading apps
- Mathematical modeling -- what is mathematical modeling
- Pit avoidance: description of null values in in and not in SQL
- 避坑:Sql中 in 和not in中有null值的情况说明
- How to build your own super signature system (yunxiaoduo)?
- The significance of XOR in embedded C language
- 【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例
猜你喜欢
【深度学习】语义分割实验:Unet网络/MSRC2数据集
How to create Apple Developer personal account P8 certificate
Cocos uses custom material to display problems
Cocos creator collision and collision callback do not take effect
Window环境下配置Mongodb数据库
【数字IC验证快速入门】23、SystemVerilog项目实践之AHB-SRAMC(3)(AHB协议基本要点)
Starting from 1.5, build a microservice framework link tracking traceid
The difference between full-time graduate students and part-time graduate students!
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
HW初级流量监控,到底该怎么做
随机推荐
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
避坑:Sql中 in 和not in中有null值的情况说明
What is data leakage
15. Using the text editing tool VIM
Cocos uses custom material to display problems
The difference between full-time graduate students and part-time graduate students!
How to deploy the super signature distribution platform system?
The significance of XOR in embedded C language
【數字IC驗證快速入門】26、SystemVerilog項目實踐之AHB-SRAMC(6)(APB協議基本要點)
OpenGL common functions
从 1.5 开始搭建一个微服务框架链路追踪 traceId
【数字IC验证快速入门】20、SystemVerilog学习之基本语法7(覆盖率驱动...内含实践练习)
The download button and debug button in keil are grayed out
Create lib Library in keil and use lib Library
2022全开源企业发卡网修复短网址等BUG_2022企业级多商户发卡平台源码
Configure mongodb database in window environment
2. Heap sort "hard to understand sort"
摘抄的只言片语
Basic knowledge sorting of mongodb database
Runnable是否可以中断