H265 HM7.1 代码阅读

下载地址:https://hevc.hhi.fraunhofer.de/svn/svn_HEVCSoftware/tags/HM-7.1/

 

 

                               第一部分 HM Encoder

1.1 encoder.cfg 文件

  1.1.1 关于bitDepth(8bit YUV,10 bit YUV,....)

  ("InputBitDepth",         m_uiInputBitDepth,    8u, "Bit-depth of input file")
  ("BitDepth",              m_uiInputBitDepth,    8u, "Deprecated alias of InputBitDepth")
  ("OutputBitDepth",        m_uiOutputBitDepth,   0u, "Bit-depth of output file")
  ("InternalBitDepth",      m_uiInternalBitDepth, 0u, "Internal bit-depth (BitDepth+BitIncrement)")

  可以设置输入和输出以及内部的bitdepth不同。

                      H265 HM7.1 代码阅读_第1张图片
  1.1.2  LCU/CU

     // Unit definition parameters
  ("MaxCUWidth",             m_uiMaxCUWidth,             64u)
  ("MaxCUHeight",            m_uiMaxCUHeight,            64u)
  ("MaxPartitionDepth,h",     m_uiMaxCUDepth,              4u, "CU depth")  
  ("QuadtreeTULog2MaxSize",  m_uiQuadtreeTULog2MaxSize,   6u, "Maximum TU size in logarithm base 2")
  ("QuadtreeTULog2MinSize",  m_uiQuadtreeTULog2MinSize,   2u, "Minimum TU size in logarithm base 2")
 
  ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs")
  ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs")

 example:

  #======== Unit definition ================
MaxCUWidth                    : 64          # Maximum coding unit width in pixel
MaxCUHeight                   : 64          # Maximum coding unit height in pixel
MaxPartitionDepth             : 4           # Maximum coding unit depth
QuadtreeTULog2MaxSize         : 5           # Log2 of maximum transform size for
                                            # quadtree-based TU coding (2...6)
QuadtreeTULog2MinSize         : 2           # Log2 of minimum transform size for
                                            # quadtree-based TU coding (2...6)
QuadtreeTUMaxDepthInter       : 3
QuadtreeTUMaxDepthIntra       : 3

 

largest coding units (LCUs): 由maxCUWidth/maxCUHeight 定义尺寸,是NXN的正方形。典型的LCU可以是128X128,64X64等。

smallest coding unit (SCU):  对LCU不断地进行4分法得到CU,最大的depth由MaxPartitionDepth 定义,通过限制深度的划分,得到的最小的CU就是SCU。目前允许的最小的SCU为8x8.

下面是一个example: LCU=128X128, MaxPartitionDepth =5

 depth=0   128x128  (LCU)

 depth=1   64x64

 depth=2   32x32

 depth=3   16x16

 depth=4    8x8  (SCU)

 

            H265 HM7.1 代码阅读_第2张图片

CU: Coded Unit, LCU可以进一步划分(平均4分法)成CU,CU才是在编码中的基本单位(类似于MB),因此一个LCU中可以保护inter编码的CU和Intra编码的CU这种混合情况,原因就在于LCU并不是面向编码的单位,CU才是基本的编码单位。因为是平均4分法,因此不会出现长方形的CU。最小的CU限制为8x8.

                H265 HM7.1 代码阅读_第3张图片

PU: prediction Unit , 如果说CU是同H264中的MB相似的概念,那么PU就是inter/intra partition (H264中的P16X16/P16X8/P8X16,P8X8,P8X4,P4X8,P4X4,对于intra只有I16X16/I4X4).在H265中,一个CU可以划分成多个PU,PU不限制是正方形,可以是长方形。目前最小的PU为8x4/4x8,不支持4x4. 一共有8种模式

 

    H265 HM7.1 代码阅读_第4张图片
同样的,在H265中也是区分Intra partition size和Inter partition size。

假设当前CU为2NX2N:

       其中Intra partition size只有2种类型:不划分(2NX2N),4分法(NXN)

       而inter partition size一共有8种partition,其中4种为对称和4种非对称的partition:

                    2NxN   2Nx N    Nx2N  NxN  (类似于H264中的P16X16,P16X8,P8X16,P8X8)

        非对称的4种为:其中一个值为2N,另外一个味1/4 * 2N=N/2

          2N*N/2, 2N*3N/2,    N/2 * 2N,  3N/2 * 2N

   

TU: Transform Unit,the basic unit used for the transform and quantization processes,是DCT和量化的基本单位。

比如在H264中通常使用的是DCT4X4(DCT8X8),量化也是以4x4(8x8)为单位进行的。

PU和TU的关系,首先TU的size可以大于PU的size,但是不能大于其属于的CU size。

TU的可选的类型需要根据当前PU 的类型来确定:如果PU是对称的划分,那么TU可选的size为2N * 2N,  N*N (假设当前CU为2N * 2N),

                                                2N * 2N      if   transform_size_flag = 0 

        TU_SIZE=                     N  *  N        if transform_size_flag = 1 && PU is symmetry

                                                N/2 * N/2   if transform_size_flag = 1 && PU is asymmetry

    

   H265 HM7.1 代码阅读_第5张图片

Table 2‑1 Possible combinations of CU, PU and TU

split flag = 0 (CUd processing, current depth = d)

split flag = 1 (NxN split)

Prediction type

PU splitting

TU size

Recursive CU processing for CUd+1 whose size is NxN

INTRA (only for 2Nx2N, NxN)

 

INTER (for all PU splitting)

 

SKIP (only for 2Nx2N)

symmetric type

asymmetric type

TU size flag = 0

TU size flag = 1

2Nx2N

2NxN

Nx2N

NxN

2NxnU

2NxnD

nLx2N

nRx2N

2Nx2N

NxN  (symmetric type)

N/2xN/2 (asymmetric type)

 

CU/PU/TU的内容来自于: JCTVC-A124 

  Samsung’s Response to the Call for Proposals on Video Compression Technology

     

 

上面是SAMSUNG的提案,那么在H265的draft中实际的CU/PU/TU的情况如何,从下面的码流中来看:

     H265 HM7.1 代码阅读_第6张图片

 SPS中定义了的参数可以用来得到下面的变量:

H265 HM7.1 代码阅读_第7张图片
 可见,CTB就是LCU。图像分辨率可以分成多少个LCU,多少个SCU,可以通过上面的变量来计算。
 下面假设是单slice结构:

   H265 HM7.1 代码阅读_第8张图片

在每一个slice中进行LCU的遍历和处理。下面是几个sliceaddr相关的变量:

     H265 HM7.1 代码阅读_第9张图片

 

 

 



  1.1.3. 输入YUV的预处理

   如果YUV的分辨率不是标准的分辨率(不是最小CU的整数倍),需要进行预处理包括padding或者cropping等

   ("CroppingMode",         m_croppingMode,      0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")

 
  ("HorizontalPadding,-pdx",m_aiPad[0],      0, "Horizontal source padding for cropping mode 2")
  ("VerticalPadding,-pdy", m_aiPad[1],      0, "Vertical source padding for cropping mode 2")
  ("CropLeft",             m_cropLeft,            0, "Left cropping for cropping mode 3")
  ("CropRight",            m_cropRight,           0, "Right cropping for cropping mode 3")
  ("CropTop",              m_cropTop,             0, "Top cropping for cropping mode 3")
  ("CropBottom",           m_cropBottom,          0, "Bottom cropping for cropping mode 3")

 

  HM代码中支持4种模式:

    不做任何的处理

    自动计算出需要padding的参数

   给定padding的参数(m_aiPad[0]/[1])

你可能感兴趣的:(HEVC学习)