x264 自适应量化模式 (AQ Adaptive Quantization) 初探

什么是自适应量化

自适应量化就是根据宏块的复杂度来调整每个宏块量化时的量化参数。

看一下x264对于相应的参数说明

aq-mode

自适应量化模式(Adaptive Quantization Mode)
默认: 1
若关闭AQ,x264倾向于对低细节度的平滑区域使用过低码率,AQ可以更好把码率分配到各个宏块中. 该选项改变AQ重新安排码率的幅度:
  • 0: 禁止AQ
  • 1: 允许AQ在整个视频中和帧内重新分配码率
  • 2: 自方差AQ(实验阶段),尝试逐帧调整强度
参见:--aq-strength

aq-strength

自适应量化强度(Adaptive Quantization Strength)
默认: 1.0
设置AQ偏向于低细节度(“平滑”)宏块的强度。不允许为负值。建议选值不超过0.0~2.0范围。
参见:--aq-mode


那为什么需要AQ呢?

看x264开发者的在分析VP8时的一段论述非常经典(http://x264dev.multimedia.cx/archives/377 )

Quantization

For quantization, the core process is basically the same among all MPEG-like video formats, and VP8 is no exception. The primary ways that video formats tend to differentiate themselves here is by varying quantization scaling factors. There are two ways in which this is primarily done: frame-based offsets that apply to all coefficients or just some portion of them, and macroblock-level offsets. VP8 primarily uses the former; in a scheme much less flexible than H.264′s custom quantization matrices, it allows for adjusting the quantizer of luma DC, luma AC, chroma DC, and so forth, separately. The latter (macroblock-level quantizer choice) can, in theory, be done using its “segmentation map” features, albeit very hackily and not very efficiently.

The killer mistake that VP8 has made here is not making macroblock-level quantization a core feature of VP8. Algorithms that take advantage of macroblock-level quantization are known as “adaptive quantization” and are absolutely critical to competitive visual quality. My implementation of variance-based adaptive quantization (before, after) in x264 still stands to this day as the single largest visual quality gain in x264 history. Encoder comparisons have showed over and over that encoders without adaptive quantization simply cannot compete.

Thus, while adaptive quantization is possible in VP8, the only way to implement it is to define one segment map for every single quantizer that one wants and to code the segment map index for every macroblock. This is inefficient and cumbersome; even the relatively suboptimal MPEG-style delta quantizer system would be a better option.  Furthermore, only 4 segment maps are allowed, for a maximum of 4 quantizers per frame.

Verdict on Quantization: Lack of well-integrated adaptive quantization is going to be a killer when the time comes to implement psy optimizations. Overall, much worse.

大致的意思如下:

对于量化来说,所有的MPEG类的视频格式的核心过程都一样,VP8也不例外.不同视频的区别之处只在于使用不同的量化缩放比例因子。基本上只有两个方法:基于帧的量化参数和基于宏块的量化参数. VP8 主要用了前者; 这就比H.264的定制量化矩阵死板多了。H264允许分别为亮度DC,亮度AC,色度DC,色度AC等等分别定义量化矩阵。VP8虽然可以通过自己的"segmentation map"来达到基于宏块改变量化参数,但是效率低下,晦涩难懂。

VP8的致命失误是没有把基于宏块级别的量化当作核心特性。利用宏块量化的算法,也就是“自适应量化”,对提高视频质量非常关键. 我在x264实现特性“基于方差自适应量化“到今天,在x264历史上仍然是最大视频质量提升。编码器比赛已经一次又一次的表明没有自适应量化就直接出局了。

你可能感兴趣的:(x264,视频编解码,x264,汇编,AQ,自适应量化,h264)