量化矩阵技术早在JPEG就已经使用,视频编码标准也早就支持了,下面来看下HEVC和VVC中量化矩阵技术。量化矩阵下文缩写为QM。
HEVC中支持两种类型的QM:默认QM和自定义QM。
默认QM如下,其中8x8 intra QM使用的是JPEG在1999年基于HVS模型生成的QM,通过线性变换得到8x8 inter QM。16x16和32x32 QM是通过对8x8 QM上采样得到。这部分在HEVC代码学习43:默认量化矩阵已经介绍过了。默认QM不需要传,解码端直接从ROM中可获得。
HEVC还支持自定义QM,通过从文件读取的形式来定义QM。自定义QM输入文件格式示例如下,包括QM和DC两部分信息。自定义量化矩阵可以写在SPS或者PPS中,HM中默认写在SPS中。
QM信息:
4x4尺寸6种(2种模式 x 3通道)的QM:INTRA4X4_LUMA
INTRA4X4_CHROMAU
INTRA4X4_CHROMAV
INTER4X4_LUMA
INTER4X4_CHROMAU
INTER4X4_CHROMAV
8x8尺寸6种(2种模式 x 3通道)的QM:INTRA8X8_LUMA
INTRA8X8_CHROMAU
INTRA8X8_CHROMAV
INTER8X8_LUMA
INTER8X8_CHROMAU
INTER8X8_CHROMAV
16x16尺寸6种(2种模式 x 3通道)的QM:INTRA16X16_LUMA
INTRA16X16_CHROMAU
INTRA16X16_CHROMAV
INTER16X16_LUMA
INTER16X16_CHROMAU
INTER16X16_CHROMAV
32x32尺寸2种(2种模式 x Y通道)的QM:INTRA32X32_LUMA
INTER32X32_LUMA
其中4x4和8x8尺寸QM会给出全部的矩阵元素,这两种尺寸的QM是必须定义和传输的;16x16和32x32尺寸QM会给出8x8的矩阵元素,然后上采样到对应尺寸,上采样方式与默认QM相同,这两种尺寸QM可以直接使用默认QM,不进行定义和传输。
DC信息:
对于16x16和32x32的QM,每一个QM都需要定义一个DC值与之对应。这个DC值作用是:
1.当DC值为0时,该QM会直接使用默认QM,不进行传输。
2.当DC值不为0时,该QM会被传输并进行DPCM编码,该DC值会用于指导DPCM编码。
DPCM编码就是按照Zscan顺序扫描QM矩阵元素,扫描当前位置的元素减上一位置元素求差值,最终会传输该差值。对于QM第一个元素,会减去DC值来求差值,对于16x16和32x32的QM,就是文件中定义的这个DC值。对于4x4和8x8的QM,DC值默认为8。
INTRA4X4_LUMA =
6,9,12,22
8,12,24,31
12,16,30,35
13,17,32,38
INTRA4X4_CHROMAU =
11,12,14,19
12,14,20,23
14,16,23,25
14,16,24,27
INTRA4X4_CHROMAV =
11,12,14,19
12,14,20,23
14,16,23,25
14,16,24,27
INTER4X4_LUMA =
10,15,26,39
13,18,39,49
16,29,50,58
23,42,56,62
INTER4X4_CHROMAU =
14,15,18,20
15,16,20,22
16,18,22,24
17,21,24,25
INTER4X4_CHROMAV =
14,15,18,20
15,16,20,22
16,18,22,24
17,21,24,25
INTRA8X8_LUMA =
11,11,12,14,17,18,19,19
11,11,12,16,19,20,21,21
11,12,13,18,24,26,27,27
11,12,14,19,29,32,33,33
12,13,16,22,32,36,38,38
12,15,18,27,36,39,40,41
13,16,19,29,35,40,41,42
13,16,21,30,37,40,42,42
INTRA8X8_CHROMAU =
2,2,2,8,20,24,28,28
2,2,2,16,28,34,36,38
2,2,6,24,48,56,60,60
2,2,8,28,70,80,84,86
2,6,18,40,82,98,104,104
2,12,24,60,96,108,114,116
6,16,28,68,94,112,118,120
6,16,36,72,102,114,120,122
INTRA8X8_CHROMAV =
2,2,2,8,20,24,28,28
2,2,2,16,28,34,36,38
2,2,6,24,48,56,60,60
2,2,8,28,70,80,84,86
2,6,18,40,82,98,104,104
2,12,24,60,96,108,114,116
6,16,28,68,94,112,118,120
6,16,36,72,102,114,120,122
INTER8X8_LUMA =
14,14,15,17,19,20,20,21
14,15,16,18,19,21,21,22
15,15,17,18,20,22,23,24
15,16,18,20,22,23,24,25
16,17,20,21,24,25,26,27
16,17,20,22,25,26,27,27
17,18,21,23,25,27,28,28
17,18,21,24,26,27,28,28
INTER8X8_CHROMAU =
5,5,14,32,44,52,59,62
5,10,17,34,50,61,68,70
8,12,25,37,57,70,84,91
10,17,34,52,73,84,95,104
17,26,52,66,88,98,113,116
23,32,57,73,97,107,118,122
26,35,62,84,102,118,124,125
30,35,64,89,107,120,124,125
INTER8X8_CHROMAV =
5,5,14,32,44,52,59,62
5,10,17,34,50,61,68,70
8,12,25,37,57,70,84,91
10,17,34,52,73,84,95,104
17,26,52,66,88,98,113,116
23,32,57,73,97,107,118,122
26,35,62,84,102,118,124,125
30,35,64,89,107,120,124,125
INTRA16X16_LUMA =
2,2,4,9,17,21,23,24
2,3,6,14,23,28,30,31
2,4,7,18,34,42,45,45
3,6,10,20,46,58,59,62
4,7,14,25,53,70,73,74
6,11,18,38,65,77,81,84
7,16,21,46,67,80,86,88
9,16,25,51,70,81,87,90
INTRA16X16_CHROMAU =
6,6,8,11,17,20,21,22
6,7,9,15,21,25,26,27
6,8,10,18,29,35,37,37
7,9,12,19,38,46,47,49
8,10,15,23,43,55,57,58
9,13,18,32,51,60,63,65
10,16,20,38,53,62,66,68
11,16,23,41,55,63,67,69
INTRA16X16_CHROMAV =
6,6,8,11,17,20,21,22
6,7,9,15,21,25,26,27
6,8,10,18,29,35,37,37
7,9,12,19,38,46,47,49
8,10,15,23,43,55,57,58
9,13,18,32,51,60,63,65
10,16,20,38,53,62,66,68
11,16,23,41,55,63,67,69
INTER16X16_LUMA =
9,9,13,23,32,36,41,44
9,12,16,24,34,42,46,49
11,13,20,28,38,45,53,60
12,16,24,33,46,54,61,67
16,20,34,43,56,63,71,76
19,23,40,47,61,68,75,80
21,27,41,53,65,75,79,82
23,27,43,57,68,78,82,83
INTER16X16_CHROMAU =
10,10,14,23,31,35,39,42
10,13,16,24,33,40,44,46
12,14,20,27,36,43,50,56
13,16,24,32,44,51,57,63
16,20,33,41,53,59,66,71
19,23,38,45,57,64,70,75
21,26,39,50,61,70,74,76
23,26,41,54,64,73,76,77
INTER16X16_CHROMAV =
10,10,14,23,31,35,39,42
10,13,16,24,33,40,44,46
12,14,20,27,36,43,50,56
13,16,24,32,44,51,57,63
16,20,33,41,53,59,66,71
19,23,38,45,57,64,70,75
21,26,39,50,61,70,74,76
23,26,41,54,64,73,76,77
INTRA32X32_LUMA =
6,6,8,11,16,19,21,22
6,7,8,14,19,23,25,25
6,8,10,17,27,33,35,36
7,9,10,18,36,45,46,47
8,10,14,21,40,53,56,57
8,13,18,29,48,59,63,64
10,15,19,36,52,61,65,67
11,16,22,38,53,62,66,68
INTER32X32_LUMA =
10,10,14,23,30,34,38,41
10,13,16,24,32,39,42,45
12,14,19,25,34,42,49,55
13,15,22,31,42,50,55,60
16,19,31,39,50,58,63,69
19,23,36,44,55,63,69,74
21,25,38,49,59,68,73,75
23,26,40,53,62,71,75,76
INTRA16X16_LUMA_DC =
0
INTRA16X16_CHROMAU_DC =
6
INTRA16X16_CHROMAV_DC =
6
INTER16X16_LUMA_DC =
0
INTER16X16_CHROMAU_DC =
10
INTER16X16_CHROMAV_DC =
10
INTRA32X32_LUMA_DC =
0
INTER32X32_LUMA_DC =
0
VVC与HEVC一样,支持默认QM和自定义QM,基本不变,主要区别如下:
1.增加了更多的尺寸:64x64 luma,2x2 chroma,32x32 chroma
2.与高频调零技术结合:例如对于64x64的TU,对应的8x8 QM的右下角4x4元素可以调为0。
3.增加多核变换和NSST相关的限制。
4.支持矩形TU,通过按比例下采样得到。