X264参考手册


本文转自: http://www.elesos.com/index.php?title=X264%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C


英文版官方原文:https://trac.ffmpeg.org/wiki/x264EncodingGuide



基本语法:

x264 [options] -o outfile infile

注意与ffmpeg的输入输出文件位置恰好相反:

ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}

输入

x264.exe --output NUL C:\input.avs
x264 --output /dev/null ~/input.y4m

当输入视频是原始YUV时,还必须指明分辨率。你可能也要使用--fps来指定帧率:

x264.exe --output NUL --fps 25 --input-res 1280x720 D:\input.yuv 
x264 --output /dev/null --fps 30000/1001 --input-res 640x480 ~/input.yuv

预设值Presets

为了减少使用者花费时间和精力在命令行上而设计的一套系统。

profile

默认值: not set

Limit the profile of the output stream. If you specify a profile, it overrides all other settings, so if you use it, you will be guaranteed a compatible stream. If you set this option, you cannot use lossless encoding (--qp 0 or --crf 0).

You should set this if you know your playback device only supports a certain profile. Most decoders support High profile, so there's no need to set this.

Values available: baseline, main, high, high10, high422, high444.

限制输出流的profile。这个参数将覆盖其它的设定,此选项能保证输出profile兼容的视频流。如果使用了这个选项,将不能进行无损压缩。

如果播放装置仅支援某个profile,则应该设此选项。大多数解码器都支援High profile,所以没有设定的必要。

建议:不设置。除非解码环境只支持main或者baseline profile的解码。

preset

默认值: medium

Change options to trade off compression efficiency against encoding speed. If you specify a preset, the changes it makes will be applied before all other parameters are applied.

You should generally set this option to the slowest you can bear.

Values available: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.

变更选项,以权衡压缩效率和编码速度。如果指定了preset,它会在其它选项生效前生效。

通常应该将此选项设为可接受的最慢值。

tune

默认值: 无

Tune options to further optimize them for your input content. If you specify a tuning, the changes will be applied after --preset but before all other parameters.

If your source content matches one of the available tunings you can use this, otherwise leave unset.

Values available: film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency.

在上一个选项基础上进一步优化输入。如果指定了一个tune值,它将在preset之后,其它选项之前生效。

建议:根据输入进行选择,如果视频的内容符合其中一个值,则可以使用此选项,如果没有合适的就不要指定。

slow-firstpass

默认值: Not Set

Using --pass 1 applies the following settings at the end of parsing the command line:

使用--pass 1会在解析命令列的最后增加以上设置。

You can set --slow-firstpass to disable this.

Note: --preset placebo enables --slow-firstpass.

使用--preset placebo也会启用--slow-firstpass.。

See also: --pass.

帧类型选项Frame-type options

keyint

默认值: 250

Sets the maximum interval between IDR-frames (又叫做keyframes) in x264's output. You can specify "infinite" to never insert non-scenecut IDR-frames.

IDR-frames are 'delimiters' in the stream - no frame can reference data from the other side of the IDR-frame. As well as this, IDR-frames are also I-frames, so they don't reference data from any other frame. This means they can be used as seek points in a video.

Note that I-frames are generally significantly larger than P/B-frames (often 10x or more in low motion scenes), so they can play havoc with ratecontrol when combined with aggressively low VBV settings (eg, sub-second buffer sizes). In these cases, investigate --intra-refresh.

The default setting is fine for most videos. When encoding for Blu-ray, broadcast, live streaming or certain other specialist scenarios you may require a significantly smaller GOP length (often ~1x fps).

设置x264输出中的最大IDR帧(亦称关键帧)间距。可以指定infinite让x264永远不要插入非场景变更的IDR帧。

IDR帧是视频流的“分隔符”,所有帧都不可以使用越过关键帧的帧作为参考帧。IDR帧是I帧的一种,它们不参照其它帧。这意味着它们可以作为视频的搜索(seek)点。

I帧通常明显大于P/B帧(在低动态场景通常为10倍大或更多),所以当它们与极低的VBV设定合并使用时会打乱码率控制。在这些情况下,请研究--intra-refresh。

这个选项可以设置IDR帧的最大间隔帧数(亦称最大图像组长度GOP)。较大的值将导致IDR帧减少(会用占用空间更少的P帧和B帧取代),也就同时减弱了参照帧选择的限制。较小的值导致减少搜索一个随机帧所需的平均时间。

建议:默认值(fps的10倍)对大多数视频都很好。如果在为蓝光、广播、直播流或者其它什么专业流编码,可能需要更小的GOP长度(通常等于帧率)。

See also: --min-keyint--scenecut--intra-refresh

min-keyint

默认值: auto (MIN(--keyint / 10,--fps))

Sets the minimum length between IDR-frames.

See --keyint for an explanation of IDR-frames. Very small keyint ranges can cause "incorrect" IDR-frame placement (for example, a strobing scene). This option limits the minimum length in frames after each IDR-frame before another can be placed.

The maximum allowed value for min-keyint is --keyint/2+1

建议: Default, or 1x your framerate.

设定IDR帧之间的最小长度。过小的keyint范围会导致“不正确的”IDR帧位置(例如闪屏场景)。此选项限制了IDR帧之间的最小距离。

min-keyint允许的最大值是--keyint/2+1。

建议:默认值,或者等于帧率

See also: --keyint--scenecut

no-scenecut

默认值: Not Set

Completely disables adaptive I-frame decision.完全关闭自适应I帧决策

See also: --scenecut

scenecut

默认值: 40

Sets the threshold for I/IDR frame placement (read: scene change detection).

x264 calculates a metric for every frame to estimate how different it is from the previous frame. If the value is lower than scenecut, a 'scenecut' is detected. An I-frame is placed if it has been less than --min-keyint frames since the last IDR-frame, otherwise an IDR-frame is placed. Higher values of scenecut increase the number of scenecuts detected. For more information on how the scenecut comparison works, see http://forum.doom9.org/showthread.php?t=121116.

Setting scenecut to 0 is equivalent to setting --no-scenecut.

建议: Default

设置使用I帧、IDR帧的阈值(场景变换检测)。

x264为每一帧计算一个度量值,来估计与前一帧的不同程度。如果该值低于scenecut,那么就算检测到一个“场景变换”。如果此时与前一个IDR帧的距离低于--min-keyint则插入一个I帧,否则放置一个IDR帧。越大的scenecut值会增加侦测到场景变更的次数。

See also: --keyint--min-keyint--no-scenecut

intra-refresh

默认值: Off

Disables IDR-frames, instead x264 uses intra coding for each macroblock in the frame every --keyint frames. Blocks are refreshed in a horizontally scrolling column - the 'refresh wave'. This benefits low-latency streaming by making it possible to achieve more constant frame sizes than is possible with standard IDR-frames. It also increases the resilience of the video stream to packet loss. This option does reduce compression efficiency, hence only use it when needed.

Fun facts:

  • The first frame is still an IDR frame.
  • Intra-blocks are placed only in P-frames - the refresh wave is wider in the first P-frame after one or more B-frames.
  • The loss in compression efficiency comes primarily from the fact macroblocks on the 'new' (left) side of the refresh wave can't refer to data on the 'old' (right) side.

停用IDR帧,作为替代x264会为每隔keyint数量的帧使用宏块内部编码。区块是以一个水平卷动的行刷新,称为刷新波。这有利于低延迟的流,使它有可能比标准的IDR帧达到更加固定的帧大小。它也增强了视频流对丢包的恢复能力。此选项会降低压缩效率,因此必要时才使用。

有趣的事:

  • 第一帧仍然是IDR帧。
  • 内部区块只在P帧中存在,刷新波在一个或多个B帧后的P帧中广泛存在。
  • 压缩效率的损失主要来自于在刷新波上左侧(新)的宏块无法参照右侧(旧)的宏块。

bframes

默认值: 3

Sets the maximum number of concurrent B-frames that x264 can use.

Without B-frames, a typical x264 stream has frame types like so: IPPPPP...PI. With --bframes 2, up to two consecutive P-frames can be replaced with B-frames, like: IBPBBPBPPPB...PI.

B-frames are similar to P-frames, except they can use motion prediction from future frames as well. This can lead to significantly better efficiency in terms of compression ratio. Their average quality is controlled by --pbratio.

Fun facts:

  • x264 also occasionally distinguishes between two different sorts of B-frames. A 'B' can refer to a B-frame that is used as a reference by other frames (see --b-pyramid, while 'b' can refer to a B-frame that is not. If you see a mix of 'B' and 'b', it's usually related to the above. When the difference is not important, just 'B' is generally used to refer to all B-frames.
  • For more information about the choices x264 makes between P or B frames for each candidate frame, see this ffmpeg-devel mail. In this case, frame types will look like this (in display order) (assuming --bframes 3): IBBBPBBBPBPI.

设置x264可使用的B帧的最大连续数量。

没有B帧时,一个典型的x264流帧类型是这样的:IPPPPP…PI。如果设置了-bframes 2,那么两个连续的P帧就可以用B帧替换,就像这样:IBPBBPBPPPB…PI。

B帧和P帧的区别在于它可以参照它之后的帧,这个特点让它可以显著地提升压缩率。他们的平均品质受 –pbratio选项的控制。

有趣的事:

  • 1、x264还区分两种不同类型的B帧。大写的"B"是可以被其他帧作为参照帧的B帧(参阅--b-pyramid),而"b"则代表一个不能被其他帧作为参照帧的B帧。如果看到一段混合的"B"和"b",原因通常与上述有关。当差别并不重要时,通常就以大"B"代表所有B帧。
  • 2、x264如何将每个候选帧选为P帧或B帧可参阅http://article.gmane.org/gmane.comp.video.ffmpeg.devel/29064。在此情况下,帧类型看起来会像这样(假设--bframes 3):IBBBPBBBPBPI。

See also: --no-b-adapt--b-bias--b-pyramid--ref--pbratio--partitions--weightb

b-adapt

默认值: 1

Set the adaptive B-frame placement decision algorithm. This setting controls how x264 decides between placing a P- or B-frame.

0. Disabled. Pick B-frames always. This is the same as what the older  no-b-adapt setting did.
1. 'Fast' algorithm, faster, speed slightly increases with higher  --b-frames setting. When using this mode, you basically always want to use  --bframes 16.
2. 'Optimal' algorithm, slower, speed significantly decreases with higher  --b-frames setting.

Note: For a multi-pass encode, this option is only needed for the first pass where frame types are decided.

设置B帧决策算法,此选项控制x264如何放置P帧或B帧。

  • 0 —— 关闭。总是使用B帧。和以前的 no-b-adapt选项效果相同;
  • 1 —— ‘快速’算法。较快,–b-frames值越大速度越快。当使用此模式时,建议搭配--bframes 16使用。
  • 2 —— ‘最佳’算法,较慢,–b-frames值越大速度越慢;

注意:多遍编码时,只有第一趟编码(first pass)才需要此选项,因为第一趟编码结束时,帧类型就已经被决定了

b-bias

默认值: 0

Controls the likelihood of B-frames being used instead of P-frames. Values greater than 0 increase the weighting towards B-frames, while values less than 0 do the opposite. This number is an arbitrary metric. The range is from -100 to 100. A value of 100/-100 does not guarantee every/no P-frame will be converted (use--b-adapt 0 for that).

Only use this if you think you make better ratecontrol decisions than x264.

控制使用B帧而不使用P帧的可能性。大于0的值增加偏向B帧的加权,而小于0的值则相反。此值是一个任意计量。范围从-100到100。100并不保证全是B帧(要全是B帧该使用--b-adapt 0),而-100也不保证全是P帧。

请只在你认为你能做出比x264更好的码率控制时才使用这个选项。

See also: --b-frames--ipratio

b-pyramid

默认值: normal

Allow the use of B-frames as references for other frames. Without this setting, frames can only reference I- or P-frames. Although I/P-frames are more valued as references because of their higher quality, B-frames can also be useful. B-frames designated as references will get a quantizer halfway between P-frames and normal B-frames. You need to use at least two B-frames before B-pyramid will work.

If you're encoding for Blu-ray, use 'none' or 'strict'.

  • none: do not allow B-frames to be used as references.
  • strict: allow one B-frame per minigop to be used as reference; enforces restrictions imposed by the Blu-ray standard.
  • normal: allow numerous B-frames per minigop to be used as references.

允许B帧作为其他帧的参照帧。没有此设定时,帧只能参照I/P帧。虽然I/P帧因其较高的品质作为参照帧更有价值,但B帧也是很有用的。作为参照帧的B帧会得到一个介于P帧和普通B帧之间的量化值。只有在--bframes设置大于等于2时此选项才生效。

如果是在为蓝光编码,须使用none或strict。

  • none:不允许B帧作为参照帧。
  • strict:每minigop只允许一个B帧作为参照帧,这是蓝光标准强制执行的限制。
  • normal:每minigop允许多个B帧作为参照帧。

See also: --bframes--refs--no-mixed-refs

open-gop

默认值: none

Open-GOP is an encoding technique which increases efficiency. Some decoders don't fully support open-GOP streams, which is why it hasn't been enabled by default. You should test with all decoders your streams will be played on, or (if that's impossible) wait until support is generally available.

open-gop的说明可以参阅http://forum.doom9.org/showthread.php?p=1300124#post1300124

Open-GOP是一个提升压缩效率的编码技术。某些解码器不完全支持open-gop流,这也是为什么它默认没有启用的原因。你应该测试所有可能用来播放此流的解码器。

no-cabac

默认值: Not set

Disables CABAC (Context Adaptive Binary Arithmetic Coder) stream compression and falls back to the less efficient CAVLC (Context Adaptive Variable Length Coder) system. Significantly reduces both the compression efficiency (10-20% typically) and the decoding requirements.

关闭CABAC (Context Adaptive Binary Arithmetic Coder)压缩,使用较为低效的CAVLC (Context Adaptive Variable Length Coder)。大幅降低压缩效率(通常10~20%)和解码的硬件需求。

ref

默认值: 3

Controls the size of the DPB (Decoded Picture Buffer). The range is from 0-16. In short, this value is the number of previous frames each P-frame can use as references. (B-frames can use one or two fewer, depending on if they are used as references or not.) The minimum number of refs that can be referenced is 1.

Also note that the H.264 spec limits DPB size for each level. If adhering to Level 4.1 specs, the maximum refs for 720p and 1080p video are 9 and 4 respectively. You can read more about levels and 4.1 in particular under --level.

控制解码图片缓冲(DPB:Decoded Picture Buffer)的大小。范围是从0到16。总之,此值设置每个P帧可以选择它之前的多少帧作为参照帧(B帧可以使用的数目要少一或两个,取决于它们是否作为参照帧)。可以被参照的最小ref数是1,即只参照自己前面的那帧。

需要注意的是,H.264规格限制了每个level的DPB大小。如果遵守Level 4.1规格,720p和1080p视频的最大ref数分别是9和4。


See also: --b-pyramid--no-mixed-refs--level

no-deblock

默认值: Not Set

Completely disables the loop filter. Not Recommended.完全停用循环滤镜。不建议。

See Also: --deblock

deblock

默认值: 0:0

Controls the loop filter (aka inloop deblocker), which is part of the H.264 standard. It is very efficient in terms of encoding time vs. quality gained.

You can find a good description of how the loop filter parameters work in this doom9 thread (看楼主和akupenguin的回复).

控制循环滤镜(亦称为内置去块滤镜),这是H.264标准的一部分。是个性价比很高的选项。

See Also: --no-deblock

slices

默认值: 0

Sets the number of slices per frame, and forces rectangular slices. (Overridden by either --slice-max-size or --slice-max-mbs if they are set.)

If you are encoding for Blu-ray, set this to four. Otherwise, don't use this unless you know you need to.

设置每帧的分片数,并且强制为矩形切片。

如果是在为蓝光编码,将值设为4。否则,不要使用此选项,除非你确定真的有必要。。

See Also: --slice-max-size--slice-max-mbs.

slice-max-size

默认值: 0

Sets the maximum slice size in bytes, including estimated NAL overhead. (Currently is not compatible with --interlaced.)

设定最大的切片大小(单位是字节),包括估计的NAL额外负荷。

See Also: --slices

slice-max-mbs

默认值: 0

Sets the maximum slice size in macroblocks. (Currently is not compatible with --interlaced.)

设置每个分片包含的最大宏块数量。

See Also: --slices

tff

Enable interlaced encoding and specify the top field is first. x264's interlaced encoding uses MBAFF, and is inherently less efficient than progressive encoding. For that reason, you should only encode interlaced if you intend to display the video on an interlaced display (or can't deinterlace the video before sending it to x264). Implies --pic-struct.

启用交错式(隔行)编码并指定顶场优先。x264的交错式编码使用MBAFF,本身效率不如逐行扫描。出于此原因,仅在需要在隔行显示的设备上显示时才开启此选项(或是送给x264之前无法进行反隔行扫描)。此选项会自动启用--pic-struct。

bff

Enable interlaced encoding and specify the bottom field is first. See --tff for more info.

no-interlaced

Forces x264 to output in progressive mode.

constrained-intra

默认值: Not Set

Enable constrained intra prediction, which is required for the base layer of SVC encodes. Since EveryoneTM ignores SVC you can likewise ignore this switch.

启用限制的内部预测,这是SVC编码的底层所需要的。既然每个人都忽略SVC,你也一样可以忽略此选项。

pulldown

默认值: none

Signal soft telecine for your (progressive, constant framerate) input stream using one of a few preset modes. Soft telecine is explained in more detail on theHandBrake wiki. The available presets are: none, 22, 32, 64, double, triple and euro.

Specifying any mode but none implies --pic-struct.

为你的输入流(逐行扫描的,固定帧率的)使用一组预设的“软性电视模式”。

除了none之外的选项都会自动启用--pic-struct。

fake-interlaced

默认值: Not Set

Mark a stream as interlaced even when not encoding as interlaced. Allows encoding of 25p and 30p Blu-ray compliant videos.

把流标志为隔行的但不按隔行编码。用于编码25p和30p的蓝光兼容视频。

frame-packing

默认值: Not Set

If you're encoding 3d video, this parameter sets a bitstream flag that tells your decoder how the 3d video was packed. The values and what they mean can be found in x264 --fullhelp.

如果你在编码3D视频,此参数设定一个位元流标志,用来告诉解码器此3D视频是如何封装的。

码率控制Ratecontrol

qp

默认值: Not Set

The first of three possible ratecontrol methods. Set x264 to encode the movie in Constant Quantizer mode. The number you give here specifies the P-frame quantizer. The quantizer used for I- and B-frames is derived from --ipratio and --pbratio. CQ mode targets a certain quantizer, which means final filesize is not known (although it can be reasonably accurately estimated with some methods). A setting of 0 will produce lossless output. qp produces larger files than --crf for the same visual quality. qp mode also disables adaptive quantization, since by definition 'constant quantizer' implies no adaptive quantization.

This option is mutually exclusive with --bitrate and --crf. See this article for more information on the various ratecontrol systems.

You should generally use --crf instead, although qp doesn't require lookahead to run and thus can be faster.

三种码率控制方法之一。设置x264以固定量化值模式编码视频。这里给的值将被作为P帧的量化值,I帧和B帧的量化值从ipratio和pbratio参数中取得。CQ模式把某个特定量化值作为目标,这意味着最终文件大小是未知的(虽然可以通过一些方法来准确地估计)。设置为0将产出无损输出。相同视觉质量时,QP模式产出的文件会比crf模式更大。QP模式将关闭自适应量化器,因为按照定义“固定量化值”意味着没有弹性量化。

这个选项和 bitrate和crf是互斥的,三者只能选一个。

一般而言crf都能代替QP模式,不过QP因为完全不需要预测所以它会运行得更快些。

See also: --bitrate--crf--ipratio--pbratio

bitrate

默认值: Not Set

The second of three ratecontrol methods. Encode the video in target bitrate mode. Target bitrate mode means the final filesize is known, but the final quality is not. x264 will attempt to encode the video to target the given bitrate as the overall average. The parameter given is the bitrate in kilobits/sec. (8bits = 1byte and so on). Note that 1 kilobit is 1000, not 1024 bits.

This setting is often used in conjunction with --pass for two-pass encoding.

This option is mutually exclusive with --qp and --crf.

三种码率控制方法之二。设置x264使用固定目标比特率模式来编码视频。目固定目标比特率意味着最终的文件大小是可知的,但是目标的质量是不可知的。x264会试图让最终文件的整体码率与给定的码率相等。参数的单位是kilobits/sec(8bits = 1byte字节)。

通常这个选项与pass选项配合进行2趟编码。

这个选项和qp和crf是互斥的,三者只能选一个。

See also: --qp--crf--ratetol--pass--stats

crf

默认值: 23.0

The final ratecontrol method: Constant Ratefactor. While qp targets a certain quantizer, and bitrate targets a certain filesize, crf targets a certain 'quality'. The idea is for crf n to give the same perceptual quality as qp n, just in a smaller space. The arbitrary unit of measure for crf values is the "ratefactor".

CRF achieves this by reducing the quality of 'less important' frames. In this context, 'less important' means frames in complex or high-motion scenes, where quality is either more expensive (in terms of bits) or less visible, will have their quantizer increased. The bits saved in frames like these are redistributed to frames where they will be more effective.

CRF will take less time than a 2pass bitrate encode, because the 'first pass' from a 2pass encode was skipped. On the other hand, it's impossible to predict the bitrate a CRF encode will come out to. It's up to you to decide which rate-control mode is better for your circumstances.

This option is mutually exclusive with qp and bitrate.

最后一种码率控制方法:固定码率系数。qp是把某个量化值作为目标,bitrate是把某个文件大小作为目标,而crf则是把某个“品质”作为目标。crf可以提供跟QP一样的视觉质量,但是文件更小。crf值的单位是“码率系数(ratefactor)”。

crf是通过降低那些“不那么重要”的帧的质量来达到此目的的。“不那么重要”的意思是那些过于耗费码率又难以用肉眼察觉的帧,比如复杂或者高速运行的场景。省下来的码率会用在其它更有效的帧里。

crf编码比2趟编码快,因为它相当于省略了第1趟编码。所以crf的最终码率也是不可预测的。你需要根据具体的应用场景来选择码率控制方式。

此选项与--qp和--bitrate互斥。

See also: --qp--bitrate

rc-lookahead

默认值: 40

Sets the number of frames to use for mb-tree ratecontrol and vbv-lookahead. The maximum allowed value is 250.

For the mb-tree portion of this, increasing the frame count generates better results but is also slower. The maximum buffer value used by mb-tree is the MIN( rc-lookahead, --keyint )

For the vbv-lookahead portion of this, increasing the frame count generates better stability and accuracy when using vbv. The maximum value used by vbv-lookahead is:

MIN(rc-lookahead, MAX(keyint, MAX(vbv-maxrate, bitrate) / vbv-bufsize * fps))

设定mb-tree码率率控制和vbv-lookahead可使用的帧数。最大允许值是250。

对于mb-tree而言,增加帧数会带来更好的效果但也会更慢。mb-tree使用的最大缓冲值是rc-lookahead和keyint中较小的那一个。

对于vbv-lookahead而言,当使用vbv时,增加帧数会带来更好的稳定性和准确度。

See Also: --no-mbtree--vbv-bufsize--vbv-maxrate--sync-lookahead

vbv-maxrate

默认值: 0

Sets the maximum rate the VBV buffer should be assumed to refill at.

VBV reduces quality, so you should only use this if you're encoding for a playback scenario that requires it.

设置VBV(Video Buffering Verifier)可用的最大码率。使用VBV会降低视频质量,只在真正需要的时候才设定它。

See also: --vbv-bufsize--vbv-init

vbv-bufsize

默认值: 0

Sets the size of the VBV buffer in kilobits.

VBV reduces quality, so you should only use this if you're encoding for a playback scenario that requires it.

See also: --vbv-maxrate--vbv-init

vbv-init

默认值: 0.9

Sets how full the VBV Buffer must be before playback starts.

If it is less than 1, the the initial fill is: vbv-init * vbv-bufsize. Otherwise it is interpreted as the initial fill in kbits.

设置在视频开始播放前VBV缓冲必须填满多少。

如果值小于1,初始的填满量是:vbv-init * vbv-bufsize。如果大于1,该值即是初始的填满量(单位是kbits)。

See also: --vbv-maxrate--vbv-bufsize

crf-max

默认值: Not set

A similar setting to --qpmax except instead of specifying a maximum quantizer you're specifying a maximum ratefactor. This option only works when you are using CRF and have VBV enabled. It prevents x264 from reducing the ratefactor (aka "quality") below the given value even when doing so would violate VBV constraints. This setting is mostly applicable to custom streaming servers. More information can be found here.

类似--qpmax,除了指定的是最大码率系数ratefactor而非最大量化值。这个选项仅在crf和vbv同时启用的时候有效。它阻止x264降低码率系数(亦称为“品质”)到低于给定的值,即使这样做会违反VBV的条件约束。此设定一般用于自定义的流服务器。

See Also: --crf--vbv-maxrate--vbv-bufsize

qpmin

默认值: 0

Defines the minimum quantizer that x264 will ever use. The lower the quantizer, the closer the output is to the input. At some point, the output of x264 will look the same as the input, even though it is not exactly the same. Usually there is no reason to allow x264 to spend more bits than this on any particular macroblock.

With adaptive quantization enabled (the default), raising qpmin is discouraged because this could reduce the quality of flat background areas of the frame.

定义x264可以使用的最小量化值。量化值越小,输出就越接近输入。到了一定的值,x264的输出看起来会跟输入一样,即使它并不完全相同。通常没有理由允许x264花费比这更多的比特数在任何特定的宏块上。

如果开启了自适应量化器(默认启用),不建议提高qpmin的值,因为这会降低帧里面平滑背景区域的品质。

See also: --qpmax--ipratio

qpmax

默认值: 51

The opposite of qpmin, above. Defines the maximum quantizer that x264 can use. The default of 51 is the highest quantizer available for use in the H.264 spec, and is extremely low quality. This default effectively disables qpmax. You may want to set this lower (values in the 30-40 range are generally as low as you'd go) if you want to cap the minimum quality x264 can output, but adjusting it is generally not recommended.

定义x264可以使用的最大量化值。默认值51是H.264规格中可供使用的最大量化值,而且品质极低。此默认值51相当于禁用qpmax。如果你想控制x264输出的最低品质,可以将此值设小一点(通常在30~40范围内),但通常并不建议调整此值。

See also: --qpmin--pbratio--crf-max

qpstep

默认值: 4

Sets the maximum change in quantizer between two frames.

设定两帧之间量化值的最大变更幅度。

ratetol

默认值: 1.0

This is a dual purpose parameter:

  • In 1-pass bitrate encodes, this settings controls the percentage that x264 can miss the target average bitrate by. You can set this to 'inf' to disable this overflow detection completely. The lowest you can set this is to 0.01. The higher you set this to the better x264 can react to complex scenes near the end of the movie. The unit of measure for this purpose is percent (eg, 1.0 = 1% bitrate deviation allowed).
Many movies (any action movie, for instance) are most complex at the climatic finale. As a 1pass encode doesn't know this, the number of bits required for the end is usually underestimated. A ratetol of inf can mitigate this by allowing the encode to function more like a --crf encode, but the filesize will blow out.
  • When VBV is activated (ie, you're specified --vbv-* options), this setting also affects VBV aggressiveness. Setting this higher allows VBV to fluctuate more at the risk of possibly violating the VBV settings. For this purpose, the unit of measure is arbitrary.

这个参数有两个目的:

  • 1、在1-pass编码时,这个参数控制x264可以偏离给定的平均目标比特率的百分比。可以设置为inf完全关闭码率溢出侦测。可以设定的最小值是0.01。较高的值可以让x264更好地处理影片结束部分的复杂场景。对于这个目的而言单位是百分比(1.0意味着允许1%的bitrate偏差)。

很多影片(比如动作片)在电影结尾时十分复杂。但1趟编码并不知道这一点,结尾所需的比特数通常被低估,往往到最后比特都已经用完了。将ratetol设为inf可以减轻这种情况,它允许编码器用类似–crf的方式工作,当然,文件大小会暴增。

  • 2、当开启了vbv时(只要使用了任何以–vbv-开头的选项就会开启),此设定也会影响VBV的强度。更高的值意味着在设定的vbv值上下允许更大的波动。在这个含义时,对于这个目的而言,可以使用任意的度量单位。

ipratio

默认值: 1.40

Modifies the target average increase in quantizer for I-frames as compared to P-frames. Higher values increase the quality of I-frames generated.

修改I帧量化值相比P帧量化值的目标平均增量。更高的值意味着更高的I帧质量

See also: --pbratio

pbratio

默认值: 1.30

Modifies the target average decrease in quantizer for B-frames as compared to P-frames. Higher values decrease the quality of B-frames generated. Not used with mbtree (enabled by default), which calculates the optimum value automatically.

修改B帧量化值相比P帧量化值的目标平均减量。更高的值意味着更低的B帧质量。当mbtree启用时(默认启用),此设定无作用,mbtree会自动计算最佳值。

See also: --ipratio

chroma-qp-offset

默认值: 0

Add an offset to the quantizer of chroma planes when encoding. The offset can be negative.

When using psy options are enabled (psy-rd, psy-trellis), x264 automatically subtracts 2 from this value to compensate for these optimisations overly favouring luma detail by default.

Note: x264 only encodes the luma and chroma planes at the same quantizer up to quantizer 29. After this, chroma is progressively quantized by a lower amount than luma until you end with luma at q51 and chroma at q39. This behavior is required by the H.264 standard.

在编码时增加色度平面量化值的偏移。偏移可以为负值。

当开启 psy-rd或 psy-trellis时,x264会自动将此值再减去2,降低色度的量化参数用于补偿亮度。 注意:x264仅在同一量化值编码亮度平面和色度平面,直到量化值29。在此之后,色度逐步以比亮度低的量进行量化,直到亮度为q51,色度为q39为止。此行为是由H.264标准所要求。

aq-mode

Adaptive Quantization Mode

默认值: 1

Without AQ, x264 tends to underallocate bits to less-detailed sections. AQ is used to better distribute the available bits between all macroblocks in the video. This setting changes what scope AQ re-arranges bits in:

  • 0: Do not use AQ at all.
  • 1: Allow AQ to redistribute bits across the whole video and within frames.
  • 2: Auto-variance AQ (experimental) which attempts to adapt strength per-frame.

自适应量化器模式。不使用自适应量化的话,x264趋向于使用较少的bit在缺乏细节的场景里。自适应量化可以在整个视频的宏块里更好地分配比特。它有以下选项:

  • 0 :完全关闭自适应量化器
  • 1 :允许自适应量化器在所有视频帧内部分配比特。
  • 2 :自动变化AQ,尝试对每帧调整强度。

See also: --aq-strength

aq-strength

Adaptive Quantization Strength

默认值: 1.0

Sets the strength of AQ bias towards low detail ('flat') macroblocks. Negative values are not allowed. Values outside the range 0.0 - 2.0 are probably a bad idea.

自适应量化强度。

设置自适应量化对于缺乏细节(平坦)的宏块的强度。不允许负值。0.0 – 2.0之外的值不推荐使用。 See also: --aq-mode

pass

默认值: Not Set

This is an important setting for 2pass encoding. It controls what x264 will do with the --stats file. It has three settings:

  • 1: Create a new stats file. Use this on the first pass.
  • 2: Read the stats file. Use this on the final pass.
  • 3: Read the stats file, and update it as well.

The stats file contains information about every input frame, which can be input to x264 in order to improve the output. The idea is you run a first pass to generate the stats file, and the second pass will create an optimized encode of the video. The improvement is mostly gained from better ratecontrol.

这是2趟编码的一个重要选项。它控制x264如何处理stats指定的文件。有三个设置:

  • 值为1 :建立一个新的stats文件,用于第一趟编码。
  • 值为2 :读取stats文件,用于最后一趟编码。
  • 值为3 :读取stats文件,并且更新它。

stats文件包含了每个输入帧的信息,x264可以读取这些信息来改善输出。你可以先跑第一趟编码生成stats文件,然后第二趟编码就可以使用这个文件优化编码。视频质量会得到很大的提升,大部分原因是因为进行了更好的码率控制。

See also: --stats--bitrate--slow-firstpass

stats

默认值: 'x264_2pass.log'

Set the location that x264 will read/write the --pass to/from.

设置x264读取和写入的stats文件名

See also: --pass

no-mbtree

默认值: Not Set

Disable macroblock tree ratecontrol. Using macroblock tree ratecontrol overall improves the compression by keeping track of temporal propagation across frames and weighting accordingly. Requires a new large statsfile in addition to the already existing for multipass encodes.

建议: Default

关闭基于宏块树的比特控制。基于宏块树的比特控制通过持续监控宏块在帧间的运动和相应权重来改善整体压缩率。除了已经存在的stats文件,它还会单独生成一个更大的stats文件。

See Also: --rc-lookahead

qcomp

默认值: 0.60

Quantizer curve compression factor. 0.0 => Constant Bitrate, 1.0 => Constant Quantizer.

When used with mbtree, it affects the strength of mbtree. (Higher qcomp = weaker mbtree).

建议: Default

量化值曲线压缩系数。0.0意味着恒定比特率,1.0意味着恒定量化值。

如果开启了mbtree,这个选项会影响mbtree的强度(更高的qcomp值意味着更弱的mbtree)。

See Also: --cplxblur--qblur

cplxblur

默认值: 20

Apply a gaussian blur with the given radius to the quantizer curve. This means that the quantizer assigned to each frame is blurred temporally with its neighbours to limit quantizer fluctuations.

以给定的半径范围套用高斯模糊于量化值曲线。这意味着分配给每个帧的量化值会被它的邻近帧模糊掉,以限制量化值的波动。

See also: --qcomp--qblur

qblur

默认值: 0.5

Apply a gaussian blur with the given radius to the quantizer curve, after curve compression. Not a very important setting.

在量化曲线压缩后,以给定的半径范围套用高斯模糊于量化值曲线。不是一个很重要的选项。

See also: --qcomp--cplxblur

zones

默认值: Not Set

Tweak settings for specific sections of the video. You can modify most x264 options per-zone.

  • A single zone takes the form of <start frame>,<end frame>,<options>
  • Multiple zones are separated from each other with a '/'


Options:

These two options are special. You can only set one per zone, and if you set one, it must be the first option listed for the zone:

  • b=<float> applies a bitrate multiplier on the zone. Useful for extra tweaking of high- and low-action scenes.
  • q=<int> applies a constant quantizer on the zone. Useful for applying to a range of frames.

调节视频的特殊片断。你可以修改每个片断的大多数x264选项。

  • 一个单独的zone使用<start frame>,<end frame>,<options>的形式表达。
  • 多个zone用’/'分隔。

选项:

以下2个选项是特殊选项,每个zone只能设置其中一个,此选项必须是zone列出来的第一个选项:

  • b=<float> 使zone内的bitrate乘上给定的系数。在调整快速和慢速场景时很有用。
  • q=<int> 使zone内使用给定的量化器。在应用于一段范围内的帧时很有用。

The other available options are as follows:

  • ref=<integer>
  • b-bias=<integer>
  • scenecut=<integer>
  • no-deblock
  • deblock=<integer>:<integer>
  • deadzone-intra=<integer>
  • deadzone-inter=<integer>
  • direct=<string>
  • merange=<integer>
  • nr=<integer>
  • subme=<integer>
  • trellis=<integer>
  • (no-)chroma-me
  • (no-)dct-decimate
  • (no-)fast-pskip
  • (no-)mixed-refs
  • psy-rd=<float>:<float>
  • me=<string>
  • no-8x8dct
  • b-pyramid=<string>
  • crf=<float>

Limitations:

  • The number of reference frames for a zone can never exceed what was specified with --ref
  • Scenecut can not be turned on and off; only varied if originally active (>0)
  • Merange can not exceed what was originally specified if --me esa/tesa
  • Subme can't be changed if the original commandline specified it as 0.
  • You can't set me to esa or tesa if --me was originally specified as dia, hex, or umh

Example: 0,1000,b=2/1001,2000,q=20,me=3,b-bias=-1000

限制:

  • 一个zone的参考帧数量不能超过ref定义的值。
  • 无法开启或关闭scenecut;如果scenecut最初为开启(>0),则只能改变scenecut的大小。
  • 如果使用--me esa/tesa,merange无法超过最初所指定的大小。
  • Subme如果原本被设置为0则不能修改。
  • 如果--me最初指定为dia、hex或umh,则无法将me设为esa或tesa。

建议: Default

qpfile

Manual override to standard ratecontrol. Specify a file that gives the quantizer and frametype for specified frames. The format is 'framenum frametype quantizer'. For example:

手动改变标准的码率控制方法。给定一个为指定的帧赋予量化值和帧类型的文件。格式是’帧序号 帧类型 量化值’

0 I 18 < IDR (key) I-frame
1 P 18 < P-frame
2 B 18 < Referenced B-frame
3 i 18 < Non-IDR (non-key) I-frame
4 b 18 < Non-referenced B-frame
5 K 18 < Keyframe*
  • You don't need to specify every frame
  • Using -1 as the desired quantizer allows x264 to choose the optimal quantizer value, useful when only needing to set the frametype
  • Having a large number of specified frame types and quantizers while still letting x264 choose intermittently decreases x264's performance
  • 'Keyframe' is a generic keyframe/seekpoint type that equates to a IDR I-Frame if --open-gop is none, otherwise it equates to a Non-IDR I-Frame flagged with the Recovery Point SEI
  • 不需要指定每个帧。
  • 使用-1作为量化值允许x264自行选择最佳的量化值,在只需设定帧类型时很有用。
  • 在指定了大量的帧类型和量化值时仍然让x264间歇地进行自行选择,会降低x264的性能。
  • "Keyframe"是一个泛用关键帧/搜寻点类型,如果--open-gop未启用则等同于一个IDR I帧,否则等同于一个加上Recovery Point SEI标志的非IDR的I帧。

Analysis

partitions

默认值: 'p8x8,b8x8,i8x8,i4x4'

H.264 video is split up into 16x16 macroblocks during compression. These blocks can be further split up into smaller partitions, which is what this option controls.

With this option, you enable individual partitions. Partitions are enabled per-frametype (i.e., I, P, B). The available partitions are p8x8, p4x4, b8x8, i8x8, and i4x4.

  • I: i8x8, i4x4
  • P: p8x8 (also enables p16x8/p8x16), p4x4 (also enables p8x4/p4x8)
  • B: b8x8 (also enables b16x8/b8x16)

You can also set 'none' or 'all'.

p4x4 is generally not very useful and has an extremely high ratio of speed cost to resulting quality gain.

H.264在压缩过程中会被切分为16×16大小的宏块。这些块可以进一步切分为更小的块,这就是此选项要控制的部分。

此选项可以启用个别分割。分割可以依不同帧类型(I、P、B)而启用。

一般而言,开启p4x4不会带来多少的质量提升,而且它极其耗时,是个性价比比较低的选项。

See also: --no-8x8dct

direct

默认值: 'spatial'

Set prediction mode for 'direct' motion vectors. There are two modes available: spatial and temporal. You can also select none to disable direct MVs, andauto to allow x264 to swap between them as it sees fit. If you set auto, x264 outputs information on the usage at the end of the encode. 'auto' works best in a 2pass encode, but will work in single-pass encodes too. In first-pass auto mode, x264 keeps a running average of how well each method has so far performed, and picks the next prediction mode from that. Note that you should only enable auto on the second pass if it was enabled on the first pass; if it wasn't, the second pass will default to temporal. Direct none wastes bits and is strongly discouraged.

建议: 'auto'

为’direct’类型的运动矢量设定预测模式。有两种模式可用:空间预测时间预测。你也可以设置为’none’关闭预测,或者设置为’auto’让x264在两者之间切换为适合的模式。如果设为auto,x264会在编码结束时告诉你它的选择。’auto’最好在2趟编码中使用,但也可以在1趟编码时使用。

在第一阶段auto模式,x264持续记录每个方法执行到目前为止的好坏,并从该记录挑选下一个预测模式。

注意,如果第1趟编码时选择了’auto’,那么第2趟编码时也必须设置为’auto’。不然,第2趟编码会使用’temporal’。none模式会浪费比特数,因此强烈不建议。

no-weightb

默认值: Not Set

H.264 allows you to 'weight' references in B-frames, which allows you to change how much each reference affects the predicted picture. This disables that feature.

建议: Default

H.264允许给可参考B帧加上影响预测图像的权重,此选项会关闭此特性。

weightp

默认值: 2

Enables use of explicit weighted prediction to improve compression in P-frames. Also improves quality in fades. Higher modes are slower.

NOTE: When encoding for Adobe Flash set this to 1 - its decoder generates artifacts otherwise. Flash 10.1 fixes this bug.

Modes:

  • 0. Disabled.
  • 1. Simple: fade analysis, but no reference duplication.
  • 2. Smart: fade analysis and reference duplication.

开启明确的权重预测以提高P帧压缩。同时也能改善淡入淡出的品质。越高级的模式越耗时,有以下模式:

  • 为0时:停用。
  • 为1时:简易:分析淡入/淡出,但不分析重复参照帧。
  • 为2时:智慧:分析淡入/淡出和重复参照帧

注意:在为Adobe Flash编码时,请将此值设为1,否则它的解码器会产生不自然痕迹。Flash 10.1修正了此bug。

me

默认值: 'hex'

Set the full-pixel motion estimation method. There are five choices:

  • dia (diamond) is the simplest search, consisting of starting at the best predictor, checking the motion vectors at one pixel upwards, left, down, and to the right, picking the best, and repeating the process until it no longer finds any better motion vector.
  • hex (hexagon) consists of a similar strategy, except it uses a range-2 search of 6 surrounding points, thus the name. It is considerably more efficient than dia and hardly any slower, and therefore makes a good choice for general-use encoding.
  • umh (uneven multi-hex) is considerably slower than hex, but searches a complex multi-hexagon pattern in order to avoid missing harder-to-find motion vectors. Unlike hex and dia, the merange parameter directly controls umh's search radius, allowing one to increase or decrease the size of the wide search.
  • esa (exhaustive) is a highly optimized intelligent search of the entire motion search space within merange of the best predictor. It is mathematically equivalent to the bruteforce method of searching every single motion vector in that area, though faster. However, it is still considerably slower than UMH, with not too much benefit, so is not particularly useful for everyday encoding.
  • tesa (transformed exhaustive) is an algorithm which attempts to approximate the effect of running a Hadamard transform comparison at each motion vector; like exhaustive, but a little bit better and a little bit slower.

设定全像素动态估算方法。有5种选择:

  • dia(四边形搜索):最简单的搜寻方法,起始于最佳预测器,在运动矢量的上下左右分别偏移一个像素进行对比,选择其中最好的一个,重复此过程直到找不到更好的运动矢量为止。
  • hex(六边形搜索):和菱形差不多的策略,不同的是,它在6边形的6个顶点上进行范围为2的搜索,它比dia更有效率且几乎没有变慢,因此作为一般用途的编码是个不错的选择。
  • umh(不均匀的多六边形搜索):比hex更慢,但它尝试进行复杂多六边形的搜索,以避免错过那些难以找到的运动矢量。不像hex和dia,merange参数可以直接控制umh的搜寻半径,允许增加或减少广域搜寻的大小。
  • esa(全局搜索):高度优化的全局智能搜索,在最佳预测器的merange范围内进行运动搜索。数学上相当于搜寻该区域每个单一动态向量的暴力方法,因此速度较快。不过,它仍然比umh还要慢,而且没有带来很大的好处,所以对于日常的编码不是特别有用。
  • tesa(变换全局搜索):一种算法,效果接近对每个运动矢量进行Hadamard变换比对。搜索方式上和esa很像,但是效果比esa好一点点,耗时也多一点点。

See also: --merange

merange

默认值: 16

merange controls the max range of the motion search in pixels. For hex and dia, the range is clamped to 4-16, with a default of 16. For umh and esa, it can be increased beyond the default 16 to allow for a wider-range motion search, which is useful on HD footage and for high-motion footage. Note that for umh, esa, and tesa, increasing merange will significantly slow down encoding.

Extremely high merange (e.g. >64) is unlikely to find any new motion vectors that are useful, so it may very slightly decrease compression in some cases by picking motion vector deltas so large that they even worsen prediction of future motion vectors in the rare cases they're locally useful, making them worse than useless.

The effect is so small as to be near-negligible, though, and you shouldn't be using such insane settings.see this post

merange控制运动搜索的最大像素范围。对于hex和dia,范围在4-16像素,默认为16。对于umh和esa,可以超过默认的16像素进行大范围的运行搜索,这对HD视频和高动态镜头而言很有用。注意,对于umh、esa和tesa,增加merange会大幅减慢编码速度。

极大的merange(如>64)不大可能找到任何有用的动态向量,所以在某些情况下它可能会轻微地降低压缩效率。

See also: --me

mvrange

默认值: -1 (auto)

Set the maximum (vertical) range of any one motion vector in pixels. The default value is level-dependent:

  • Level 1/1b: 64
  • Level 1.1-2.0: 128
  • Level 2.1-3.0: 256
  • Level 3.1+: 512

Note: if you want to manually override the mvrange, subtract 0.25 from the above values when setting (eg --mvrange 127.75).

设定动态向量的最大(垂直)范围(单位是像素)。默认值依level不同而不同。

注意:如果你想要手动覆写mvrange,在设定时请从上述值减去0.25(例如--mvrange 127.75)。

建议: Default

mvrange-thread

默认值: -1 (auto)

Set the minimum motion vector buffer between threads. Don't touch it.

建议: Default

设置线程间运动矢量缓冲区大小的最小值。不要碰这个选项。

subme

默认值: 7

Set the subpixel estimation complexity. Higher numbers are better. Levels 1-5 simply control the subpixel refinement strength. Level 6 enables RDO for mode decision, and level 8 enables RDO for motion vectors and intra prediction modes. RDO levels are significantly slower than the previous levels.

Using a value less than 2 will enable a faster, and lower quality lookahead mode, as well as cause poorer --scenecut decisions to be made, and thus it is not recommended.

Possible Values:

0. fullpel only
1. QPel SAD 1 iteration
2. QPel SATD 2 iterations
3. HPel on MB then QPel
4. Always QPel
5. Multi QPel + bi-directional motion estimation
6. RD on I/P frames
7. RD on all frames
8. RD refinement on I/P frames
9. RD refinement on all frames
10. QP-RD (requires  --trellis=2,  --aq-mode > 0)
11. Full RD  [1] [2]

设定子像素估算复杂度。值越大越好。层级1到5只是控制子像素细分强度。级别6给模式决策开启RDO(码率失真优化模式),级别8给运动矢量和帧内预测模式开启RDO。开启RDO会比之前的级别更加耗时。

使用小于2的值不但会启用较快且品质较低的lookahead模式,而且会导致较差的scenecut决策,因此不建议。

建议: Default, or higher, unless speed is very important.

subq

Alias of --subme

psy-rd

默认值: 1.0:0.0

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.

See this thread on doom9 for an explanation of psy-rd.

Life is short, and this article saved valubale time on this Earth.

第1个数字是psy-RDO的强度(subme大于等于6时激活)。第2个数字是Psy-Trellis的强度(trellis大于等于1时激活)。注意Trellis的特性仍是’实验性’的,至少对于动画视频来说它是不适合使用的。

no-mixed-refs

默认值: Not Set

Mixed refs will select refs on a per-8x8 partition, rather than per-macroblock basis. This improves quality when using multiple reference frames, albeit at some speed cost. Setting this option will disable it.

建议: Default

混合参照会以每个8x8分割为基础来选取参照,而不是以每个宏区块为基础。当使用多个参照帧时这会改善品质,但要损失一些速度。设定此选项会停用该功能。

See also: --ref

no-chroma-me

默认值: Not Set

Normally, motion estimation works off both the luma and chroma planes. This disables chroma motion estimation for a small speed boost.

建议: Default

通常运动估计都会同时考虑亮度和色度因素。开启此选项将会忽略色度因素以换取一些速度的提升。

no-8x8dct

默认值: Not Set

Adaptive 8x8 DCT enables the intelligent adaptive use of 8x8 transforms in I-frames. This disables the feature.

建议: Default

自适应的8×8离散余弦转换会在I帧中开启更智能的自适应8×8时域变换。开启此选项可以禁用这个特性。(注:此选项是将H.264的Profile从High降为Main的重要参数)

trellis

默认值: 1

Performs Trellis quantization to increase efficiency.

0. Disabled
1. Enabled only on the final encode of a macroblock
2. Enabled on all mode decisions

On Macroblock provides a good compromise between speed and efficiency. On all decisions reduces speed further.

See: Trellis Quantization

建议: Default

Note: Requires --cabac

使用网格编码量化来提高效率:

  • 0:停用。
  • 1:只在一个宏区块的最终编码上启用。
  • 2:在所有模式决策上启用。

选项1提供了速度和效率间较好的均衡,选项2大幅降低速度。注意:需要开启cabac选项

no-fast-pskip

默认值: Not Set

Disables early skip detection on P-frames. At low bitrates, provides a moderate quality increase for a large speed cost. At high bitrates, has negligible effect on both speed and quality.

建议: Default

关闭P帧的早期跳过侦测。在低码率时,适中地提高品质但要损失很多速度。在高码率时,对速度和品质的影响都微不足道。

no-dct-decimate

默认值: Not Set

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.

建议: Default

DCT抽样会丢弃它认为“不必要的DCT块。这会改善编码效率,通常质量损失可以忽略。此选项关闭此特性。

nr

默认值: Not Set

Performs fast noise reduction. Estimates film noise based on this value and attempts to remove it by dropping small details before quantization. This may not match the quality of a good external noise reduction filter, but it performs very fast.

建议: Default or (100 to 1000 for denoising)

执行快速去噪。根据此值估算影片的噪声,并通过在量化前舍弃小细节来尝试去除噪音。效果可能不如优秀的外部去造滤镜,但它执行得非常快。

deadzone-inter/intra

默认值: Not Set

Set the size of the inter/intra luma quantization deadzone. Deadzones should be in the range of 0 to 32. The deadzone value sets the level of fine detail that x264 will arbitrarily drop without attempting to preserve. Very fine detail is both hard to see and expensive to encode, dropping this detail without attempting to preserve it stops wasting bits on such a low-return section of the video. Deadzone is incompatible with Trellis.

建议: Default

设置帧间/帧内亮度量化器的盲区大小。盲区的范围应该在0-32,此值设定x264会任意舍弃而不尝试保留细微细节的级别。非常细微的细节既难以发觉,编码代价又昂贵,丢弃它们可以避免在这些低回报的部分浪费比特数。此选项和Trellis选项不相容。

cqm

默认值: Flat (Not Set)

Sets all custom quantization matrices to those of a built-in preset. The built-in presets are flat or JVT.

建议: Default

See also: --cqmfile

为内建的预设设定所有自定义的量化矩阵。内建的预设有flat和JVT。

cqmfile

默认值: Not Set

Sets custom quantization matrices from a specified JM-compatible file. Overrides any other --cqm* options.

建议: Default

使用一个JM格式矩阵文件设置自定义的量化矩阵。会覆盖其他以cqm开头的选项。

See also: --cqm

cqm4* / cqm8*

默认值: Not Set

  • --cqm4: Set all 4x4 quant matrices. Takes a comma-separated list of 16 integers.设定所有4x4量化矩阵。需要16个以逗号分隔的整数(1-255)清单。
  • --cqm8: Set all 8x8 quant matrices. Takes a comma-separated list of 64 integers.设定所有8x8量化矩阵。需要64个以逗号分隔的整数清单。
  • --cqm4i--cqm4p--cqm8i--cqm8p: Set both luma and chroma quant matrices 同时设置色度和亮度(i为帧内、p为帧间)矩阵
  • --cqm4iy--cqm4ic--cqm4py--cqm4pc: Set individual quant matrices. Same switches exist for cqm8.设置色度或亮度矩阵(y为亮度、c为色度),这样的参数cqm8也有同样的4个。

建议: Default

视频可用性信息Video Usability Info

These options set a flag in the output stream that can be read by the decoding application and possibly acted on. It's worth noting that most of these options in most scenarios are pointless, and are usually ignored by software decoders.

这些选项在输出流里设定一个标记,标记可以被解码器读取并采取可能的动作。在大多数场景中这些参数都没什么意义,而且经常被解码器所忽略。

overscan

默认值: undef

How to handle overscan. Overscan is used here in the sense of a device only displaying part of an image.

如何处理溢出扫描。溢出扫描的意思是装置只显示图像的一部分。(注:溢出扫描技术本用在阴极射线管显示器中为保持画面完整。)

Possible Values:

  • undef - Undefined.
  • show - Indicate to show the entire image. Theoretically must be respected if set.显示全部图像。理论上如果设了此值则解码器必须遵守。
  • crop - Indicate that the image is suitable for playback on devices with overscan. Not necessarily respected.指示此影像适合在有溢出扫描功能的装置上播放。解码器不一定遵守。

建议: Crop before encoding and use show if your device supports it, otherwise ignore.

如果你的设备支持此选项,建议在编码之前对视频进行裁剪然后设置为show。如果不支持就别管此选项了。

videoformat

默认值: undef

Indicates what the video was before encoding/digitizing.

Possible Values:

  • component
  • pal
  • ntsc
  • secam
  • mac
  • undef

建议: Whatever your source video was, or undefined.

指示此视频在 编码/数字化 之前是什么格式。

建议:设为原视频的格式,或者设为undef

range

默认值: auto

Indicates whether the output range of luma and chroma levels should be limited or full. If set to TV, the limited ranges will be used. If set to auto, use the same range as input.
NOTE: If range and --input-range differ, then a range conversion will occur!如果range和--input-range不同,则会进行范围转换。

See this pagefor a simple description.

建议: Default.

指示亮度和色度级别的输出范围是有限范围还是全范围。如果设为TV,则会使用有限范围。如果设为auto,则会使用与输入相同的范围。

See also: --input-range

colorprim

默认值: undef

Set what color primaries for converting to RGB.设置转换到RGB的原色

Possible Values:

  • undef
  • bt709
  • bt470m
  • bt470bg
  • smpte170m
  • smpte240m
  • film

See: RGB and YCrCb

建议: Default, unless you know what your source uses.

transfer

默认值: undef

Set the opto-electronic transfer characteristics to use. (Sets the gamma curve to use for correction.)设定要使用的光电子传输特性(设置用于修正的伽马曲线)。

Possible Values

  • undef
  • bt709
  • bt470m
  • bt470bg
  • linear
  • log100
  • log316
  • smpte170m
  • smpte240m

See: Gamma Correction

建议: Default, unless you know what your source uses.

colormatrix

默认值: undef

Set the matrix coefficients used in deriving the luma and chroma from the RGB primaries.

Possible Values

  • undef
  • bt709
  • fcc
  • bt470bg
  • smpte170m
  • smpte240m
  • GBR
  • YCgCo

设置用于从RGB原色中提取亮度和色度的矩阵系数。

See: YCbCr

建议: Whatever your sources uses, or default.源使用的矩阵,或者默认值。

chromaloc

默认值: 0

Sets the chroma sample location. (as defined in Annex E of the ITU-T Specification).

设定色度采样位置

Values range from 0 to 5.

See x264's vui.txt

建议:

  • If you transcode from MPEG1 with proper subsampled 4:2:0, and don't do any color space conversion, you should set this option to 1.如果你以MPEG1源为输入做4:2:0采样的转码,而且没作任何色彩空间转换,应该设置为1;
  • If you transcode from MPEG2 with proper subsampled 4:2:0, and don't do any color space conversion, you should set this option to 0.
  • If you transcode from MPEG4 with proper subsampled 4:2:0, and don't do any color space conversion, you should set this option to 0.
  • Otherwise, default.

nal-hrd

默认值: None

Signal HRD information. Required for Blu-ray streams, television broadcast and a few other specialist areas. Acceptable values are:

  • none Specify no HRD information
  • vbr Specify HRD information
  • cbr Specify HRD information and pack the bitstream to the bitrate specified by bitrate. Requires bitrate mode ratecontrol.设置HRD信息,而且把流限制在bitrate参数定义的码率内。需要bitrate码率控制方式。

建议: none, unless you need to signal this information.

设置HRD信息。用于蓝光流、电视广播和其他一些特殊场合。

See also: --vbv-bufsize--vbv-maxrate--aud

pic-struct

默认值: Not Set

Force sending pic_struct in Picture Timing SEI.

Implied when you use --pulldown or --tff/--bff.

强制按照图像时序SEI传送pic_struct。当使用--pulldown或--tff/--bff时会自动启用。

建议: Default

crop-rect

默认值: Not Set

Specify a bitstream-level cropping rectangle. You can use this if you want the decoder to crop on playback, but don't want to crop the video x264 encodes for some reason. Specify the value in pixels that should be cropped on playback.

指定一个比特流级的裁剪矩形。如果想要解码器在播放时裁剪,但因为某些原因不想要裁剪视频再让x264编码,则可以使用此选项。指定的值是在播放时应该被裁剪的像素值。

输入输出Input/Output

output

默认值: Not Set.

Specifies output filename. The extension you specify determines the output format of your video. If the extension is not recognised the default output format is the raw video stream (generally stored with the .264 extension).

The special location NUL (Windows) or /dev/null (Unix) specifies the output should be discarded. This is particularly useful when using --pass 1, as the only output you care about is that from --stats.

指定输出文件名。由文件的扩展名决定视频的输出格式。如果扩展名无法识别则默认采用 raw 格式(通常以.264后缀进行存储)。

特殊的文件名 NUL (Windows)或者 /dev/null (Unix)表示丢弃输出内容。当使用 pass 1 时特别有用,因为你唯一关心的输出来自 stats。

muxer

默认值: auto

Specifies what format to write to.指定输出格式。

Possible Values

  • auto
  • raw
  • mkv
  • flv
  • mp4

The 'auto' option will pick a muxer based on the supplied output filename.

‘auto’选项将根据提供的文件名选择相应的封装器。

See also: --output

建议: Default

demuxer

默认值: Automatically detected.

Sets what demuxer and decoder x264 uses for parsing the input video.

Possible Values

  • auto
  • raw
  • y4m
  • avs
  • lavf
  • ffms

If the input file has an extension of raw, y4m or avs, x264 will use the relevant demuxer to read the file. Standard input uses the raw demuxer. Otherwise, x264 will attempt to open the file with ffms, then lavf, and then fail.

The 'lavf' and 'ffms' options require x264 to be compiled with the respective libraries. If either is used, x264 will carry over the timecodes from the input file, provided you don't output to raw. This effectively makes x264 VFR-aware. The other options can have a constant framerate specified with --fps or a variable framerate with --tcfile-in.

指定x264用于分析输入视频的解封装器和解码器。

如果输入文件为raw、y4m 或 avs,x264会使用相应的解封装器读取文件。标准输入使用raw解封装器。否则,x264 将依次尝试使用 ffms, lavf 来打开文件,直至最终失败。

‘lavf’和‘ffms’参数需要用其它的库文件编译x264。如果使用两者之一,而且输出不是raw 的话,x264会从输入文件中带入时间码。这将使x264有效的感知VFR。其它选项可以通过指定--fps为固定帧率,或者通过指定--tcfile-in为可变帧率。

See also: --input--muxer

建议: Default.

input-csp

默认值: i420

Tell x264 what colourspace your raw video input is with this switch. Supported colourspaces are listed in x264 --fullhelp.

告诉x264视频源的色彩空间。注意:当指定为 RGB 色彩空间时,视频在压缩前会按 bt601 矩阵转换为 YUV。

See Also: --input-res--fps

output-csp

默认值: i420

Tell x264 what colourspace you want out. Supported colourspaces are listed in x264 --fullhelp.

Possible Values

  • i420
  • i422
  • i444
  • rgb

告诉x264要输出什么色彩空间。

See Also: --input-csp

input-range

默认值: auto

Indicates the source's range of luma and chroma levels. Can be set to TV for limited ranges or PC for full ranges.
NOTE: If --range and input-range differ, then a range conversion will occur!

建议: Default, unless you know if your source is TV or PC levels.

指定源的亮度和色度层级范围。可以为TV设定为有限范围或为PC设定为全范围。

注意:如果--range和input-range不同,则会进行范围转换。

建议:默认值,除非你知道源是TV或PC层级

See also: --range

input-res

Specify the input resolution of raw video input. Use the syntax --input-res 720x576.

为raw格式输入视频指定分辨率。

See Also: --input-csp--fps

index

默认值: Not Set

An optional setting that only takes effect when using the ffms --demuxer. Specifies a file for ffms to write out indexing data for the input file to, which can be referred to in a future encode to remove the need to reindex the video. Generally not needed -- indexing is not a slow process relative to video encoding.

See also: --demuxerFFMS2 API Documentation

一个仅在使用 ffms --demuxer 时才起作用的可选设置。为 ffms 指定一个用于为输入文件建立索引数据的文件,以后编码的时候可以省去再次建立索引的时间。通常不需要,因为相对于编码来说索引非常快。

建议: Default, unless you want to save a minute amount of time indexing.默认值,除非想节省建立索引的几分钟时间

sar

默认值: Not Set

Specifies the input video's Sample Aspect Ratio (SAR) to be used by the encoder in width:height.

This in conjunction with frame dimensions can be used to encode an anamorphic output by determining the Display Aspect Ratio (DAR) via the formula: DAR = SAR x width/height

See Main Article here

建议: You might need to set this if you're using the resize filter and encoding with anamorphic input.

以“宽:高”格式指定编码器使用的输入视频的采样纵横比。

综合SAR 和帧尺寸可以编码依赖显示纵横比的变形输出,公式为:DAR = SAR x width/height

建议:如果使用 resize 滤镜和变形视频源的话,应该指定。

“可变形”是种特殊应用,可参考细说DVD的画面比例

fps

默认值: autodetected

Specifies video framerate as either a float (29.970) a rational (30000/1001), or an integer (2997/100) value. x264 detects and uses the framerate from the input stream header when available (y4m, avs, ffms and lavf demuxer), otherwise uses 25. Setting this implies --force-cfr.

If you are using raw YUV input and --bitrate-based ratecontrol, you need to specify the correct framerate using this parameter or --tcfile-in. x264 won't hit your target bitrate otherwise.

以浮点数(29.970)、有理数(30000/1001)或整数(2997/100)值指定视频的帧率。当使用y4m、avs、ffms或lavf解封装器时,x264会使用从输入流头部侦测到的帧率,否则使用25作为帧率。设定此选项会自动启用--force-cfr。

如果正在使用 raw YUV 视频源并且基于 --bitrate 码率控制,需要通过此选项或 -tcfile-in来指定正确的帧率。否则,x264 无法达到设定的码率目标。

seek

默认值: Not Set

Specifies the first frame to encode, allowing the encode to begin at any point in the source.

指定要编码的初始帧,允许从视频源的任意位置开始编码。

建议: Default

frames

默认值: Not Set

Specifies the maximum number of frames to encode, allowing the encode to finish at any point before the end of the source.

指定要编码的最大帧数,允许在视频源结束前的任意位置终止编码。

建议: Default

level

默认值: -1 (auto)

Sets the level flag in the output bitstream (as defined by Annex A of the H.264 standard). Permissible levels are:

1 1b 1.1 1.2 1.3 2 2.1 2.2 3 3.1 3.2 4 4.1 4.2 5 5.1

If you do not specify --level on the commandline, x264 will attempt to autodetect the level. This detection is not perfect and may underestimate the level if you are not using VBV. x264 will also automatically limit the DPB size (see --ref) to remain in compliance with the level you select (unless you also manually specify --ref). Note: specifying the level does not automatically set the --vbv-maxrate or --vbv-bufsize, however it will warn if the level specific properties are exceeded.

What Level Do I Pick?

Level 4.1 is often considered the highest level you can rely on desktop consumer hardware to support. Blu-ray Discs only support level 4.1, and many non-mobile devices like the Xbox 360 specify level 4.1 as the highest they officially support. Mobile devices like the iPhone/Android are a totally different story.

Wikipedia has a nice chart detailing the restrictions for each level, if you want to read it.

建议: Default, unless you are aiming for a specific device.

在输出流中设定等级标志。

如果在命令行中没有指定--level,x264会尝试自动侦测level。此侦测并不完美,而且如果没有使用VBV则可能会低估level。x264也会自动限制DPB的大小来保持与所选level相匹配(除非你也手动指定--ref)。

注意:指定level并不会自动设定--vbv-maxrate或--vbv-bufsize,但是如果它们的参数超过设定的等级会告警。

如何选择等级?

Level 4.1 常常是桌面型硬件能支持的最高等级。蓝光碟仅支持 Level 4.1,许多非手机类设备,像 Xbox 360,指定 Level 4.1 为其官方支持的最高等级。手机设备,像 iPhone/Android 则是完全不同的处理方式。

建议: Default,除非是为一个特定设备编码。

bluray-compat

默认值: Not set

Modify x264's options to ensure better compatibility with all Blu-Ray players. Only neccessary if your video will be played by Blu-Ray hardware players.

This setting makes some option changes:

修改x264的选项以保证与蓝光播放机有更好的兼容性。仅当你的视频在蓝光机上播放时才需要此选项。

此设定变更一些选项:

  • 限制--weightp不超过1
  • 设定--min-keyint为1
  • 停用--intra-refresh等等

It also enables some internal x264 hacks to produce more hardware-player-friendly streams. For example:

  • GOP/mini-GOP tweaks to size and reference lists.
  • More verbose slice headers

它也启用了x264内部的一些特殊处理

建议: Set if you're encoding for hardware Blu-Ray players.默认值,除非针对蓝光播放机。

verbose

默认值: Not Set

Displays statistics for each encoded frame.

显示每个已编码帧的统计信息。

建议: Default

no-progress

默认值: Not Set

Disables the progress indicator while encoding.

编码时关闭进度指示器。

建议: Default

quiet

默认值: Not Set

Enables Quiet Mode, silencing status messages from x264.

启用安静模式,使x264不显示状态讯息。

建议: Default

log-level

默认值: info

Manually specify the logging level of both x264cli and libx264.

手动设定x264cli和libx264的日志等级。

Possible Values

  • none
  • error
  • warning
  • info
  • debug

越往下,日志信息越详细。

建议: Default

psnr

默认值: Not Set

Enables PSNR calculations that are reported on completion at the cost of a small decrease in speed.

开启 PSNR 计算,会在编码完成后给出报告,会略微降低一些速度。

建议: Default

ssim

默认值: Not Set

Enables SSIM calculations that are reported on completion at the cost of a small decrease in speed.

开启SSIM 计算,会在完成后给出报告,会略微降低一些速度。

建议: Default

threads

默认值: auto (frame based threads: 1.5 * logical processors, rounded down; slice based threads: 1 * logical processors)

Enables parallel encoding by using more than 1 thread to increase speed on multi-core systems. The quality loss from multiple threads is mostly negligible unless using very high numbers of threads (say, above 16). The speed gain should be slightly less than linear until you start using more than 1 thread per 40px of vertical video, at which point the gain from additional threads sharply decreases.

x264 currently has an internal limit on the number of threads set at 128, realistically you should never set it this high.

建议: Default

默认:auto (基于帧的线程数:1.5x逻辑处理器数,向下舍入取整;基于分片的线程数:1x逻辑处理器数)

在多核处理器上通过开启多线程并行编码以加快速度。质量损失可以忽略不计,除非使用非常多的线程(比如超过16个)。速度增长和线程的数量近似于线性,直到视频垂直方向每40px多于1个线程为止,超过临界点后再增加线程数所获得的速度增长将大幅下降。

当前在 x264 内部对线程数量限制为128,实际上你不应该设置这么高。

See also: --sliced-threads--thread-input

sliced-threads

默认值: off

Enables slice-based threading. This threading method produces lower quality results than the default method both compression and efficiency-wise, but adds no encoding latency.

开启基于分片的线程。比默认方式的质量和效率都低,但是没有编码延迟。

The maximum number of sliced threads is MIN( (height+15)/16 / 4, 128 )

建议: Default (off), unless you are doing some sort of realtime streaming or low latency is important.除非你正在做实时流或者当低延迟非常重要时。

thread-input

默认值: Set if threads > 1.

Decodes the input video in a separate thread to the encoding process.

在单独的线程中解码输入视频用于编码进程。

建议: Default.

sync-lookahead

默认值: auto (--bframes+1)

Sets the number of frames to be used as a buffer for threaded lookahead. Maximum Value is 250. Automatically disabled during the 2nd or greater pass or when using sliced threads.

Setting this to 0 disables threaded lookahead, which allows lower latency at the cost of reduced performance.

设置用于线程预测的帧缓存大小。最大值为250。在第二遍及更多遍编码时或基于分片线程时会自动关闭。

将此选项设为0将关闭线程预测,将减小延迟,但是以降低性能为代价。

建议: Default

non-deterministic

默认值: Not Set

Slightly improve quality when encoding with --threads > 1, at the cost of non-deterministic output encodes. This enables multi-threaded mv and uses the entire lookahead buffer in slicetype decisions when slicetype is threaded -- rather than just the minimum amount known to be available.

Not for general use.一般不用。

建议: Default

在 --threads>1 时可以稍微提高编码质量,以非确定性输出编码为代价。开启多线程 mv 和 在分片类型决策时使用全部的向前预测缓存。

See also: threads

asm

默认值: auto

Override automatic CPU detection. Useful for debugging or troubleshooting.不理会自动 CPU 检测。用于调试或排除故障。

建议: Default

no-asm

默认值: Not Set

Disables all CPU optimisations. Useful for debugging or troubleshooting.关闭所有 CPU 优化。用于调试或排除故障。

建议: Default

visualize

默认值: Not Set

Enables Macroblock Type visualizations over the encoded video. Useful for frame by frame debugging or analysis.

Requires compile time support, and an X11 windowing system.

开启已编码视频宏块可视化。用于逐帧调试或分析。

需要编译支持和 X11 窗口系统。

建议: Default

dump-yuv

默认值: Not Set

Dumps the reconstructed YUV frames to the specified file. Useful mostly for debugging. Not for general use.

把重建的 YUV 帧转存到指定文件。通常用于调试。一般不用。

建议: Default

sps-id

默认值: Not Set

Set SPS (sequence parameter set) and PPS (picture parameter set) id numbers. Not for general use.设置序列参数集和图像参数集id号。一般不用。

建议: Default

aud

默认值: Not Set

Use access unit delimiters.设置访问单元分隔符。

建议: Default, unless encoding for Blu-ray, in which case set this option.仅用于蓝光碟

force-cfr

默认值: Not Set

If using ffms2 or lavf demuxers, timecodes are copied from the input file, provided the output file is not raw. This option disables this, and forces x264 to generate its own. When using this you probably also want to set --fps.

如果使用 ffms2 或 lavf 解封装器,且输出文件不是 raw 格式,则从输入文件复制时间码。此选项关闭这个功能,并强制 x264 自己产生。当使用此选项时一般也会设置--fps。

建议: Default

tcfile-in

Specify a timecodes file which should be used to interpret the framerate of the input video. The timecode file can be in either v1 or v2 format which are described in the mkvmerge documentation.

指定一个说明输入视频帧率的时间码文件。

See Also: --tcfile-out--force-cfr--fps

tcfile-out

Output a timecode file (v2 format) based on the input timestamps. For use when you're encoding a VFR input video and want to dump the timecodes. For details on the file format, see --tcfile-in.

输出一个基于输入时间戳的时间码文件(v2 格式)。用于当你正在编码一个 VFR 视频源并且想转存时间码的时候。

timebase

默认值: Not Set

Allows you to set a custom timebase.

The numerator is 'seconds', and the denominator is 'ticks'. Means how many seconds one tick takes.

  • If passed a rational, it will set the numerator and denominator accordingly.
  • If passed an integer, and an input timecodes file is set via --tcfile-in, it will use the value passed as the numerator, and generate the denominator accordingly.
  • If passed an integer, and no input timecodes file is set, it will use the value passed as the denominator and generate the 'ticks per frame' from the input video.

Not compatible with --force-cfr mode.

允许你自定义时间基准。

分子是‘秒’,分母是‘ticks’。意思是1个 tick 多少秒。

  • 如果为有理数,将相应的设置分子和分母。
  • 如果为整数,并且通过 tcfile-in 设置了时间码文件,将使用此值做分子,并相应的生成分母。
  • 如果为整数,并且没有设置时间码文件,将使用此值作为分母并从视频源生成每帧‘ticks’数。

与--force-cfr 不兼容。

建议: Default

dts-compress

默认值: Not Set

A hack, implemented for FLV and MP4 containers only, that can work around buggy decoders that expect all DTSs to be positive. As per the commit message for this change, use at your own risk.

Note: DTS refers to Decode TimeStamp. Each frame is allocated a DTS that reflects its position in the 'coded order' of the stream, as opposed to the 'display order' of the stream, which is specified by the Presentation TimeStamp. The order frames are stored in the stream is different to the order they are displayed due to compression techniques such as B-frames, which result in frames requiring data from frames that will be displayed after.

一个小把戏,仅适用于FLV和MP4容器,可以在有缺陷的解码器下工作,这些解码器认为所有的 DTS 都是正数。使用此选项风险自担。

注:DTS指的是解码时间戳。每一帧都分配一个 DTS,对应其在流的‘编码顺序’中的位置,不同于由显示时间戳PTS指定的‘显示顺序’。由于使用 B 帧等压缩技术的原因,造成某些帧需要后续帧的数据。因此各帧在视频流中的保存顺序与其显示顺序是不同的。

滤镜或特效Filtering

video-filter

The x264 filtering system is used to process the input video before encoding. Multiple filters can also be applied sequentially to the input video.x264过滤系统会在视频源被编码前处理它们。可以顺序使用多个过滤器(滤波器)。

The basic syntax to apply a filter is this:

--video-filter <filter>

You can apply multiple filters sequentially by delimiting them with a /连续使用多个过滤器时用 / 分隔

--video-filter <filter1>/<filter2>

You can 'chain' as many filter operations as you like together.你可以按自己喜欢的方式链式使用多个过滤器。

The available filters are:

crop

Syntax: crop:left,top,right,bottom

Remove pixels from the edges of the frame.从帧的边缘移去像素,就是常说的剪裁。

  • You must crop height in multiples of 4 when using yv12i, i420i, or nv12i format video input
  • You must crop height in multiples of 2 when using yv12p, i420p, nv12p, or any other interlaced format video input not specified above.
  • You must crop width in multiples of 2 when using i420, i422, yv12, yv16, nv12, or nv16 format video input.当视频源是这几种格式时,在宽度方向剪裁的像素必须是2的倍数。
resize

Syntax: resize:[width,height][,sar][,fittobox][,csp][,method]

Resizes frames and/or converts frames between different colorspaces. Requires x264 to be compiled with libswscale.

There are a few possible modes on how to resize frames:

  • Resolution only: Resizes frames to the specified resolution and changes the SAR to avoid stretching.
  • SAR only: Sets the SAR and resizes frames to a new resolution to avoid stretching.
  • Resolution + SAR: Resizes frames to the specified resolution and sets SAR to the specified value, potentially allowing stretching.
  • Fittobox: Resizes frames based on the specified constraint mode, adapting the resolution to have a resultant SAR of 1:1
  • width: Resize frames to fit within the specified width constraint
  • height: Resize frames to fit within the specified height constraint
  • both: Resize frames to fit within the specified box constraint
  • Fittobox + SAR: Same as regular Fittobox mode except the resultant frames have the specified SAR, shrinking the video to where the anamorphic video fits within the specified constraint.

Options that are independent of the resizing mode are

  • csp: simultaneously converting frames to the specified colorspace. The valid list of colorspaces are displayed in x264 --fullhelp
  • method (Default bicubic): when resizing frames, use the specified resizer method
fastbilinear, bilinear, bicubic, experimental, point, area, bicublin, gauss, sinc, lanczos, spline

调整帧尺寸 和/或 转换帧的色彩空间。需要 x264 编译时带上 libswscale 库。

有下面几种调整帧尺寸的方式:

  • 仅分辨率:按照指定的分辨率调整帧尺寸,同时调整 SAR 从而避免图像拉伸变形。
  • 仅SAR:设定 SAR,同时调整帧尺寸从而避免图像拉伸变形。
  • 分辨率 + SAR:按照指定的分辨率调整帧尺寸并且按指定值设定 SAR,可能产生拉伸变形。
  • Fittobox:基于指定约束模式调整帧尺寸,分辨率按1:1的 SAR 自适应。
    • width:调整帧尺寸来符合指定宽度约束。
    • height:调整帧尺寸来符合指定高度约束。
    • both:调整帧尺寸来符合指定矩形约束。
  • Fittobox + SAR:除额外指定 SAR 外与 Fittobox 类似,收缩视频使可变形视频符合指定的约束。

与调整尺寸无关的参数:

  • csp:同时将帧转换为指定的色彩空间。
  • method (默认 bicubic):当调整帧尺寸时,使用指定的调整方法。

Example:

resize:width=1280,height=720,method=spline
select_every

Syntax: select_every:step,offset1[,offset2,...]

"Select" only a subset of input frames to encode, dropping the rest. Every step frames, take only the frames specified with an offset. 仅选择部分输入帧进行编码,丢弃其它。每隔 step 帧,仅使用 offset 指定的帧。For example: To encode every second frame:每2帧,丢弃第1帧,采用第2帧

select_every:2,1

To drop every third frame:每3帧,采用第0,1帧,丢弃第2帧

select_every:3,0,1

You can see more examples at the Avisynth wiki (which has an identical filter).




=====================================================================================================================================



FFmpeg and H.264 Encoding Guide

The goal of this guide is to inform new users how to create a high-quality H.264 video using the encoder x264.

There are two rate control modes that are usually suggested for general use: Constant Rate Factor (CRF) or Two-Pass ABR. The rate control is a method that will decide how many bits will be used for each frame. This will determine the file size and also how quality is distributed.

If you need help compiling and installing libx264 see one of our FFmpeg and x264 compiling guides.

Constant Rate Factor (CRF)

This method allows the encoder to attempt to achieve a certain output quality for the whole file when output file size is of less importance. This provides maximum compression efficiency with a single pass. Each frame gets the bitrate it needs to keep the requested quality level. The downside is that you can't tell it to get a specific filesize or not go over a specific size or bitrate.

1. Choose a CRF value

The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless or nearly so: it should look the same or nearly the same as the input but it isn't technically lossless.

The range is exponential, so increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value and if it looks bad then choose a lower value.

Note: The CRF quantizer scale mentioned on this page only applies to 8-bit x264 (10-bit x264 quantizer scale is 0-63). You can see what you are using by referring to the ffmpegconsole output during encoding (yuv420p or similar for 8-bit, and yuv420p10le or similar for 10-bit). 8-bit is more common among distributors.

2. Choose a preset

A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.

The general guideline is to use the slowest preset that you have patience for. Current presets in descending order of speed are: ultrafast,superfastveryfastfasterfastmedium,slowslowerveryslowplacebo. The default preset is medium. Ignore placebo as it is not useful (see FAQ). You can see a list of current presets with -preset help (see example below), and what settings they apply with x264 --fullhelp.

You can optionally use -tune to change settings based upon the specifics of your input. Current tunings include: filmanimationgrainstillimagepsnrssimfastdecodezerolatency. For example, if your input is animation then use the animation tuning, or if you want to preserve grain then use the grain tuning. If you are unsure of what to use or your input does not match any of tunings then omit the -tune option. You can see a list of current tunings with -tune help, and what settings they apply with x264 --fullhelp.

Another optional setting is -profile:v which will limit the output to a specific H.264 profile. This can generally be omitted unless the target device only supports a certain profile (seeCompatibility). Current profiles include: baselinemainhighhigh10high422high444. Note that usage of -profile:v is incompatible with lossless encoding.

To list all possible internal preset and tunes:

ffmpeg -f lavfi -i nullsrc -c:v libx264 -preset help -f mp4 -

Note: Windows users may need to use NUL instead of - as the output.

3. Use your settings

Once you've chosen your settings apply them for the rest of your videos if you are encoding more. This will ensure that they will all have similar quality.

CRF Example

ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv

Note that in this example the audio stream of the input file is simply stream copied over to the output and not re-encoded.


Two-Pass

This method is generally used if you are targeting a specific output file size and output quality from frame to frame is of less importance. This is best explained with an example. Your video is 10 minutes (600 seconds) long and an output of 50 MB is desired. Since bitrate = file size / duration:

(50 MB * 8192 [converts MB to kilobits]) / 600 seconds = ~683 kilobits/s total bitrate
683k - 128k (desired audio bitrate) = 555k video bitrate

Two-Pass Example

ffmpeg -y -i input -c:v libx264 -preset medium -b:v 555k -pass 1 -c:a libfdk_aac -b:a 128k -f mp4 /dev/null && \
ffmpeg -i input -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4

Note: Windows users should use NUL instead of /dev/null.

As with CRF, choose the slowest preset you can tolerate.

In pass 1 specify a output format (with "-f") that matches the output format in pass 2. Also in pass 1, specify the audio codec used in pass 2; in many cases "-an" in pass 1 will not work.

See Making a high quality MPEG-4 ("DivX") rip of a DVD movie. It is an MEncoder guide, but it will give you an insight about how important it is to use two-pass when you want to efficiently use every bit when you're constrained with storage space.


Lossless H.264

You can use -qp 0 or -crf 0 to encode a lossless output. Use of -qp is recommended over -crf for lossless because 8-bit and 10-bit x264 use different -crf values for lossless. Two useful presets for this are ultrafast or veryslow since either a fast encoding speed or best compression are usually the most important factors. Most non-FFmpeg based players will not be able to decode lossless (but YouTube can), so if compatibility is an issue you should not use lossless.

Lossless Example (fastest encoding)

ffmpeg -i input -c:v libx264 -preset ultrafast -qp 0 output.mkv

Lossless Example (best compression)

ffmpeg -i input -c:v libx264 -preset veryslow -qp 0 output.mkv

Overwriting default preset settings

You can overwrite default preset settings with the x264opts option, the x264-params option, or by using the libx264 private options (see ffmpeg -h encoder=libx264). This is not recommended unless you know what you are doing. The presets were created by the x264 developers and tweaking values to get a better output is usually a waste of time.

Example:

ffmpeg -i input -c:v libx264 -preset slow -crf 22 -x264opts keyint=123:min-keyint=20 -c:a copy output.mkv

Additional Information & Tips

ABR (Average Bit Rate)

ffmpeg -i input -c:v libx264 -b:v 1000k output.mp4

This provides something of a "running average" target, with the end goal that the final file match this number "overall on average" (so basically, if it gets a lot of black frames, which cost very little, it will encode them with less than the requested bitrate, but then the next few seconds of (non-black) frames it will encode at very high quality, to bring the average back in line). Using 2-pass can help this method to be more effective. You can also use this in combination with a "max bit rate" setting in order to prevent some of the swings.

CBR (Constant Bit Rate)

There is no native CBR mode, but you can "simulate" a constant bit rate setting by tuning the parameters of ABR:

ffmpeg -i input -c:v libx264 -b:v 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v

In the above example, -bufsize is the "rate control buffer" so it will enforce your requested "average" (4000k in this case) across each 1835k worth of video. So basically it is assumed that the receiver/end player will buffer that much data so it's ok to fluctuate within that much.

Of course, if it's all just empty/black frames then it will still serve less than that many bits/s but it will raise the quality level as much as it can, up to the crf level.

CRF with maximum bit rate

You can also also use a crf with a maximum bit rate by specifying both crf *and* maxrate settings, like

ffmpeg -i input -c:v libx264 -crf 20 -maxrate 400k -bufsize 1835k output.mp4

This will effectively "target" crf 20, but if the output exceeds 400kb/s, it will degrade to something less than crf 20 in that case.

Low Latency

libx264 offers a -tune zerolatency option. See the StreamingGuide.

Compatibility

All devices

If you want your videos to have highest compatibility with target devices (older iOS versions or all Android devices):

-profile:v baseline -level 3.0

This disables some advanced features but provides for better compatibility. Typically you may not need this setting (and therefore avoid using -profile:v and -level), but if you do use this setting it may increase the bit rate quite a bit compared to what is needed to achieve the same quality in higher profiles.

iOS
iOS Compatability (source)
Profile Level Devices Options
Baseline3.0All devices-profile:v baseline -level 3.0
Baseline3.1iPhone 3G and later, iPod touch 2nd generation and later-profile:v baseline -level 3.1
Main3.1iPad (all versions), Apple TV 2 and later, iPhone 4 and later-profile:v main -level 3.1
Main4.0Apple TV 3 and later, iPad 2 and later, iPhone 4s and later-profile:v main -level 4.0
High4.0Apple TV 3 and later, iPad 2 and later, iPhone 4s and later-profile:v high -level 4.0
High4.1iPad 2 and later, iPhone 4s and later, iPhone 5c and later-profile:v high -level 4.1
High4.2iPad Air and later, iPhone 5s and later-profile:v high -level 4.2
  • This table does not include any additional restrictions which may be required by your device.
  • -level may not set the correct number of reference frames (-refs) if you're using an older build. See ticket #3307.
Apple Quicktime

Apple QuickTime only supports YUV planar color space with 4:2:0 chroma subsampling (use -pix_fmt yuv420p) for H.264 video. For information on additional restrictions see QuickTime-compatible Encoding.

Blu-ray

See Authoring a professional Blu-ray Disc with x264.

Pre-testing your settings

Encode a random section instead of the whole video with the -ss and -t options to quickly get a general idea of what the output will look like.

  • -ss: Offset time from beginning. Value can be in seconds or HH:MM:SS format.
  • -t: Output duration. Value can be in seconds or HH:MM:SS format.

faststart for web video

You can add -movflags +faststart as an output option if your videos are going to be viewed in a browser. This will move some information to the beginning of your file and allow the video to begin playing before it is completely downloaded by the viewer. It is not required if you are going to use a video service such as YouTube.

Custom preset file

Add -fpre or -vpre output option.

First ffmpeg searches for a file named arg.ffpreset in the directories $FFMPEG_DATADIR (if set), and $HOME/.ffmpeg, and in the datadir defined at configuration time (usually PREFIX/share/ffmpeg) or in a ffpresets folder along the executable on win32, in that order. For example, if the argument is libx264-1080p, it will search for the file libx264-1080p.ffpreset.


FAQ

Will two-pass provide a better quality than CRF?

No, though it does allow you to target a file size more accurately.

Why is placebo a waste of time?

It helps at most ~1% compared to the veryslow preset at the cost of a much higher encoding time. It's diminishing returns: veryslow helps about 3% compared to the slower preset,slower helps about 5% compared to the slow preset, and slow helps about 5-10% compared to the medium preset.

Why doesn't my lossless output look lossless?

Blame the RGB to YUV color space conversion. If you convert to yuv444 it should still be lossless (which is the default now).

Will a graphics card make x264 encode faster?

Not necessarily. x264 supports OpenCL for some lookahead operations. There are also some proprietary encoders that utilize the GPU, but that does not mean they are well optimized, though encoding time may be faster; and they might be worse than vanilla x264, and possibly slower. Regardless, FFmpeg today doesn't support any means of GPU encoding, outside of libx264.

Encoding for dumb players

You may need to use -pix_fmt yuv420p for your output to work in QuickTime and most other players. These players only supports the YUV planar color space with 4:2:0 chroma subsampling for H.264 video. Otherwise, depending on your source, ffmpeg may output to a pixel format that may be incompatible with these players.


Additional Resources


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值