X264

From wiki.selur.net
Revision as of 06:15, 23 November 2026 by Selur (talk | contribs) (New page (via create-page on MediaWiki MCP Server))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

x264 is the open-source encoder for H.264/MPEG-4 AVC. H.264 plays on practically every device, and x264 is the reference for quality and speed among the software encoders for it. Hybrid drives the command line encoder and exposes nearly all of its options.

Base → Video: x264, then the x264 tab

What it does

x264 compresses video by predicting each frame from already coded frames (motion estimation) or from neighbouring blocks, transforming what is left and quantizing it. How coarse the quantization is decides size and quality; the rate control picks it per frame and per macroblock from the chosen mode:

  • constant rate factor (CRF): constant perceived quality, the size results from the content. The usual choice when no size has to be hit.
  • 2-pass: a first pass analyses the video, the second distributes a given bit rate or file size over it.
  • average bitrate: one pass towards a bit rate; less precise than 2-pass.
  • constant quantizer: the same quantizer for all frames of a type; for tests and for lossless encoding.

Most other options trade encoding time against compression, or restrict the stream so that a certain player can decode it.

Requirements

x264 is part of Hybrid on every system. Bit depths above 8 bit and color formats other than 4:2:0 need the matching AVC profile (High10, High4:2:2, High4:4:4), which most hardware players do not support.

Settings

The option column shows the x264 option a control ends up as. Many controls are locked depending on the profile, level and encoding mode; the tables name the conditions.

Base

x264 Base tab
x264 Base tab

General Settings

Control x264 option Range / values Hybrid default Meaning
Encoding mode --crf, --qp, --bitrate, --pass specific filesize/bitrate (2-pass), 2pass - 1st pass, 2pass - 2nd pass, average bitrate (1-pass), constant rate factor (1-pass), constant quantizer (1-pass) specific filesize/bitrate (2-pass) Rate control mode, see above. The two single-pass entries of 2-pass run only that pass, e.g. to repeat a second pass with an existing statistics file.
Quantization factor --crf 1 – 51, step 0.01 18 Quality target of the CRF mode; lower is better and bigger. Around 16 – 22 is common, ±6 roughly halves or doubles the size.
Quantization strength --qp 1 – 51 18 Quantizer of the constant quantizer mode (for P-frames; I- and B-frames follow through the quant factors).
Lossless --qp 0 on/off off Lossless encoding in constant quantizer mode; also switches the in-loop filter off. Needs the profile High4:4:4 or None.
Restrict crf to --crf-max 0.1 – 51 off, 18.1 With VBV active: the highest CRF the encoder may go to when the buffer forces it to save bits. Protects quality at the price of possibly breaking the buffer limits.
Bitrate (kbit/s) --bitrate 16 – 300000 1500 Target bit rate of the bit rate based modes. The level limits the maximum.
Target size (MiB), Target mode --bitrate 0.2 MiB and up; custom, 1/4 CD … 1 BD 50 custom, 700 Aim at a file size instead; Hybrid computes the video bit rate from the size, the length and the size of audio and other streams. Target mode offers common media sizes.
Fast 1st pass --slow-firstpass (when off) on/off on Lets x264 run the first pass with reduced settings (dia, subme 2, 1 reference, no trellis, no partitions), which is much faster and costs hardly any quality.
Threads --threads 0 – 128 0 Number of encoding threads; 0 lets x264 decide (1.5 × logical cores). See Limit threads by height.
Sliced threads --sliced-threads on/off off Slice-based threading: no frame delay, but worse compression. Only for low-latency use.
Calculation precision, auto --output-depth 8-bit, 10-bit 8-bit, auto on Bit depth of the output. With auto Hybrid takes the highest depth the profile allows (10 bit from High10 on).
Output color space, auto --output-csp i420, i422, i444 i420, auto on Chroma format of the output. With auto the highest one the profile allows.

Restriction Settings

Control x264 option Range / values Hybrid default Meaning
AVC Profile --profile Base, Main, High, High10, High4:2:2, High4:4:4, None High H.264 profile, the set of coding tools the decoder must support. It also locks the controls the profile forbids (e.g. no B-frames and no CABAC in Base). None leaves the choice to x264.
AVC Level --level 1.0 – 6.2, unrestricted 5.1 Level, the upper limit for frame size × frame rate, bit rate, buffer and reference frames. Hybrid limits references, VBV and bit rate to it.
Entropy coding --cabac / --no-cabac CABAC, CAVLC CABAC CABAC compresses 10 – 15 % better; CAVLC is easier to decode and the only choice in the Base profile.
signal hrd --nal-hrd none, vbr, cbr off Signals the buffer model in the stream. Blu-ray needs vbr; cbr pads the stream to a constant bit rate.
Hardware --bluray-compat (Blu-ray/AVCHD) unrestricted, DXVA, Blu-ray/AVCHD off Restricts settings, frame sizes, frame rates and pixel aspect ratios to what the chosen playback target accepts.
Pulldown --pulldown 22, 32, 64, double, triple, euro off Soft pulldown flags for playback (e.g. 32 for 24 → 30 fps); the stored frames do not change. Only with Blu-ray/AVCHD.
Multi-slice --slices, --slice-max-mbs, --slice-max-size disabled, by slices per frame (4 – 1024), by macroblocks per slice (8 – 880), by slice size in bytes (64 – 1024) disabled Splits each frame into several slices. Needed for Blu-ray (4 slices) and for transports with a packet size limit; costs some compression.

Profile & Presets

Control x264 option Range / values Hybrid default Meaning
Preset --preset none, ultrafast … placebo none x264's speed presets. The arrow button applies the preset to the controls; nothing changes before that. medium equals x264's defaults.
Tune --tune none, film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency none Adjustment for a kind of content or a goal; also applied with its arrow button.
Reset to preset – on/off on Apply the selected preset first whenever a tune is applied.

Frames

x264 Frames tab
x264 Frames tab

General Frame Settings

Control x264 option Range / values Hybrid default Meaning
Maximum number of reference frames --ref 1 – 16 3 How many earlier frames a frame may refer to. More helps mostly with animation and costs speed and decoder memory; the level limits it.
Mixed references --no-mixed-refs (when off) on/off on Lets every 8×8 block pick its own reference frame instead of one per macroblock.
Fast p-frame skip --no-fast-pskip (when off) on/off off Early skip detection in P-frames. Faster, but can cause blocking in flat areas such as sky.
Weighted P-frame prediction --weightp disabled, refs, refs+dupl refs Weighted prediction for P-frames, which helps most in fades. 0, 1 (fade analysis) or 2 (also duplicated references; x264's default).
Scene change at --scenecut 0 – 100 40 Threshold for placing an I-frame at a scene change. 0 switches the detection off.
Adjust max gop to output fps – on/off off Sets the maximum GOP size to ten times the output frame rate whenever it changes.
GOP size min/max --min-keyint, --keyint 0 – 10000 0 / 250 Shortest and longest distance between IDR frames. Minimum 0 lets x264 choose; maximum 0 is written as --keyint infinite.
Input lookahead --sync-lookahead off, minimize, manual (up to 250) minimize Frame buffer of the threaded lookahead. minimize sets threads + B-frames.

B-Frame Settings

Control x264 option Range / values Hybrid default Meaning
Maximum number of consecutive b-frames --bframes 0 – 16 3 Upper limit of B-frames in a row.
Weighted references --no-weightb (when off) on/off on Weighted prediction for B-frames.
Adaptive b-frame decision --b-adapt disabled, fast, optimal disabled How x264 decides between P- and B-frames. disabled always uses the maximum, fast is x264's default, optimal gets much slower with many B-frames.
B-pyramid --b-pyramid disabled, strict, normal normal Lets B-frames be references for other B-frames. strict is the Blu-ray compatible form.
B-frame prediction mode --direct automatic, temporal, spatial, disabled automatic Prediction of the motion vectors of direct blocks.
Boost b-frame frequency --b-bias 0 – 100 0 Makes the adaptive decision prefer B-frames.

Advanced Frame Settings

Control x264 option Range / values Hybrid default Meaning
Open GOP --open-gop on/off off Allows B-frames before an I-frame to refer across it; saves bits with short GOPs.
Intra refresh --intra-refresh on/off off Replaces IDR frames by a column of intra blocks that moves across the picture; for low-latency streaming. Only available with exactly one reference frame and B-frames in use.
Fake interlaced encoding flag --fake-interlaced on/off off Flags a progressive stream as interlaced; needed for 25p and 30p on Blu-ray.
Interlaced encoding, Force bff --tff / --bff on/off off Interlaced (MBAFF) encoding. The field order comes from the video; Force bff forces bottom field first.
Stereoscopic --frame-packing checkerboard, column alternation, row alternation, side by side, top bottom, frame alternation off Flags how the two views of a 3D video are packed.
Noise reduction --nr 0 – 10000 0 x264's built-in noise reduction in the transform domain; 100 – 1000 are useful values. A denoising filter gives better results.
SPS/PPS --sps-id 0 – 50000 off Sets the id of the parameter sets; only needed when streams are to be joined.
Send pic_struct in Picture Timing SEI --pic-struct on/off off Writes the picture structure into the timing SEI; implied by interlacing and pulldown.

Rate Control

x264 Rate Control tab
x264 Rate Control tab

Rate Control Settings

Control x264 option Range / values Hybrid default Meaning
Curve compression --qcomp 0 – 1 0.5 0 gives a constant bit rate, 1 a constant quantizer; x264's default is 0.6. At 1 Hybrid switches macroblock tree off.
Quantizer smoothing pre/post cc --cplxblur, --qblur 0 – 100 20 / 0.5 Smooths the quantizer curve before and after curve compression (2-pass).
Data rate fluctuation --ratetol 0 – 100 2 How far a 1-pass bit rate encode may drift from its target.
Lookahead threads --lookahead-threads auto, manual (0 – 16) auto Threads of the lookahead.
Lookahead (frames) --rc-lookahead 0 – 250 40 Frames macroblock tree and VBV look ahead.
Macroblock tree rate control --mbtree / --no-mbtree disabled, activated activated Gives blocks that many later frames refer to more bits.
Statistic file --stats file empty Statistics file of the 2-pass modes; empty uses a temporary file.
Always create --pass on/off off Also write a statistics file in the 1-pass modes and in the 2nd pass (--pass 3).
Fade compensation --fade-compensate 0 – 1 0 Gives fades more bits. Only shown when the x264 build has the option.

Video Buffer Verifier (VBV)

Control x264 option Range / values Hybrid default Meaning
Medium limit – unrestricted, UHD-BD, BD 25/50 - x2, BD 25/50 - x1, DVD/BD (5/9), CD off Limits the VBV values to the read speed of the medium.
Buffer size (kbit) --vbv-bufsize 1 – 300000 78125 Size of the decoder buffer.
Max fillrate (kbit/s) --vbv-maxrate 1 – 300000 62500 Highest rate at which the buffer is filled, i.e. the peak bit rate.
Initial load --vbv-init 0.1 – 100 0.9 Buffer fill at the start of playback.

Hybrid adjusts both VBV values to the profile and level unless Keep VBV values is set. They are written with a restricted level and not in constant quantizer mode.

Motion Estimation

x264 Motion Estimation tab
x264 Motion Estimation tab
Control x264 option Range / values Hybrid default Meaning
Full-pixel precision --me diamond, hexagonal, multi-hexagonal, exhaustive, hadamard hexagonal Motion search method (dia, hex, umh, esa, tesa), from fastest to slowest. umh is a good choice for quality.
Max pixel search range --merange 4 – 1024 16 Search range in pixels; matters for umh and above.
Motion vector range --mvrange automatic, 64, 128, 256, 512 automatic Longest vertical motion vector; automatic follows the level.
Chroma motion estimation --no-chroma-me (when off) on/off on Includes chroma in the sub-pixel motion search.
Sub-pixel precision --subme 0 – 11 5 Quality of the sub-pixel refinement and of the mode decision; from 6 on with rate-distortion optimization. x264's default is 7.
Adaptive DCT --8x8dct / --no-8x8dct on/off on 8×8 transform; needs High profile.
I4x4, I8x8, P4x4, P8x8, B8x8 --partitions on/off each I4x4, P8x8, B8x8 on Block sizes the encoder may split macroblocks into. I8x8 needs Adaptive DCT, P4x4 needs P8x8.
Allow P4x4 at all levels – on/off off Ignores the level rule for P4x4.
Fast DCT calculation --no-dct-decimate (when off) on/off on Drops blocks with only tiny coefficients in P-frames.
Show macroblock types --visualize on/off off Debug overlay of old x264 builds.

Quantization

x264 Quantization tab
x264 Quantization tab
Control x264 option Range / values Hybrid default Meaning
Quantizer min/max --qpmin, --qpmax 0 – 69 0 / 51 Limits of the quantizer.
Quantfactor I->P/P->B --ipratio, --pbratio 1 – 10 1.4 / 1.3 Quantizer ratio between I- and P-frames and between P- and B-frames.
Max quantizer difference --qpstep 1 – 50 4 Largest quantizer change from one frame to the next.
Chroma boost/modifier --chroma-qp-offset -12 – 12 0 Quantizer offset of chroma. The grey number is what psy-RD and psy-trellis add on their own.
Deadzone inter/intra --deadzone-inter, --deadzone-intra 1 – 51 21 / 11 Rounding threshold of the quantization without trellis; lower keeps more fine detail.
Adaptive quantization, Strength --aq-mode, --aq-strength disabled, manual, automatic, automatic2; 0 – 2 disabled Shifts bits between flat and detailed areas inside a frame (modes 0 – 3). x264's default is mode 1 with strength 1.0.
Trellis quantization --trellis disabled, MBs only, always disabled Rate-distortion optimized quantization (0, 1, 2). Needs CABAC.
Psy RD/trellis strength --psy-rd 0 – 10 each 0.8 / 0.2 Psychovisual optimization that keeps detail and grain instead of maximizing PSNR. Psy-RD needs sub-pixel precision 6 or more, psy-trellis needs trellis.
In-Loop Filter --no-deblock (when off) on/off on The deblocking filter of H.264.
Deblocking strength/threshold --deblock -6 – 6 each 0 / 0 Strength (alpha) and threshold (beta) of the deblocking filter. Negative values keep more detail, positive values smooth more.
Quantization matrix, Custom matrix --cqm, --cqmfile jvt, flat, custom flat Quantization matrix; custom loads a matrix file.
Custom qp file --qpfile file empty File that forces frame types and quantizers for single frames.

Zones

x264 Zones tab
x264 Zones tab

A zone gives a range of frames its own treatment, e.g. fewer bits for the credits. Enter start and end frame, the value and the type, then add the zone to the list with the plus button; the arrow writes changes back to the selected zone, minus removes it. Hybrid passes the list as --zones.

Type x264 zone option Meaning of Mod/Quant
fixed quantizer q= Quantizer for the zone.
constant rate factor crf= CRF for the zone.
bitrate modificator b= Factor on the bit rate of the zone; 1.0 changes nothing.

VUI

x264 VUI tab
x264 VUI tab

The Video Usability Information describes how the decoded video is to be shown. It does not change the picture, only the flags in the stream.

Control x264 option Range / values Hybrid default Meaning
Color matrix, to input --colormatrix undef, bt709, fcc, bt470bg, smpte170m, smpte240m, GBR, YCgCo, bt2020nc, bt2020c on, to input Matrix for the YUV ↔ RGB conversion. With to input Hybrid takes the value of the video that reaches the encoder.
Luma range, to input --range limited, full on, to input Value range (tv/pc).
Transfer characteristics, to input --transfer undef, bt709, … smpte2084, arib-std-b67 off Transfer function (gamma, PQ, HLG).
Color primaries, to input --colorprim undef, bt709, bt470m, bt470bg, smpte170m, smpte240m, film, bt2020 off Color primaries.
Chroma sample location --chromaloc 0 – 5 off Position of the chroma samples.
Video format --videoformat undef, component, pal, ntsc, secam, mac off Original video system.
Overscan --overscan undef, show, crop off Whether the edge may be cut off by overscan.

The pixel aspect ratio is always written (--sar) and comes from Crop/Resize.

Misc

Main

x264 Misc tab, Main
x264 Misc tab, Main
Control x264 option Hybrid default Meaning
Keep VBV values – off Stops Hybrid from adapting the VBV values to profile and level.
Minimize command line --preset, --tune on Shortens the call: Hybrid looks for the preset and tune whose values are all present and writes them instead of the single options, and drops options that equal x264's defaults.
Use internal decoder if possible – off Lets x264 read the source with its own input modules instead of getting it piped from ffmpeg.
Stitchable --stitchable off Keeps the headers identical between encodes with the same settings, so that segments can be joined.
Limit threads by height --threads on Limits the thread count to height / 40 + B-frames, because more threads than that hurt quality at small frame sizes.
Medium restriction for Blu-ray – on Turns Medium limit on when Hardware is set to Blu-ray/AVCHD.
Access unit delimiters --aud off Writes access unit delimiters; some transport streams and players need them.
Non-deterministic encoding --non-deterministic on Slightly better quality with many threads; two runs no longer give identical files.
Constrained intra prediction --constrained-intra off Intra blocks do not use inter-coded neighbours; for error resilience.
Disable assembler optimizations --no-asm off For debugging only; very slow.
Disable psychovisual enhancements --no-psy off Switches off all optimizations that lower PSNR/SSIM; for metric tests.
Minimize AVC level – off Hybrid picks the lowest level that fits hardware restriction, bit rate, VBV and macroblocks per second.
Minimize AVC level for mbps and bitrate – off The same without looking at VBV.
Create qp file for chapters --qpfile on Writes a qp file that puts an IDR frame at every chapter start.
OpenCL, Use device number --opencl, --opencl-device off, 0 Runs parts of the lookahead on the GPU.
No too small warning – off No warning when the computed file size is below 1 MB.
Calculate SSIM, PSNR --ssim, --psnr off Lets x264 report the metrics in its log.

Timecodes

x264 Misc tab, Timecodes
x264 Misc tab, Timecodes
Control x264 option Hybrid default Meaning
Output time codes --tcfile-out off Writes the time stamps of the encoded frames to a timecode v2 file.
Input time codes, From input --tcfile-in empty, off Timecode file for variable frame rate input; From input takes the time stamps of the source.
Force input to be handled as constant frame rate --force-cfr off Ignores the time stamps and uses the frame rate.

Imports/Additions

x264 Misc tab, Imports/Additions
x264 Misc tab, Imports/Additions
Control Values Meaning
Addition text Text that is added to the call unchanged, for options Hybrid does not offer. It is not shortened and not checked.
Position Start, End Where the addition goes; x264 uses the last occurrence of an option, so End overrides Hybrid's own values.

The tab also imports x264 settings from a command line or from the encoder settings MediaInfo shows for an existing H.264 file.

The Configuration row below the tabs saves, loads and deletes named sets of all x264 settings.

Example

CRF 18, profile High, level 5.1 on a 10-bit YUV 4:2:0 source (640x352, 25 fps), with Minimize command line on:

vspipe "encodingTempSynthSkript.vpy" - --outputindex 0 -c y4m --progress | x264 --crf 18.00 --profile high --level 5.1 --direct auto --b-adapt 0 --sync-lookahead 48 --qcomp 0.50 --qpmax 51 --partitions i4x4,p8x8,b8x8 --no-fast-pskip --subme 5 --trellis 0 --weightp 1 --aq-mode 0 --vbv-maxrate 300000 --vbv-bufsize 300000 --threads 11 --sar 1:1 --non-deterministic --range tv --colormatrix smpte170m --demuxer y4m --input-range tv --fps 25/1 --output-depth 8 --output "video.264" -

The same settings in 2-pass mode with 1500 kbit/s; the first pass is the fast one:

x264 --preset fast --pass 1 --bitrate 1500 --profile high --level 5.1 --ref 1 --direct auto --b-adapt 0 --rc-lookahead 40 --sync-lookahead 48 --qcomp 0.50 --qpmax 51 --partitions none --no-8x8dct --me dia --subme 2 --trellis 0 --aq-mode 0 --threads 11 --sar 1:1 --non-deterministic --range tv --stats "video.stats" --demuxer y4m --input-range tv --fps 25/1 --output-depth 8 --output NUL -
x264 --pass 2 --bitrate 1500 --profile high --level 5.1 --direct auto --b-adapt 0 --sync-lookahead 48 --qcomp 0.50 --qpmax 51 --partitions i4x4,p8x8,b8x8 --no-fast-pskip --subme 5 --trellis 0 --weightp 1 --aq-mode 0 --vbv-maxrate 300000 --vbv-bufsize 300000 --threads 11 --sar 1:1 --non-deterministic --range tv --colormatrix smpte170m --stats "video.stats" --demuxer y4m --input-range tv --fps 25/1 --output-depth 8 --output "video.264" -

How Hybrid calls it

  • The filter script (Vapoursynth or AviSynth) is piped into x264 as y4m; without a script ffmpeg decodes the source and pipes raw video.
  • The script delivers the bit depth and color format set on the Base tab; the 10-bit source of the example is converted to 8 bit there.
  • x264 writes a raw H.264 stream; Hybrid muxes it into the chosen container in a separate job.
  • Preset and tune are not passed on as they are selected. Their buttons set the single controls, and Hybrid always builds the call from the controls; --preset and --tune only appear when Minimize command line finds that the values match one.
  • Options that equal x264's default are left out with Minimize command line on.
  • In the 2-pass mode Hybrid creates one job per pass and removes the statistics file afterwards.
  • The interlaced flags follow the scan type of the video that reaches the encoder; see Interlace.

Background

CRF or 2-pass

At the same file size CRF and 2-pass give the same quality; they use the same rate control and differ only in what is fixed, the quality or the size. 2-pass is only needed when the size matters.

Profiles and levels

Players state what they can decode as profile@level, e.g. High@4.1 for Blu-ray. The profile is about coding tools and bit depth, the level about size, frame rate and bit rate. A stream above the level of a hardware player usually does not play at all, so set both when encoding for a device.

Sources