x264参数选择
x264参数选择…
samples
1 | Wind River 2017 1080p BluRay DTS x264-DON |
1 | Writing library : x264 core 152 r2851+58 429492e t_mod_Custom [8-bit@all X86_64] |
1 | Wind River 2017 1080p BluRay DTS x264-TayTO |
1 | Writing library : x264 core 155 r2867+82 a249126 t_mod_Custom_2 [8-bit@all X86_64] |
1 | release info |
1 | Writing library : x264 core 104 r1688 0b36c6d |
1 | .Release.Info |
1 | Writing library : x264 core 129 r2245+704+36 8e61944 tMod+MixAQ [8- |
参数选择
固定参数 Part 1
1 | --level 4.1 --vbv-bufsize 78125 --vbv-maxrate 62500 |
考虑播放硬件兼容性设置,以上设置是大部分桌面播放设置支持的规格
固定参数 Part 2
1 | --preset placebo --me umh --merange 32 --subme 11 --ref 4? --bframes 16? --deblock -3:-3 --no-fast-pskip --no-mbtree --no-dct-decimate |
preset
1 | --preset <string> Use a preset to select encoding settings [medium] |
me方法是preset veryslow和placebo主要区别,实际上无论是在哪个preset基础上修改参数,最终我们还是用到一样的结果。注意preset选这两个档次隐性的包含了
1 | --b-adapt 2 --direct auto --trellis 2 |
–me
Motion search method
umh|esa|tesa
一般用umh配合32-48的merange
–merange
Motion search range
32
x265的参数设置对于merange的为什么设置57这么一个值讲的比较清楚。
x264的宏块16x16,这里设置32是16*2的意思?
如果me选tesa一般可配合小一点的merange,例如16
–subme
Set the subpixel estimation complexity. RDO(Rate Distortion Optimization)
10|11
不怕慢的选11
–no-mbtree
https://forum.doom9.org/showthread.php?t=166356
蓝光电影压制的达成共识的选项,具体的讨论参考上贴内容
–no-fast-pskip
Disables early skip detection on P-frames. Very slightly increases quality at a large speed cost.
为了质量而关闭的选项
–no-dct-decimate
DCT Decimation will drop DCT blocks it deems “unnecessary”. This will improve coding efficiency, with a usually negligible loss in quality. Setting this option will disable it.
为了质量而关闭的选项
–deblock
https://forum.doom9.org/showthread.php?t=109747
-3:-3
是真人电影的惯用设置,具体的讨论参考上贴内容
–ref
ref这个参数按照level 4.1是有最大限制的,如果是全屏的1080p应该是4,但是由于我们切过黑边,可能调整成5。具体的计算办法8388608 / (width * height)
–bframes
先用16测试,根据x264返回结果确定
可变参数
剩下的这些参数是控制码率的,针对具体电影具体调整
1 | --crf ? --qcomp 0.60 --psy-rd 1.00:0.00 --aq-mode 1 --aq-strength 0.8 --ipratio 1.4 --pbratio 1.3 |
–crf
The final ratecontrol method: Constant Ratefactor
15-20
最主要的一个控制码率(质量)参数
–qcomp
Quantizer curve compression factor. 0.0 => Constant Bitrate, 1.0 => Constant Quantizer
0.6-0.8
控制时间轴上码率的分配,变化越快的画面倾向与分配跟多的码率,多多少就是有这个参数来控制。注意这个参数是在计算公式中是指数,不宜变化太大。一般用默认值0.6即可,遇到一些动作片,速度与激情,变形金刚这种可以稍微调高一点
–aq-mode –aq-strength
Adaptive Quantization Mode/Strength
–aq-mode 1 –aq-strength 0.8-0.6
官方中–aq-mode 1是标准方法,–aq-mode 2是实验方法。不少mod版本的x264都在这个上面做文章,具体情况参考具体mod版本的说明
aq-strength控制的是同一张画面中码率的分布,值越高越倾向于分配给细节更多码率。当一张画面颗粒感比较强应该用较低的值。0.8是建议值,可以尝试跟宽的取值范围
–ipratio –pbratio
Modifies the target average increase in quantizer for I-frames as compared to P-frames. Higher values increase the quality of I-frames generated
Modifies the target average decrease in quantizer for B-frames as compared to P-frames. Higher values decrease the quality of B-frames generated
–ipratio 1.4 –pbratio 1.3
这一对参数,一般同时变化。这两参数控制i帧与p帧,p帧与b帧的质量比。当你做测试的时候发先p帧,b帧质量比较差,而i帧都满意的时候就该把这个值调小一点了。会明显加大整体码率
–psy-rd
The first number is the strength of Psy-RDO to use (requires subme>=6 to activate). The second number is the strength of Psy-Trellis (requires trellis>=1 to activate). Note that Trellis is still considered ‘experimental’, and almost certainly is a Bad Thing for at least cartoons.
https://forum.doom9.org/showthread.php?t=138293
讨论参考上帖,建议默认,或小幅度调整
最终参数
1 | --level 4.1 --vbv-bufsize 78125 --vbv-maxrate 62500 --preset placebo --me umh --merange 32 --subme 11 --ref ? --bframes ? --deblock -3:-3 --no-fast-pskip --no-mbtree --no-dct-decimate --crf ? --qcomp 0.60? --psy-rd 1.00:0.00? --aq-mode 1 --aq-strength 0.8? --ipratio 1.4? --pbratio 1.3? |