x265压缩转码x264编码的ABR视频

从网络上下载的一些电影,源文件是采用了ABR平均码率控制,压制成6M码率的1080P视频。
虽然,官方说法H265比H264压缩率提升50%,但多方实践结果显示x265通常比x264优化25%-30%码率。

参数如下:

copy the film original x264 settings

尝试用x265二次编码降低视频文件大小,在最大化保持视频源文件清晰度的目标下,探讨x265编码参数。

首先,需要知道x265的优点和缺点是并存的,俗话说“x265参数控制不好,非常容易糊一脸”
其次,在CPU不够强劲的情况下,x265转码速度感人。

综合选择x265编码参数基础为medium或fast。

由于源文件ABR编码属于一次性快速平均码率,导致码率分配不恰当。
通常会存在静态画面较多的场景码率浪费,而动态场景码率不足。

所以,对于x265参数要考虑对于动态场景给予更高的压缩率,静态场景尽可能给更小的crf数值,这样对于源文件中静态场景较多的部分可以保持更好地清晰度,对于动态场景则可以适当降低编码质量,提高压缩率。

x265默认crf=28
微调至  crf=25-26

然后考虑动态和静态场景的编码复杂度,码率利用率,配合x265默认的–qcomp 0.6即可。
毕竟x265默认参数下,动态场景画面已经糊的很厉害了。

因为目标是利用x265重编码,降低码率储存电影文件,在前面qcomp分配码率的基础上,开启SAO。

最后,关闭 strong-intra-smoothing

参考资料:


  1. 官方说明文档
    –qcomp
    qComp sets the quantizer curve compression factor. It weights the frame quantizer based on the complexity of residual (measured by lookahead). It’s value must be between 0.5 and 1.0. Default value is 0.6. Increasing it to 1.0 will effectively generate CQP.

B站资料

qcomp 决定了qp时域变化灵活度,人话就是数值越低qp变动就越大,不让高动态的场景拿到高码率,就会糊。高画
质编码,qcomp要给高,反之亦然。
默认0.6 如果开了mbtree就要高 但不要超过0.8
作者:XSky晓天 https://www.bilibili.com/read/cv4910766/ 出处:bilibili


  1. 贴吧讨论资料
    前提是讨论的mbtree=0情况下,qcomp的取值:
    {1}Originally Posted by Diary Of An x264 DeveloperQuantizer curve compression, or “qcomp”, is a very old and simple idea. Lower the quality in areas of the video with high complexity and raise the quality in areas with low complexity. The original implementation dates at least back to the original libavcodec ratecontrol. There are three justifications for this:

【1】High-complexity scenes generally have high motion, and one is less likely to notice quality loss in a high motion scene, since fine detail is impossible to see in motion anyways.

【2】High-complexity scenes are extraordinarily costly bit-wise, so even if it makes quality somewhat worse, it might be worth it to save those bits to use elsewhere.

【3】Each frame in a high-complexity scene is not referenced very far into the future since there is a great deal of change between each frame, so even from a PSNR perspective, one should allocate fewer bits to those frames as opposed to frames which are nearly static.

【4】x264 uses qcomp pretty much unchanged except that it performs a gaussian blur over the frame complexities to avoid too much local fluctuation between quantizers.

【大概意思就是qcomp降低高复杂度场景的质量,节约出来的码率用来提升低复杂度场景的质量!!!
主要是因为高复杂场景就算损失一点质量也是难以视觉察觉的,除非要帧帧去截图比较差不多。
而且高复杂高动态场景分码率太多就太浪费了,而且从PSNR的好看角度来看也应该分配更少的码率给那些相对于静态场景的区域。
看来qcomp=0.60(mbtree=0)保持不变就好了,除非对那些复杂帧使用了高斯模糊(大概是降噪降细节降码率)防止局部码率波动过大的情况下可以改变下qcomp的取值】

{2}If you raise the “–qcomp” value towards 1.0, you actually lower the effect of the qcomp algorithm!
This means that “high complexity” scenes will get better quality - which may look better at a first glance (especially if you step through those scenes frame-by-frame).
However, it also means that “high complexity” scenes will cost a lot more bits!
Those bits are will then be missing in other places, of course!
Consequently, the overall quality may easily become worse. Bummer!

As with most parameters (especially Psy optimizations), neither very high nor very low values will give optimal results. It’s all about finding the sweet spot!
And a “–qcomp” value of 0.6 obviously is what the developers consider to be a good default.
If a higher (or lower) value would generally be beneficial, they would have made that value the default!
This doesn’t mean that a somewhat higher (or lower) value couldn’t be beneficial for your particular source and/or your personal preferences.
But if you decide to mess with “–qcomp”, your decision should be based on intensive testing rather than rumors. And if you are too lazy for running an in-depth test, just trust the developer’s decision and stick with the default value

(BTW: The basic principle behind the classic “qcomp” algorithm and the “MB-Tree” algorithm is the same. The difference is that qcomp measures “complexity” for complete frames while MB-Tree tracks the “complexity” of individual macro-blocks)

【看来qcomp管的是所有帧的复杂度情况,mbtree管的是单独的宏观的复杂度。】

总结就是:如果视频高动态特别多的话,mbtree=0的情况下,提升qcomp的取值(高于0.60)是对整体都有好处的。如果视频静态特别多的话,mbtree=0的情况下,保持qcomp=0.60(或低于0.60)就可以了。因为一般视频动态也有,静态也有,保持默认的0.60似乎是最好的。

BTW:一直觉得mbtree=0的情况下,qcomp=0.80的质量会比mbtree=0,qcomp=0.60的质量好,看来是不正确的认知。(不过解决掉心中的疑惑感觉还是挺好的!!!)

–qcomp
默认: 0.60

量化曲线(quantizer curve)压缩因子。0.0 => 恒定比特率,1.0 => 恒定量化值。
qcomp在“高成本”的高运动帧与“低成本”的低运动帧之间权衡分配码率。
极端设置qcomp=0.0趋于真正的恒定比特率,通常会造成高运动场景十分难看,而将宝贵的码率用于让低运动场景看着很完美。另一极端设置qcomp=1.0则能达到近似恒定量化参数(QP),并完全关闭x264的aq-mode和时间方向的RDO(mb-tree),于是码率被浪费在高复杂度的场景上,而高复杂度的场景无法用作未来远处的帧的参考,因为帧与帧之间的变化太大。
与mbtree一起使用时,也会影响mbtree与aq-strength的强度,而这两项倾向于将更多码率用于低复杂度的场景和宏块(macroblock)。(qcomp越大,则aq与mbtree越弱)。

https://tieba.baidu.com/p/3485066522