美文网首页
x264 的preset设置

x264 的preset设置

作者: smallest_one | 来源:发表于2019-04-17 19:53 被阅读0次

目录

  1. 参考
  2. x264 的preset设置

1. 参考

2. x264 的preset设置

以下为x264 --fullhelp打印的preset部分的说明。

  • 默认使用的preset为medium。
  • 其他preset与medium不同的设置都在各preset中说明了。
--preset <string>       Use a preset to select encoding settings [medium]
    Overridden by user settings.
    - ultrafast:
      --no-8x8dct --aq-mode 0 --b-adapt 0
      --bframes 0 --no-cabac --no-deblock
      --no-mbtree --me dia --no-mixed-refs
      --partitions none --rc-lookahead 0 --ref 1
      --scenecut 0 --subme 0 --trellis 0
      --no-weightb --weightp 0
    - superfast:
      --no-mbtree --me dia --no-mixed-refs
      --partitions i8x8,i4x4 --rc-lookahead 0
      --ref 1 --subme 1 --trellis 0 --weightp 1
    - veryfast:
      --no-mixed-refs --rc-lookahead 10
      --ref 1 --subme 2 --trellis 0 --weightp 1
    - faster:
      --no-mixed-refs --rc-lookahead 20
      --ref 2 --subme 4 --weightp 1
    - fast:
      --rc-lookahead 30 --ref 2 --subme 6
      --weightp 1
    - medium:
      Default settings apply.
    - slow:
      --direct auto --rc-lookahead 50 --ref 5
      --subme 8 --trellis 2
    - slower:
      --b-adapt 2 --direct auto --me umh
      --partitions all --rc-lookahead 60
      --ref 8 --subme 9 --trellis 2
    - veryslow:
      --b-adapt 2 --bframes 8 --direct auto
      --me umh --merange 24 --partitions all
      --ref 16 --subme 10 --trellis 2
      --rc-lookahead 60
    - placebo:
      --bframes 16 --b-adapt 2 --direct auto
      --slow-firstpass --no-fast-pskip
      --me tesa --merange 24 --partitions all
      --rc-lookahead 60 --ref 16 --subme 11
      --trellis 2

各preset参数不同的对比可参考[2] dev.beandog.org/x264_preset_reference中的表格。

以下表格为不同于medium的preset会修改的参数的说明。

  • x264_param_t的成员为命令行参数对应到x264_param_t中的成员变量,说明摘自x264 --fullhelp中对参数的解释。
  • 说明列里[]中的值为参数的默认值。
参数名称 x264_param_t的成员 说明
ref i_frame_reference Number of reference frames [3]
scenecut i_scenecut_threshold How aggressively to insert extra I-frames [40]
no-deblock b_deblocking_filter Disable loop filter
no-cabac b_cabac Disable CABAC
bframes i_bframe Number of B-frames between I and P [3]
- analyse.intra -
partitions analyse.inter Partitions to consider ["p8x8,b8x8,i8x8,i4x4"]
(p4x4 requires p8x8. i8x8 requires --8x8dct.)
no-8x8dct analyse.b_transform_8x8 Disable adaptive spatial transform size
me analyse.i_me_method Integer pixel motion estimation method ["hex"]
- dia: diamond search, radius 1 (fast)
- hex: hexagonal search, radius 2
- umh: uneven multi-hexagon search
- esa: exhaustive search
- tesa: hadamard exhaustive search (slow)
subme analyse.i_subpel_refine Subpixel motion estimation and mode decision [7]
- 0: fullpel only (not recommended)
- 1: SAD mode decision, one qpel iteration
- 2: SATD mode decision
- 3-5: Progressively more qpel
- 6: RD mode decision for I/P-frames
- 7: RD mode decision for all frames
- 8: RD refinement for I/P-frames
- 9: RD refinement for all frames
- 10: QP-RD - requires trellis=2, aq-mode>0
- 11: Full RD: disable all early terminations
aq-mode rc.i_aq_mode AQ method [1]
- 0: Disabled
- 1: Variance AQ (complexity mask)
- 2: Auto-variance AQ
- 3: Auto-variance AQ with bias to dark scenes
no-mixed-refs analyse.b_mixed_references Don't decide references on a per partition basis
trellis analyse.i_trellis Trellis RD quantization. [1]
- 0: disabled
- 1: enabled only on the final encode of a MB
- 2: enabled on all mode decisions
b-adapt i_bframe_adaptive Adaptive B-frame decision method [1]
Higher values may lower threading efficiency.
- 0: Disabled
- 1: Fast
- 2: Optimal (slow with high --bframes)
no-mbtree rc.b_mb_tree Disable mb-tree ratecontrol
weightp analyse.i_weighted_pred Weighted prediction for P-frames [2]
- 0: Disabled
- 1: Weighted refs
- 2: Weighted refs + Duplicates
no-weightb analyse.b_weighted_bipred Disable weighted prediction for B-frames
rc-lookahead rc.i_lookahead Number of frames for frametype lookahead [40]
direct analyse.i_direct_mv_pred Direct MV prediction mode ["spatial"]
- none, spatial, temporal, auto
merange analyse.i_me_range Maximum motion vector search range [16]
no-fast-pskip analyse.b_fast_pskip Disables early SKIP detection on P-frames
  • ref:最大参考帧的数目。控制解码图片缓冲(DPB:Decoded Picture Buffer)的大小。范围是从0到16。此值是每个P帧可以使用先前多少帧作为参照帧的数目(B帧可以使用的数目要少一或两个,取决于它们是否作为参照帧)。可以被参照的最小ref数是1。还要注意的是,H.264规格限制了每个level的DPB大小。如果遵守Level 4.1规格,720p和1080p视频的最大ref数分别是9和4。[4]
  • scenecut:x264会对每一帧检查它与前面一帧的差异程度,当该值低于scenecut时,就认为发生了场景切换。如果此时与最近一个IDR帧的距离小于min-keyint,则放置一个I帧,否则放置一个IDR帧。越大的scenecut值会增加侦测到场景切换的数目。[3][4]
  • no-deblock,预设值:b_deblocking_filter =1。停用循环loop filter。不建议。[4]
  • no-cabac,预设值:b_cabac = 1。停用CABAC切换回效率较低的CAVLC。会降低压缩效率(通常10~20%)和解码的硬件需求。[4]
  • bframes,设置x264可使用的B帧的最大连续数量。
    没有B帧时,一个典型的x264流帧类型是这样的:IPPPPP…PI。如果设置了-bframes 2,两个连续的P帧就可以用B帧替换,像这样:IBPBBPBPPPB…PI。[4]
  • partitions,H.264视频在压缩过程中划分为16x16的宏块。这些宏块可以进一步划分为更小的分割,这就是此选项要控制的部分。分割依不同帧类型(I、P、B)启用。可用的分割:p8x8, p4x4, b8x8, i8x8, i4x4, none, all
    • I:i8x8、i4x4。
    • P:p8x8(亦会启用p16x8/p8x16)、p4x4(亦会启用p8x4/p4x8)。
    • B:b8x8(亦会启用b16x8/b8x16)。
    • p4x4通常不怎么有用,而且性价比极低[4]。
  • no-8x8dct,预设值b_transform_8x8 = 1。弹性8x8离散余弦转换(DCT)使x264能够弹性使用I帧的8x8转换。此选项停用该功能。
  • me,设定全像素(full-pixel)运动估计的方法。有五个选项[4]:
    1. dia(diamond):菱形搜索,半径1。最简单的搜寻方法,起始于最佳预测器。
    2. hex(hexagon):正六边形搜索,半径2。它比dia更有效率且几乎没有变慢,因此作为一般用途的编码是个不错的选择。
    3. umh(uneven multi-hex):可变半径六边形搜索。比hex更慢,但搜寻复杂的多六边形图样以避免遗漏难以找到的动态向量。不像hex和dia,merange参数直接控制umh的搜寻半径,允许增加或减少广域搜索的大小。
    4. esa(exhaustive):全局搜索。一种在merange内整个动态搜寻空间的高度最佳化搜索。虽然速度较快,但数学上相当于搜寻该区域每个单一运动矢量的暴力(bruteforce)方法。不过,它仍然比UMH还要慢,而且没有带来很大的好处,所以对于日常的编码不是特别有用。
    5. tesa(transformed exhaustive):一种尝试接近在每个动态向量执行Hadamard转换法比较的效果之算法,就像exhaustive,但效果好一点而速度慢一点。
  • subme,设定子像素的运动估计和模式决策。1~5只是控制子像素细分(refinement)强度。层级6为模式决策启用RDO,而层级8为动态向量和内部预测模式启用RDO。RDO层级明显慢于先前的层级。使用小于2的值不但会启用较快且品质较低的lookahead模式,而且导致较差的scenecut决策,因此不建议。建议:预设值,或者更高,除非速度非常重要[5]。
  • aq-mode,弹性量化模式。x264倾向于对低细节度的平滑区域使用过低码率,AQ可以更好把码率分配到各个宏块中. 该选项改变AQ重新安排码率的幅度。[7]
    • 0:完全不使用AQ。
    • 1:会在整个视频中和帧内重新分配码率。
    • 2:自动变化(Auto-variance)AQ,会尝试对每帧调整强度。(实验性的)
  • no-mixed-refs,预设值b_mixed_references = 1。建议使用预设值。Mixed refs(混合参照)会以8×8的切块为参照取代以整个宏块为参照。会增进多帧参照的帧的质量,会有一些时间耗用。此选项将禁用这个特性。[5]
  • trellis,Trellis量化,对每个8x8的块寻找合适的量化值:
    • 0:关闭
    • 1:只在最后编码时使用
    • 2:一直使用
  • b-adapt,设定自适应的B帧决策算法。此设定控制x264如何决定要放置P帧或B帧。注意:对于multi-pass编码,这个选项只在决定帧类型的编码第一阶段适用。
    • 0:禁用。总是选择B-frames。
    • 1:“Fast”算法。
    • 2:“Optimal”算法,速度较慢。
  • no-mbtree,预设值:b_mb_tree = 1。禁用macroblock tree码率控制。适用macroblock tree码率控制会提高压缩率,
  • weightp:使x264使用明确的加权预测来改善P帧的压缩率。
    • 0:停用。
    • 1:简易:分析淡入/淡出,但不分析重复参照帧。
    • 2:智慧:分析淡入/淡出和重复参照帧。
  • no-weightb,预设值:b_weighted_bipred = 1。H.264允许给可参考B帧加上影响预测图像的权重,此选项会关闭此特性。建议:使用预设值。
  • rc-lookahead,为mb-tree ratecontrol和vbv-lookahead设置可用的帧的数量。最大可设置为250。
    • 对于mb-tree而言,调大这个值会得到更准确地结果,但也会更慢。mb-tree能使用的最大值是–rc-lookahead和–keyint中较小的那一个。
    • 对于vbv-lookahead而言,调大这个值会得更稳定和精确的码率控制。vbv-lookahead能使用的最大值是如下公式算出来的:MIN(rc-lookahead, MAX(–keyint, MAX(–vbv-maxrate, –bitrate) / –vbv-bufsize * –fps))
  • direct,为’direct’类型的运动矢量设定预测模式。有两种可选的模式:spatial和temporal。可以设置为’none’关闭预测,也可以设置为’auto’让x264去选择它认为更好的模式,x264会在编码结束时告诉你它的选择。’auto’最好在2-pass编码中使用,但也可以在1-pass时使用。如果用于2-pass编码,x264会在第1趟编吗时同时尝试2种预测模式,然后在第2趟编码时使用它认为较好的那一个。注意,如果第1趟编码时选择了’auto’,那么第2趟编码时也必须设置为’auto’。不然,第2趟编码会使用’temporal’。本选项从不会浪费比特,强烈推荐使用。建议:’auto’
  • merange,控制动态搜寻的最大范围(单位是像素)。对于hex和dia,范围限制在4~16。对于umh和esa,它可以增加到超过默认值16来允许范围更广的动态搜寻,对于高清镜头和高运动镜头很有用。注意,对于umh、esa和tesa,增加merange会大幅减慢编码速度。
  • b_fast_pskip,预设值b_fast_pskip = 1。关闭P帧的早期跳过决策。大量的耗时换回非常小的质量提升。建议:预设值。

相关文章

网友评论

      本文标题:x264 的preset设置

      本文链接:https://www.haomeiwen.com/subject/mkzgwqtx.html