X264设定
本页说明所有x264参数之目的和用法。参数的排列相同于在x264 --fullhelp
出现的顺序。
x264设定
说明
x264带有一些内置的文件。要阅读此说明,执行x264 --help
、x264 --longhelp
或x264 --fullhelp
。越后面的选项将提供更详细的资讯。
输入
用一个位置参数指定输入的视频。例如:
x264.exe -o NUL C:\input.avs x264 -o /dev/null ~/input.y4m
当输入的视频是raw YUV格式时,还必须告诉x264视频的解析度。你可能也要用--fps
来指定帧率:
x264.exe -o NUL --fps 25 --input-res 1280x720 D:\input.yuv x264 -o /dev/null --fps 30000/1001 --input-res 640x480 ~/input.yuv
预设值系统
为减少使用者花费时间和精神在命令列上而设计的一套系统。这些设定切换了哪些选项可从x264 --fullhelp
的说明中得知。
profile
预设:无
限制输出流的profile。如果指定了profile,将覆盖所有其他设定。所以如果指定了profile,将保证输出的流与该profile相容。如果设了此选项,将不能使用无损编码(--qp
0或--crf
0)。
如果知道你的播放设备仅支援某个profile,则应设此选项。大多数解码器支援High profile,因此不需要设此选项。
可用的值:baseline, main, high
preset
预设:medium
更改选项,以权衡压缩效率和编码速度。如果指定了preset,更改的选项将在所有其他参数套用前被套用。
通常应将此选项设为你所能承受的最慢的值。
可用的值:ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
tune
预设:无
调整选项,以进一步优化为视频的内容。如果指定了tune,更改的选项将在--preset
之后,但所有其他参数之前被套用。
如果视频内容符合其中一个可用的值,则可设此选项,否则就不要指定。
可用的值:film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency
slow-firstpass
预设:无
随著预设值系统在r1177版本的出现,使用--pass
1会在解析命令列的最后套用以下设定:
可以设--slow-firstpass
来停用此特性。使用--preset
placebo也会启用slow-firstpass。
参阅:--pass
帧类型选项
keyint
预设:250
设定x264的输出中最大的IDR帧(亦称关键帧)间隔。可以指定“infinite”让x264永远不要插入非scenecut的IDR帧。
IDR帧是视频流的‘分隔符号’,所有帧都不可以从IDR帧的另一边参考资料。因此,IDR帧也是I帧,所以它们不从任何其他帧参考资料。这意味著它们可以用作视频的搜寻点(seek points)。
请注意,I帧通常明显大于P/B帧(在低运动场景通常为10倍或更多),所以当它们与极低的VBV设定合并使用时会打乱码率控制。在这些情况下,研究一下--intra-refresh
。
预设值对于大多数视频没啥问题。在为蓝光、广播、直播流或某些其他特殊情况编码时,可能需要更小的GOP长度(通常等于帧率)。
参阅:--min-keyint
, --scenecut
, --intra-refresh
min-keyint
预设:自动 (MIN(--keyint
/10, --fps
))
设定IDR帧之间的最小长度。
对于IDR帧的说明可参阅--keyint
。过小的keyint范围可能会导致“错误的”IDR帧位置(例如闪屏场景)。此选项限制了在每个IDR帧之后,要有多少帧才能再有另一个IDR帧的最小长度。
min-keyint的最大允许值为--keyint
/2+1。
建议: 预设值,或者等于帧率
no-scenecut
预设:无
Completely disables adaptive I-frame decision.
参阅: --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 this doom9 thread.
Setting scenecut to 0 is equivalent to setting --no-scenecut
.
Recommendation: Default
参阅: --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.
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.
参阅:--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-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-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.
参阅:--bframes
, --refs
, --no-mixed-refs
open-gop
预设:none
Open-GOP is an encoding technique which increases efficiency. There are three modes:
none
: Open-GOP disabled.normal
: Open-GOP enabled.bluray
: . Open-GOP enabled. A less efficient version of open-GOP,normal
mode doesn't work when authoring Blu-rays.
Some decoders don't fully support open-GOP streams, which is why this 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.
There's an explanation of Open-GOP here.
no-cabac
预设:无
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.
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
.
参阅:--b-pyramid
, --no-mixed-refs
, --level
no-deblock
预设:无
Completely disables the loop filter. Not Recommended.
参阅: --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 (see the initial post and akupenguin's replies).
参阅: --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.
参阅: --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
.)
参阅: --slices
slice-max-mbs
预设:0
Sets the maximum slice size in macroblocks. (Currently is not compatible with --interlaced
.)
参阅: --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
.
bff
Enable interlaced encoding and specify the bottom field is first. See --tff
for more info.
constrained-intra
预设:无
Enable constrained intra prediction, which is required for the base layer of SVC encodes. Since Everyone(tm) ignores SVC you can likewise ignore this switch.
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 the HandBrake wiki. The available presets are: none, 22, 32, 64, double, triple and euro.
Specifying any mode but none implies --pic-struct
.
fake-interlaced
预设:无
Mark a stream as interlaced even when not encoding as interlaced. Allows encoding of 25p and 30p Blu-ray compliant videos.