4. 本文档使用的格式和过程 (Formats and Processes Used in This Document)
4.1. Bitstream 格式
本节规定 Advanced Professional Video (APV) codec 的 bitstream 格式.
raw bitstream format 由一系列 AUs 组成, 每个 AU 前都有一个指示 access unit 大小的字段. raw bitstream format 在附录 A 中规定.
4.2. 源帧, 解码帧和输出帧格式
本节规定源帧和解码帧之间的关系.
bitstream 所表示的视频源是一系列帧.
源帧和解码帧各自由一个或多个 sample arrays 组成:
- Monochrome, 例如仅 Luma.
- Luma 和两个 chroma, 例如 [H273] 中规定的 YCbCr 或 YCgCo.
- Green, blue 和 red (GBR, 也称为 RGB).
- 表示其他未指定 tri-stimulus color samplings 的数组, 例如 [CIE15] 中规定的 YZX, 也称为 XYZ.
- 表示其他未指定 four color samplings 的数组.
为便于本文档的记法和术语, 与这些数组关联的变量和术语可称为 luma 和 chroma, 无论实际使用的颜色表示方法是什么.
变量 SubWidthC, SubHeightC 和 NumComps 的值取决于表 2 中规定的 chroma format sampling 结构. chroma format sampling 结构通过 chroma_format_idc 发信号表示. chroma_format_idc, SubWidthC, SubHeightC 和 NumComps 的其他值可在本文档未来版本中规定.
| chroma_format_idc | Chroma format | SubWidthC | SubHeightC | NumComps |
|---|---|---|---|---|
| 0 | 4:0:0 | 1 | 1 | 1 |
| 1 | reserved | reserved | reserved | reserved |
| 2 | 4:2:2 | 2 | 1 | 3 |
| 3 | 4:4:4 | 1 | 1 | 3 |
| 4 | 4:4:4:4 | 1 | 1 | 4 |
| 5..7 | reserved | reserved | reserved | reserved |
表 2: 从 chroma_format_idc 派生的 SubWidthC, SubHeightC 和 NumComps 值
在 4:0:0 sampling 中, 只有一个 sample array, 可视为 luma array.
在 4:2:2 sampling 中, 两个 chroma arrays 各自具有与 luma array 相同的高度和 luma array 一半的宽度.
在 4:4:4 sampling 和 4:4:4:4 sampling 中, 所有 sample arrays 都具有与 luma array 相同的高度和宽度.
视频序列中 luma 和 chroma arrays 中每个 sample 表示所需的 bit 数范围为 10 到 16, 包含两端.
当 chroma_format_idc 的值等于 2 时, chroma samples 与对应的 luma samples 共址. 一帧中的标称位置如图 1 所示.
& * & * & * & * & * ...
& * & * & * & * & * ...
& * & * & * & * & * ...
& * & * & * & * & * ...
...
& - location where both luma and chroma sample exist
* - location where only luma sample exist
图 1: 一帧中 4:2:2 luma 和 chroma samples 的标称垂直和水平位置
对于每一帧, 当 chroma_format_idc 的值等于 3 或 4 时, 所有 array samples 都共址. 一帧中的标称位置如图 2 所示.
& & & & & & & & & & ...
& & & & & & & & & & ...
& & & & & & & & & & ...
& & & & & & & & & & ...
...
& - location where both luma and chroma sample exist
图 2: 一帧中 4:4:4 和 4:4:4:4 luma 与 chroma samples 的标称垂直和水平位置
samples 以 MB 为单位处理. 变量 MbWidth 和 MbHeight 指定每个 MB 的 luma arrays 的宽度和高度, 定义如下:
MbWidth = 16MbHeight = 16
变量 MbWidthC 和 MbHeightC 指定每个 MB 的 chroma arrays 的宽度和高度, 派生如下:
MbWidthC = MbWidth // SubWidthCMbHeightC = MbHeight // SubHeightC
4.3. 帧划分
4.3.1. 将帧划分为 Tiles
本节规定如何将帧划分为 tiles.
帧被划分为 tiles. tile 是覆盖帧中矩形区域的一组 MBs, 并且独立于其他 tiles 处理. 每个 tile 具有相同宽度和高度, 但当帧宽度或高度分别不是 tile 宽度或高度的倍数时, 右侧或底部帧边界处的 tiles 可能例外. 一帧中的 tiles 按 raster order 扫描. 在一个 tile 内, MBs 按 raster order 扫描. 每个 MB 由一个 (MbWidth) x (MbHeight) luma array 和 0 个, 2 个或 3 个对应 chroma sample arrays 组成.
例如, 图 3 所示帧被划分为 6 个 tiles, 即 3 个 tile columns 和 2 个 tile rows. 在此示例中, tile 大小定义为 4 个 column MBs 和 4 个 row MBs. 对于按 raster order 的第 3 和第 6 个 tiles, 由于帧宽度不是 tile 宽度的倍数, tile 大小为 2 个 column MBs 和 4 个 row MBs.
+===================+===================+=========+
# | | | # MB | MB | MB | MB # MB | MB #
+-------------------+-------------------+---------+
# | | | # MB | MB | MB | MB # MB | MB #
+----- tile -----+-------------------+---------+
# | | | # MB | MB | MB | MB # MB | MB #
+-------------------+-------------------+---------+
# | | | # MB | MB | MB | MB # MB | MB #
+===================+===================+=========+
# MB | MB | MB | MB # MB | MB | MB | MB # MB | MB #
+-------------------+-------------------+---------+
# MB | MB | MB | MB # MB | MB | MB | MB # MB | MB #
+-------------------+-------------------+---------+
# MB | MB | MB | MB # MB | MB | MB | MB # MB | MB #
+-------------------+-------------------+---------+
# MB | MB | MB | MB # MB | MB | MB | MB # MB | MB #
+===================+===================+=========+
#,= tile boundary
|,- MB boundary
图 3: 具有 10 x 8 MBs 并被划分为 6 个 tiles 的帧
4.3.2. 空间或按组件划分
以下处理元素划分形成空间或按组件划分:
- 将每一帧划分为 components.
- 将每一帧划分为 tile columns.
- 将每一帧划分为 tile rows.
- 将每个 tile column 划分为 tiles.
- 将每个 tile row 划分为 tiles.
- 将每个 tile 划分为 color components.
- 将每个 tile 划分为 MBs.
- 将每个 MB 划分为 blocks.
4.4. 扫描过程
4.4.1. Zig-Zag Scan
该过程把二维数组转换为一维数组. 过程从 block 左上位置开始, 然后沿对角线移动, 在 block 边缘改变方向, 直到到达右下位置. 图 4 给出了 4x4 大小 block 的扫描顺序示例.
+===================+
# 00 | 01 | 05 | 06 #
+-------------------+
# 02 | 04 | 07 | 12 #
+-------------------+
# 03 | 08 | 11 | 13 #
+-------------------+
# 09 | 10 | 14 | 15 #
+===================+
图 4: 4x4 block 的 zig-zag scanning order 示例
该过程的输入为:
- 变量
blkWidth, 指定 block 的宽度. - 变量
blkHeight, 指定 block 的高度.
该过程的输出为数组 zigZagScan[sPos].
数组索引 sPos 指定扫描位置, 范围从 0 到 (blkWidth * blkHeight)-1. 根据 blkWidth 和 blkHeight 的值, 数组 zigZagScan 派生如下:
pos = 0
zigZagScan[pos] = 0
pos++
for(line = 1; line < (blkWidth + blkHeight - 1); line++){
if(line % 2){
x = min(line, blkWidth - 1)
y = max(0, line - (blkWidth - 1))
while(x >=0 && y < blkHeight){
zigZagScan[pos] = y * blkWidth + x
pos++
x--
y++
}
}
else{
y = min(line, blkHeight - 1)
x = max(0, line - (blkHeight - 1))
while(y >= 0 && x < blkWidth){
zigZagScan[pos] = y * blkWidth + x
pos++
x++
y--
}
}
}
图 5: zig-zag scan 伪代码
4.4.2. Inverse Scan
该过程的输入为:
- 变量
blkWidth, 指定 block 的宽度. - 变量
blkHeight, 指定 block 的高度.
该过程的输出为数组 inverseScan[rPos].
数组索引 rPos 指定 raster scan 位置, 范围从 0 到 (blkWidth * blkHeight)-1. 根据 blkWidth 和 blkHeight 的值, 数组 inverseScan 派生如下:
- 变量
forwardScan通过调用第 4.4.1 节规定的 zig-zag scan order initialization process 派生, 输入参数为blkWidth和blkHeight. - 输出变量
inverseScan派生如下:
for(pos = 0; pos < blkWidth * blkHeight; pos++){
inverseScan[forwardScan[pos]] = pos
}
图 6: inverse zig-zag scan 伪代码