将编译好的x265可以通过命令直接调用。为了调试,要先准备一个未编码的YUV文件,并且知道其分辨率,然后直接输入命令即可,例如:
/x265 --input BQMall_832x480_60.yuv --fps 20 --input-res 832x480 -o basket.265
这个是最简洁的X265命令了。
上面的input 后指定了输入文件名,fps指定了输出帧率,input-res 指定了输入文件的分辨率,-o是输出的文件。
1.X265参数分类
X265的其他参数比较多,可以通过x265 --hep来查看。
整体而言,其命令分为以下几类:
下面整理各个参数,为了便于阅读,功能一样的选项只保留一个,例如-o和–output一样,就只保留-o。
有些指标说是CLI only,就是只能用在命令行窗口的意思 。
1. 执行选项
2. 日志和输出选项
3. 输入选项
–input 原始的YUV 或者 Y4M 输入的文件. -
表示从标准输入中读。
–y4m 忽略输入文件的后缀,强制解析为YUV4MPEG2。
–fps <float|rational> 原始文件帧率,如果是Y4M的话就自动识别
–input-res WxH 原始文件大小,格式为 [w x h],
–input-depth 输入文件的比特深度.默认为 8
–input-csp 色度抽样
0 - i400 (4:0:0 单色的,也就是灰度图像)
1 - i420 (4:2:0 默认)
2 - i422 (4:2:2)
3 - i444 (4:4:4)
–nalu-file 输入一个包含SEI的文本文件。
-f/–frames 编码的最大帧率
–seek 编码第一帧的位置,也就是要跳跃几帧。
–[no-]interlace <bff|tff> 表示输入图片是按时间顺序的交错场。 0. 逐行图像(缺省) 1. 先顶场 2. 先底场。HEVC将交错的内容作为一场进行编码。提供正确的场的顺序给编码器。源尺寸必须是场的尺寸,FPS必须是每秒以场为单位。解码器必须要根据场的定向重新组合以用于显示。
–dither 如果下采样到8位像素,则启用抖动。默认禁用
–[no-]copy-pic 将输入图像的缓存保存到帧中,默认是可以。
4. 性能和指标选项
–[no-]ssim 允许输出SSIM 统计结果. 默认为禁止
–[no-]psnr 允许输出PSNR 统计结果. 默认为禁止
–pools <integer,…> 每 NUMA 个节点有一个逗号分隔的线程列表。如果是 “none”,就没有工作池创建,只有可能有帧的并行化。如果是 NULL 或 “ ”(缺省),x265 所有的线程都用在每 NUMA 个节点上。
-F/–frame-threads 并行编码的帧数. 0:自动决策
–[no-]wpp 允许波前并行处理.默认为允许。波前编码。编码器可能开始编码一行只要当前行上方至少有个 CTU(编码树单元)处于编码过程中。这会带来3-5倍的并行化和提高大约1%的压缩率。如果线程池不可用,这个特性会被隐式地关闭掉。缺省:开启
–[no-]slices 启用多个片的功能. Default 1
–[no-]pmode 并行模式预测. 默认禁止。并行模式或分布式模式。如果开启,编码器会将每个CU(merge、inter、intra)的分析工作部署到多个工作线程。只有当x265没有使得CPU核饱和才推荐使用该模式。如果-rect开启,RD level处于3或4,此时是最有效的。RD level处于5或6时,通常会部署足够多的工作来保证CPU过头,假定你的CPU还没有饱和。
–pmode 会增加利用率而不会降低压缩效果。事实上,因为这个模式是在并行模式下测量,这使得一些不切实际的模式过早退出,从而使得你通常会得到稍微好一点的压缩率当开启的时候(是以不跳过不太可能的模式为代价)。pmode绕过提前退出会降低编码速度,尤其是preset为faster的时候。
当不存在线程池的时候,这个特征被隐式地关闭了。
–[no-]pme 并行运动预测,默认禁止。并行运动估计。当开启的时候,如果对于一个给定的CU有多余两个的参考需要运动搜索,编码器会将运动估计部署到多个工作线程进行工作。只有当x265没有使得CPU核饱和才推荐使用该模式。–pmode比这个选项更有效,因为它所分发的工作量更高。开启–pme选项,分发的工作过量超过并行带来的好处一般不常见。
当不存在线程池的时候,这个特征被隐式地关闭了。
–[no-]asm <bool|int|string> cpu检测,默认自动,x265缺省地会使用所有检测到的CPU SIMD架构。你也可以试用 –no-asm 来禁止使用任何 SIMD 架构,或指定一个以逗号分隔的 SIMD 架构使用列表,匹配以下字符串: MMX2, SSE, SSE2, SSE3, SSSE3, SSE4, SSE4.1, SSE4.2, AVX, XOP, FMA4, AVX2, FMA3, 一些高的架构就隐含了低架构可用;你也可以直接提供一个CPU能力图。
-p/–preset 编码的级别。提供了几个预设的值,在编码效率和编码速度之间做一个折中。该参数需在其他输入参数应用之前启用,因此可以覆盖任何这些值所控制的参数值。预设的参数值如下: 0 – ultrafast; 1 – superfast;2 – veryfast; 3 – faster; 4 - fast;5 - medium(缺省);6 – slow; 7 – slower; 8 – veryslow; 9 – placebo.
-t/–tune 设置特定的视频源或情景,这个参数设置的应用是在preset之后,但在其他所有参数之前。缺省:none,值:psnr、ssim、grain、zero-latency、fast-decode。
4. 层次档次和级别
-P/–profile 强制指定档次的需求,确保解码器的输出流可修饰以支持指定的档次。如果指定的档次不被编码器的编译选项所支持(高比特位深度的编码器不能输出与Main或MainStillPicture兼容的比特流),则有可能放弃该编码器。
–level-idc <integer|float> 最低的解码需求级别。缺省值0,意味着由编码器自动检测。如果指定了值,编码器就会在指定级别内赋予编码一些指定规则。如果编码器不能达到这个级别,就会给出警告并放弃这个编码器。如果所要求的级别比实际级别高,则发送实际的需求级别。
注意,指定解码界别会强制编码器开启 VBV 用于常码率因子编码,可能会导致不确定性。 值被指定为浮点数或一个整数(级别乘以10),例如:级别 5.1 可以被指定为 “5.1” 或 “51”,级别 5.0 被指定为 “5.0”或“50”。
–[no-]high-tier 如果 --level-idc 被指定,–high-tier允许支持那个级别的高等级。编码器首先会在指定的级别和主等级下编码,仅当有必要且那个级别的高等级可用的情况下才开启高等级。如果你所要求的级别不支持高等级,那么高等级不会被支持。如果 --no-high-tier 被指定,则编码器只会在主等级下编码。
缺省:开启
–uhd-bd 允许支持HD蓝光碟格式,如果指定了与编码选项不兼容,则编码器会尝试着去修正或设置正确的编码配置。如果编码器不能这么做,则这个选项就会被关闭。
–[no-]allow-non-conformance ,允许libx265指定profile和无级别的情况下生成比特流。如果不满足严格的级别条件,缺省是放弃任何编码。两种最有可能的原因就是:–ctu太小,–ref太大,或者码率或者分辨率超出了指定条件。
5. 模式选择和分析
–rd <1…6> 模式决策中RDO水平。这个值越大,模式分析越耗时,使用更多的率失真优化。值越小编码速度越快,通常值越大比特流越小。缺省:3
–[no-]psy-rd <0…5.0> 心理视率失真优化的强度,0表示禁止,默认为2。
–[no-]rdoq-level <0|1|2> 量化中的RDO水平, 0:none, 1:levels, 2:levels & coding groups. Default 0
–[no-]psy-rdoq <0…50.0> Strength of psycho-visual optimization in RDO quantization, 0 to disable. Default 0.0
–dynamic-rd <0…4.0> Strength of dynamic RD, 0 to disable. Default 0.00
–[no-]ssim-rd Enable ssim rate distortion optimization, 0 to disable. Default disabled
–[no-]rd-refine Enable QP based RD refinement for rd levels 5 and 6. Default disabled
–[no-]early-skip Enable early SKIP detection. Default disabled
–[no-]rskip Enable early exit from recursion. Default enabled
–[no-]tskip-fast Enable fast intra transform skipping. Default disabled
–[no-]splitrd-skip Enable skipping split RD analysis when sum of split CU rdCost larger than one split CU rdCost for Intra CU. Default disabled
–nr-intra An integer value in range of 0 to 2000, which denotes strength of noise reduction in intra CUs. Default 0
–nr-inter An integer value in range of 0 to 2000, which denotes strength of noise reduction in inter CUs. Default 0
–ctu-info Enable receiving ctu information asynchronously and determine reaction to the CTU information (0, 1, 2, 4, 6) Default 0
- 1: force the partitions if CTU information is present
- 2: functionality of (1) and reduce qp if CTU information has changed
- 4: functionality of (1) and force Inter modes when CTU Information has changed, merge/skip otherwise
Enable this option only when planning to invoke the API function x265_encoder_ctu_info to copy ctu-info asynchronously
-w/–[no-]weightp Enable weighted prediction in P slices. Default enabled
–[no-]weightb Enable weighted prediction in B slices. Default disabled
–[no-]cu-lossless Consider lossless mode in CU RDO decisions. Default disabled
–[no-]signhide Hide sign bit of one coeff per TU (rdo). Default enabled
–[no-]tskip Enable intra 4x4 transform skipping. Default disabled
6. 时间和运动搜索选项
–max-merge <1…5> Maximum number of merge candidates. Default 2
–ref max number of L0 references to be allowed (1 … 16) Default 3
–limit-refs <0|1|2|3> Limit references per depth (1) or CU (2) or both (3). Default 3
–me Motion search method dia hex umh star full. Default 1
-m/–subme Amount of subpel refinement to perform (0:least … 7:most). Default 2
–merange Motion search range. Default 57
–[no-]rect Enable rectangular motion partitions Nx2N and 2NxN. Default disabled
–[no-]amp Enable asymmetric motion partitions, requires --rect. Default disabled
–[no-]limit-modes Limit rectangular and asymmetric motion predictions. Default 0
–[no-]temporal-mvp Enable temporal MV predictors. Default enabled
7. 空间和帧内选项
–[no-]strong-intra-smoothing Enable strong intra smoothing for 32x32 blocks. Default enabled
–[no-]constrained-intra Constrained intra prediction (use only intra coded reference pixels) Default disabled
–[no-]b-intra Enable intra in B frames in veryslow presets. Default disabled
–[no-]fast-intra Enable faster search method for angular intra predictions. Default disabled
–rdpenalty <0…2> penalty for 32x32 intra TU in non-I slices. 0:disabled 1:RD-penalty 2:maximum. Default 0
8. 心理与视觉选项
9. 片决策选项
–[no-]open-gop Enable open-GOP, allows I slices to be non-IDR. Default enabled
-I/–keyint Max IDR period in frames. -1 for infinite-gop. Default 250
-i/–min-keyint Scenecuts closer together than this are coded as I, not IDR. Default: auto
–gop-lookahead Extends gop boundary if a scenecut is found within this from keyint boundary. Default 0
–no-scenecut Disable adaptive I-frame decision
–scenecut How aggressively to insert extra I-frames. Default 40
–scenecut-bias <0…100.0> Bias for scenecut detection. Default 5.00
–radl Number of RADL pictures allowed in front of IDR. Default 0
–intra-refresh Use Periodic Intra Refresh instead of IDR frames
–rc-lookahead Number of frames for frame-type lookahead (determines encoder latency) Default 20
–lookahead-slices <0…16> Number of slices to use per lookahead cost estimate. Default 8
–lookahead-threads Number of threads to be dedicated to perform lookahead only. Default 0
-b/–bframes <0…16> Maximum number of consecutive b-frames. Default 4
–bframe-bias Bias towards B frame decisions. Default 0
–b-adapt <0…2> 0 - none, 1 - fast, 2 - full (trellis) adaptive B frame scheduling. Default 2
–[no-]b-pyramid Use B-frames as references. Default enabled
–qpfile Force frametypes and QPs for some or all frames
Format of each line: framenumber frametype QP
QP is optional (none lets x265 choose). Frametypes: I,i,K,P,B,b.
QPs are restricted by qpmin/qpmax.
–force-flush Force the encoder to flush frames. Default 0
0 - flush the encoder only when all the input pictures are over.
1 - flush all the frames even when the input is not over. Slicetype decision may change with this option.
2 - flush the slicetype decided frames only.
10. 质量,码率控制和率失真选项
–bitrate Target bitrate (kbps) for ABR (implied). Default 0
-q/–qp QP for P slices in CQP mode (implied). --ipratio and --pbration determine other slice QPs
–[no-]dynamic-refine Dynamically changes refine-inter level for each CU. Default disabled
–[no-]refine-mv Enable mv refinement for load mode. Default disabled
–aq-mode Mode for Adaptive Quantization - 0:none 1:uniform AQ 2:auto variance 3:auto variance with bias to dark scenes. Default 1
–aq-strength Reduces blocking and blurring in flat and textured areas (0 to 3.0). Default 1.00
–[no-]aq-motion Adaptive Quantization based on the relative motion of each CU w.r.t., frame. Default disabled
–qg-size Specifies the size of the quantization group (64, 32, 16, 8). Default 32
–[no-]cutree Enable cutree for Adaptive Quantization. Default enabled
–[no-]rc-grain Enable ratecontrol mode to handle grains specifically. turned on with tune grain. Default disabled
–ipratio QP factor between I and P. Default 1.40
–pbratio QP factor between P and B. Default 1.30
–qcomp Weight given to predicted complexity. Default 0.60
–qpstep The maximum single adjustment in QP allowed to rate control. Default 4
–qpmin sets a hard lower limit on QP allowed to ratecontrol. Default 0
–qpmax sets a hard upper limit on QP allowed to ratecontrol. Default 69
–[no-]const-vbv Enable consistent vbv. turned on with tune grain. Default disabled
–cbqpoffs Chroma Cb QP Offset [-12…12]. Default 0
–crqpoffs Chroma Cr QP Offset [-12…12]. Default 0
–scaling-list Specify a file containing HM style quant scaling lists or ‘default’ or ‘off’. Default: off
–zones //… Tweak the bitrate of regions of the video
Each zone is of the form
,,
where is either
q= (force QP)
or b= (bitrate multiplier)
–lambda-file Specify a file containing replacement values for the lambda tables
MAX_MAX_QP+1 floats for lambda table, then again for lambda2 table
Blank lines and lines starting with hash(#) are ignored
Comma is considered to be white-space
–max-ausize-factor This value controls the maximum AU size defined in specification.
It represents the percentage of maximum AU size used. Default 1.0
–[no-]deblock Enable Deblocking Loop Filter, optionally specify tC:Beta offsets Default enabled
–[no-]sao Enable Sample Adaptive Offset. Default enabled
–[no-]sao-non-deblock Use non-deblocked pixels, else right/bottom boundary areas skipped. Default disabled
–[no-]limit-sao Limit Sample Adaptive Offset types. Default disabled
11. 量化和深度选项
-s/–ctu <64|32|16> 最大CU尺寸(宽和高)。该值越大,x265编码图像平坦区域的效率就越高,码流降低的就越厉害。然而这会带来并行化的损失,更少的CU行并行编码,同样更少的帧并行编码。因为这个原因,preset选择faster的话,CU的尺寸就设置为32。缺省:64
–min-cu-size <64|32|16|8> 最小Cu大小.默认为8
–max-tu-size <32|16|8|4> Maximum TU size (WxH). Default 32
–tu-intra-depth Max TU recursive depth for intra CUs. Default 1
–tu-inter-depth Max TU recursive depth for inter CUs. Default 1
–limit-tu <0…4> Enable early exit from TU recursion for inter coded blocks. Default 0**
12. 环路滤波
–[no-]deblock Enable Deblocking Loop Filter, optionally specify tC:Beta offsets Default enabled
–[no-]sao Enable Sample Adaptive Offset. Default enabled
–[no-]sao-non-deblock Use non-deblocked pixels, else right/bottom boundary areas skipped. Default disabled
–[no-]limit-sao Limit Sample Adaptive Offset types. Default disabled
13. VUI选项
–sar width:height|int Sample Aspect Ratio, the ratio of width to height of an individual pixel.
Choose from 0=undef, 1=1:1(“square”), 2=12:11, 3=10:11, 4=16:11,
5=40:33, 6=24:11, 7=20:11, 8=32:11, 9=80:33, 10=18:11, 11=15:11,
12=64:33, 13=160:99, 14=4:3, 15=3:2, 16=2:1 or custom ratio of int:int. Default 0
–display-window Describe overscan cropping region as ‘left,top,right,bottom’ in pixels
–overscan Specify whether it is appropriate for decoder to show cropped region: undef, show or crop. Default undef
–videoformat Specify video format from undef, component, pal, ntsc, secam, mac. Default undef
–range Specify black level and range of luma and chroma signals as full or limited Default limited
–colorprim Specify color primaries from bt709, unknown, reserved, bt470m, bt470bg, smpte170m,
smpte240m, film, bt2020, smpte428, smpte431, smpte432. Default undef
–transfer Specify transfer characteristics from bt709, unknown, reserved, bt470m, bt470bg, smpte170m,
smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1,
bt2020-10, bt2020-12, smpte2084, smpte428, arib-std-b67. Default undef
–colormatrix Specify color matrix setting from undef, bt709, fcc, bt470bg, smpte170m,
smpte240m, GBR, YCgCo, bt2020nc, bt2020c, smpte2085, chroma-derived-nc, chroma-derived-c, ictcp. Default undef
–chromaloc Specify chroma sample location (0 to 5). Default of 0
–master-display SMPTE ST 2086 master display color volume info SEI (HDR)
format: G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)
–max-cll Emit content light level info SEI as “cll,fall” (HDR)
–[no-]hdr Control dumping of HDR SEI packet. If max-cll or master-display has non-zero values, this is enabled. Default disabled
–[no-]hdr-opt Add luma and chroma offsets for HDR/WCG content. Default disabled
–min-luma Minimum luma plane value of input source picture
–max-luma Maximum luma plane value of input source picture
14. 比特流选项
–[no-]repeat-headers Emit SPS and PPS headers at each keyframe. Default disabled
–[no-]info Emit SEI identifying encoder and parameters. Default enabled
–[no-]hrd Enable HRD parameters signaling. Default disabled
–[no-]idr-recovery-sei Emit recovery point infor SEI at each IDR frame
–[no-]temporal-layers Enable a temporal sublayer for unreferenced B frames. Default disabled
–[no-]aud Emit access unit delimiters at the start of each access unit. Default disabled
–hash Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum. Default 0
–atc-sei Emit the alternative transfer characteristics SEI message where the integer is the preferred transfer characteristics. Default disabled
–pic-struct Set the picture structure and emits it in the picture timing SEI message. Values in the range 0…12. See D.3.3 of the HEVC spec. for a detailed explanation.
–log2-max-poc-lsb Maximum of the picture order count
–[no-]vui-timing-info Emit VUI timing information in the bistream. Default enabled
–[no-]vui-hrd-info Emit VUI HRD information in the bistream. Default enabled
–[no-]opt-qp-pps Dynamically optimize QP in PPS (instead of default 26) based on QPs in previous GOP. Default disabled
–[no-]opt-ref-list-length-pps Dynamically set L0 and L1 ref list length in PPS (instead of default 0) based on values in last GOP. Default disabled
–[no-]multi-pass-opt-rps Enable storing commonly used RPS in SPS in multi pass mode. Default disabled
–[no-]opt-cu-delta-qp Optimize to signal consistent CU level delta QPs in frame. Default disabled
15. DCT近似值
**16. Debug选项 **
-r/–recon Reconstructed raw image YUV or Y4M output file name
–recon-depth Bit-depth of reconstructed raw image file. Defaults to input bit depth, or 8 if Y4M
–recon-y4m-exec pipe reconstructed frames to Y4M viewer, ex:“ffplay -i pipe:0 -autoexit”
–lowpass-dct Use low-pass subband dct approximation. Default disabled