# x264

Canonical URL: https://encode.wiki/tools/software-encoders/x264/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): b2dfeb2e7fc82f48a2038b904a0dc87a8d2da1506b95fee901b139b71688c889

> **Repository:** [videolan/x264](https://code.videolan.org/videolan/x264) (No commits since Sep 2025). x264, the best and fastest H.264 encoder. Last commit: Sep 10, 2025. License: GPL-2.0-or-later.

x264 is VideoLAN's open-source encoder for [H.264 / AVC](/codecs/video/avc/), available as a command-line program and as the `libx264` library used by FFmpeg, HandBrake and most other tools. It is fast, well threaded and keeps fine detail and grain well thanks to its psychovisual optimizations. Because H.264 decodes on practically everything, x264 is still the default choice when compatibility matters more than compression efficiency.

x264 has no numbered releases. Builds are identified by API core and revision, for example `core 165 r3222`; development now consists mostly of occasional platform and assembly work. Most FFmpeg builds include `libx264`; standalone binaries are published at [artifacts.videolan.org](https://artifacts.videolan.org/x264/), and the source is at [code.videolan.org/videolan/x264](https://code.videolan.org/videolan/x264).

## Encode with x264

Pick the slowest preset you can tolerate, pick a CRF, and adjust from there:

```sh
x264 --preset slow --crf 20 -o output.mkv input.y4m
ffmpeg -i input.mkv -c:v libx264 -preset slow -crf 20 -c:a copy output.mkv
```

The standalone program reads Y4M and raw YUV (plus anything else if built with libavformat or FFMS2 input) and writes raw `.264`, Matroska, FLV, or MP4 when built with L-SMASH or GPAC. It handles video only, so mux audio and subtitles afterwards. To feed it from FFmpeg, pipe Y4M:

```sh
ffmpeg -i input.mkv -f yuv4mpegpipe - | x264 --demuxer y4m --preset slow --crf 20 -o output.264 -
```

> **Caution — Remux x264's Matroska output.**
>
> x264's built-in Matroska writer does not write a seek index (Cues), so seeking in its `.mkv` files can be slow or broken. Remux the file (or a raw `.264` output) with [mkvmerge](/tools/utilities/mkvtoolnix/) or FFmpeg (`-c copy`).
In FFmpeg, `-preset`, `-tune`, `-crf`, `-profile:v`, `-g` (keyint) and `-b:v` map to x264 settings; anything else goes through `-x264-params` as colon-separated `key=value` pairs (use `,` inside values such as `psy-rd=1.0,0.15`). FFmpeg leaves x264's own defaults alone unless you set something, so a plain `-c:v libx264` encode is preset medium, CRF 23.

## Rate control

| Mode | Use it for | How |
| --- | --- | --- |
| CRF | Almost everything: constant perceived quality, file size follows the content | `--crf 20` / `-crf 20` |
| Two-pass bitrate | Hitting a file size | `--pass 1` then `--pass 2` with the same `--bitrate` |
| VBV | Streaming, Blu-ray or device limits on peak bitrate | `--vbv-maxrate` + `--vbv-bufsize`, with CRF or bitrate |
| Constant QP | Lossless (`--qp 0`) and testing only | `--qp N` |

**CRF** defaults to 23. Lower is higher quality and larger files; ±6 roughly halves or doubles the bitrate. Most encodes land between about 16 (close to transparent) and 23. CRF values are not comparable between encoders, and changing the preset or tune changes the size you get at a given CRF. With 10-bit output the CRF scale extends down to -12.

**Two-pass** gives the best quality for a target size. x264 runs the first pass with faster analysis settings automatically (`--slow-firstpass` disables that), and the first-pass output can be thrown away:

```sh
x264 --preset slow --pass 1 --bitrate 4000 -o /dev/null input.y4m
x264 --preset slow --pass 2 --bitrate 4000 -o output.mkv input.y4m
```

With FFmpeg, use `-pass 1`/`-pass 2` with `-b:v 4M`; the first pass can skip audio and discard its output with `-an -f null /dev/null`.

**VBV** limits the peak bitrate a decoder's buffer has to absorb. `--vbv-maxrate` is in kbit/s and `--vbv-bufsize` in kbit, so `--vbv-maxrate 10000 --vbv-bufsize 20000` caps the rate at 10 Mbit/s over a 2-second buffer. Combined with CRF ("capped CRF") it keeps CRF's quality targeting until a scene would exceed the cap. In FFmpeg the equivalents are `-maxrate` and `-bufsize`.

**Levels.** Without `--level`, x264 signals whatever level the settings need. At 1080p, `--preset veryslow` uses 16 reference frames and produces level 5.1, which some TVs and hardware players reject. Set `--level 4.1` (or whatever your target device needs) and x264 caps the reference count to fit.

## Presets and tunes

Presets run `ultrafast`, `superfast`, `veryfast`, `faster`, `fast`, `medium` (default), `slow`, `slower`, `veryslow` and `placebo`. Each step trades speed for compression efficiency. `veryslow` is the usual practical ceiling; `placebo` is much slower for a negligible gain. Choose a preset first, then tune individual options.

Tunes adjust settings for a type of content and are applied after the preset; your own options override both. Only one of the psy tunes (film, animation, grain, stillimage, psnr, ssim) can be used at a time, though `fastdecode` and `zerolatency` can be combined with one.

| Tune | Changes (from x264 --fullhelp) | Use for |
| --- | --- | --- |
| `film` | `--deblock -1:-1 --psy-rd <unset>:0.15` | Live action |
| `animation` | `--bframes +2 --deblock 1:1 --psy-rd 0.4:<unset> --aq-strength 0.6`, doubled refs | Cel animation, flat colours |
| `grain` | `--aq-strength 0.5 --no-dct-decimate --deadzone-inter 6 --deadzone-intra 6 --deblock -2:-2 --ipratio 1.1 --pbratio 1.1 --psy-rd <unset>:0.25 --qcomp 0.8` | Keeping heavy film grain at high bitrates |
| `stillimage` | `--aq-strength 1.2 --deblock -3:-3 --psy-rd 2.0:0.7` | Slideshows, still content |
| `psnr` / `ssim` | Disable psy optimizations (`--no-psy`; AQ off for psnr, auto-variance AQ for ssim) | Metric benchmarking only |
| `fastdecode` | `--no-cabac --no-deblock --no-weightb --weightp 0` | Weak decoders, very high bitrates |
| `zerolatency` | `--bframes 0 --force-cfr --no-mbtree --sync-lookahead 0 --sliced-threads --rc-lookahead 0` | Real-time streaming, video calls |

> **Caution — `--tune psnr` and `--tune ssim` make video look worse.**
>
> They switch off the psychovisual optimizations so the encode scores higher on PSNR or SSIM. The result is blurrier and loses texture, so use them only when you are measuring the encoder against those metrics. For judging quality, look at the video, and see [Compare encoding quality](/guides/compare-encoding-quality/) for better metrics.
## Options worth adjusting

Defaults are for preset medium with no tune. Most people only touch a few of these: a common high-quality starting point for live action is `--preset veryslow --tune film --crf 18`, adding `--aq-mode 3` if dark scenes band. See [Psychovisual optimization](/start-here/psychovisual/) for the background.

| Option | Default | What it does and when to change it |
| --- | --- | --- |
| `--psy-rd <rd>:<trellis>` | `1.0:0.0` | Psy-RD (first value) favours keeping the source's energy and detail; psy-trellis (second) does the same in quantization. Film and grain tunes raise psy-trellis to 0.15/0.25. Lower psy-RD (e.g. 0.4 in the animation tune) for flat content. Psy-RD needs `--subme` 6 or higher; psy-trellis needs trellis. |
| `--aq-mode` | `1` | 0 off, 1 variance AQ, 2 auto-variance, 3 auto-variance with a bias toward dark scenes. Mode 3 is a popular choice to reduce banding and blocking in dark areas; it spends more bits on dark scenes. |
| `--aq-strength` | `1.0` | How strongly AQ moves bits between flat and textured areas. Animation tune lowers it to 0.6, grain to 0.5. |
| `--deblock <alpha>:<beta>` | `0:0` | Loop-filter strength offsets. Negative values keep more detail and grain at high bitrates (film -1:-1, grain -2:-2); positive values smooth more (animation 1:1). |
| `--no-mbtree` / `--qcomp` | MB-tree on, qcomp `0.60` | MB-tree gives more bits to areas that later frames reference and fewer to areas that quickly disappear. It is a large efficiency gain, but it can flatten grain and dark detail. Raising `--qcomp` weakens it (MB-tree strength is 5 × (1 − qcomp)); the grain tune uses 0.8. Turning MB-tree off entirely costs a lot of efficiency. |
| `--bframes` | `3` | Maximum consecutive B-frames. 8 (veryslow) is common for high-efficiency encodes; animation benefits from more. |
| `--b-adapt` | `1` | B-frame placement: 0 fixed, 1 fast, 2 optimal. Use 2 (slower and up) with high `--bframes`. |
| `--ref` | `3` | Reference frames, up to 16. More helps efficiency, especially for animation, but costs speed and raises the required level. |
| `--me` | `hex` | Motion search: `dia`, `hex`, `umh`, `esa`, `tesa`. `umh` (slower and up) is the usual quality choice; `esa`/`tesa` are rarely worth the time. |
| `--subme` | `7` | Subpixel motion estimation and mode decision, 0–11. 10 needs `--trellis 2` and AQ; 11 disables all early terminations. |
| `--merange` | `16` | Motion search range for `umh`/`esa`/`tesa`. 24 in veryslow; raise it for fast motion or high resolutions. |
| `--rc-lookahead` | `40` | Frames analysed for frame types and MB-tree. 60 in slower and up; more costs memory and speed. |
| `--trellis` | `1` | Rate-distortion optimized quantization: 0 off, 1 final decision, 2 all decisions. |
| `--keyint` / `--min-keyint` | `250` / auto | Maximum and minimum keyframe interval in frames. Lower `--keyint` gives faster seeking and is often set to about 10 × the frame rate. |
| `--open-gop` | Off | Lets frames reference across keyframe boundaries for slightly better compression. Leave it off if the stream will be cut or segmented at keyframes. |
| `--threads` | auto | 1.5 × the logical CPU count by default. x264 scales well, so only lower it to leave CPU for other work. |

## 10-bit, 4:2:2 and 4:4:4

Current x264 builds include 8-bit and 10-bit in one binary (`--output-depth 10`, or `-pix_fmt yuv420p10le` in FFmpeg). 10-bit H.264 (High 10 profile) reduces banding and compresses a little better, which made it popular for anime releases, but few hardware decoders, phones, TVs or browsers support it. Use 10-bit x264 only when the video will be played in software players.

FFmpeg 9.0.2 still refuses to write more than 8 bits to Y4M without `-strict -1`, so a 10-bit pipe looks like this:

```sh
ffmpeg -i input.mkv -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe - | x264 --demuxer y4m --output-depth 10 --preset slow --crf 20 -o output.mkv -
```

x264 also encodes 4:0:0, 4:2:2 and 4:4:4 (`--output-csp`, or the input pixel format in FFmpeg) and RGB (`--output-csp rgb`, or `libx264rgb` in FFmpeg). These use the High 4:2:2 and High 4:4:4 Predictive profiles, which have even less decoder support.

## Lossless

`--qp 0` (`-qp 0` in FFmpeg) is lossless and uses the High 4:4:4 Predictive profile. `--crf 0` is also lossless with 8-bit output but not with 10-bit, so use `--qp 0`. Slower presets make smaller lossless files.

Lossless x264 is a very fast intermediate format. `--preset ultrafast` gives the fastest encoding and decoding, and adding `--tune fastdecode` speeds decoding further; `--preset superfast` produces noticeably smaller files and is still very fast. For archival, compare against [FFV1](/codecs/video/ffv1/), which is designed for that job and has wider support in archival tools.

## Complete standalone parameter reference

Every long option in the x264 r3222 command-line parser, grouped as in `x264 --fullhelp`, with short forms where they exist. Defaults are x264's own with `--preset medium` and no tune or profile; presets, tunes and `--profile` change many of them. Apart from `--range`, the Video Usability Info options only write metadata and never convert the picture. Optional demuxers, muxers and OpenCL support depend on how your binary was built.

<details>
<summary>Help</summary>

| Option | Default | Description |
| --- | --- | --- |
| `-h`, `--help` | — | Print the basic options and exit. |
| `--longhelp` | — | Print the basic and common advanced options and exit. |
| `--fullhelp` | — | Print every option, including what each preset and tune changes, and exit. |

</details>

<details>
<summary>Presets</summary>

| Option | Default | Description |
| --- | --- | --- |
| `--profile` | none (lowest profile the settings need) | Restrict output to an H.264 profile: `baseline`, `main`, `high`, `high10`, `high422` or `high444`. Turns off tools the profile forbids, overriding other options, and fails if the bit depth, chroma format or lossless mode needs a higher profile. |
| `--preset` | medium | Speed/compression trade-off: `ultrafast`, `superfast`, `veryfast`, `faster`, `fast`, `medium`, `slow`, `slower`, `veryslow`, `placebo`. Applied first; any option you set explicitly overrides it. Use the slowest preset you can afford. |
| `--tune` | none | Adjust for the source or use case. Psy tunes (pick at most one): `film`, `animation`, `grain`, `stillimage`, `psnr`, `ssim`. Others: `fastdecode`, `zerolatency`. Combine with commas, e.g. `film,fastdecode`. |
| `--slow-firstpass` | off | Keep the full analysis settings in `--pass 1`. By default the first pass switches to `--ref 1 --me dia --partitions none --trellis 0 --no-8x8dct` and at most `--subme 2` for speed. `placebo` implies it. |

</details>

<details>
<summary>Frame-type options</summary>

| Option | Default | Description |
| --- | --- | --- |
| `-I`, `--keyint` | 250 | Maximum distance between IDR frames, in frames; `infinite` for none. Lower it for faster seeking or to match a streaming segment length. |
| `-i`, `--min-keyint` | auto (`keyint`/10, at most the frame rate) | Minimum distance between IDR frames. A scene cut closer than this to the previous IDR gets a non-IDR I-frame instead. Clamped to `keyint`/2+1. |
| `--no-scenecut` | off | Disable scene-cut detection, so keyframes are placed only by `--keyint`. Same as `--scenecut 0`. |
| `--scenecut` | 40 | Scene-cut sensitivity: higher values insert I/IDR frames at more scene changes. `0` disables detection. |
| `--intra-refresh` | off | Replace IDR keyframes with a column of intra blocks that sweeps across the picture over `keyint` frames. Evens out frame sizes for low-latency streaming; forces `--ref 1`, and disables `--open-gop`. |
| `-b`, `--bframes` | 3 | Maximum consecutive B-frames, 0–16. With adaptive B-frames x264 uses fewer where that is cheaper. |
| `--b-adapt` | 1 | B-frame placement: `0` always use `--bframes`, `1` fast, `2` optimal (slower, especially with many B-frames). |
| `--b-bias` | 0 | Bias the adaptive B-frame decision toward (positive) or against (negative) B-frames, −90 to 100. |
| `--b-pyramid` | normal | Let B-frames be used as references: `none`, `strict` (hierarchy allowed by Blu-ray) or `normal`. Needs at least 2 B-frames. |
| `--open-gop` | off | Let frames after a keyframe reference frames before it, with recovery-point SEI marking the random-access point. Slightly more efficient; some players and editors handle open GOPs poorly. Needs B-frames. |
| `--no-cabac` | off | Use CAVLC instead of CABAC entropy coding: larger files, faster decoding. Required for Baseline profile. |
| `-r`, `--ref` | 3 | Maximum reference frames, 1–16. More helps compression with diminishing returns and costs speed and decoder memory. If you set `--level` but not `--ref`, x264 lowers it to fit the level's DPB. |
| `--no-deblock` | off | Disable the in-loop deblocking filter. |
| `-f`, `--deblock` | 0:0 | Deblocking strength and threshold offsets as `alpha:beta`, each −6 to 6. Negative values keep more fine detail and grain, positive values smooth more. A single number sets both. |
| `--slices` | 0 (one slice) | Slices per frame. Forces rectangular slices; overridden by `--slice-max-size` and `--slice-max-mbs`. Mainly for specs that require slices (Blu-ray, broadcast). |
| `--slices-max` | 0 (no limit) | Absolute maximum slices per frame; takes priority over `--slice-max-size` and `--slice-max-mbs`. |
| `--slice-max-size` | 0 (off) | Maximum slice size in bytes, including NAL overhead. Used to fit slices into network packets. |
| `--slice-max-mbs` | 0 (off) | Maximum macroblocks per slice. |
| `--slice-min-mbs` | 0 (off) | Minimum macroblocks per slice when slices are split by size or macroblock count. |
| `--tff` | off | Encode interlaced, top field first. x264 also switches to interlaced coding when the input is flagged interlaced. |
| `--bff` | off | Encode interlaced, bottom field first. |
| `--constrained-intra` | off | Intra macroblocks may only predict from intra-coded neighbours. Limits error propagation; costs compression. |
| `--pulldown` | none | Soft pulldown: code progressive frames and flag repeated fields/frames with pic_struct. Values: `none`, `22`, `32`, `64`, `double`, `triple`, `euro`; `32` turns 23.976p into 29.97i. Requires CFR input. |
| `--fake-interlaced` | off | Flag the stream as interlaced while coding progressive frames. Allows 25p and 30p on Blu-ray, which only permits those rates as interlaced. |
| `--frame-packing` | -1 (none) | Stereo 3D frame-packing SEI: 0 checkerboard, 1 column interleave, 2 row interleave, 3 side by side, 4 top-bottom, 5 frame alternation, 6 2D, 7 tile format. |

</details>

<details>
<summary>Ratecontrol</summary>

| Option | Default | Description |
| --- | --- | --- |
| `-q`, `--qp` | none (CRF mode) | Constant-QP mode. Range 0–69 for 8-bit and 0–81 for 10-bit output (10-bit QPs are 12 higher for the same quantizer step); `0` is lossless. Turns off AQ and MB-tree, so CRF compresses better at the same quality. |
| `-B`, `--bitrate` | none | Average bitrate in kbit/s (ABR). Use it with `--pass` for a target file size, or with VBV for capped streaming; single-pass ABR without VBV is the weakest mode. |
| `--crf` | 23.0 | Constant rate factor, the default mode: constant quality with variable bitrate. Lower is better quality; +6 roughly halves the bitrate. Range 0–51 for 8-bit and −12–51 for 10-bit output; CRF 0 is lossless only for 8-bit. 17–28 is the usual range. |
| `--rc-lookahead` | 40 | Frames analysed ahead for frame-type decisions, MB-tree and VBV, up to 250. More helps MB-tree slightly but adds memory and latency. Capped at the larger of `--keyint` and the VBV buffer duration. |
| `--vbv-maxrate` | 0 (off) | VBV maximum rate in kbit/s; needs `--vbv-bufsize`. With CRF it caps peaks; set it equal to `--bitrate` for CBR-like output. |
| `--vbv-bufsize` | 0 (off) | VBV buffer size in kbit; needs `--vbv-maxrate` except in ABR mode, where maxrate defaults to the bitrate. Buffer size divided by maxrate is roughly the averaging window in seconds. |
| `--vbv-init` | 0.9 | Initial VBV buffer fill: values up to 1 are a fraction of `--vbv-bufsize`, larger values are in kbit. |
| `--crf-max` | none | With CRF and VBV, the highest rate factor VBV may push to. Stops quality collapsing in hard scenes but can cause VBV underflows. |
| `--qpmin` | 0 | Lowest QP rate control may use. Raising it saves bits on easy content at the cost of quality there. |
| `--qpmax` | 81 (no cap) | Highest QP rate control may use. The default is clamped to x264's internal maximum for the bit depth (69 for 8-bit, 81 for 10-bit). Lowering it prevents very coarse frames but can break bitrate or VBV targets. |
| `--qpstep` | 4 | Maximum QP change between consecutive frames, minimum 2. |
| `--ratetol` | 1.0 | How far ABR may drift from the target bitrate while spreading bits (higher = freer distribution, less exact size); also how aggressively VBV avoids underflow. Accepts `inf`. |
| `--ipratio` | 1.40 | QP factor between I- and P-frames: 1.4 makes I-frames about 3 QP lower. |
| `--pbratio` | 1.30 | QP factor between P- and B-frames. Has no effect with MB-tree on (the default), which sets B-frame QPs itself. |
| `--chroma-qp-offset` | 0 | Chroma QP offset relative to luma, −12 to 12. x264 adds its own adjustment on top: −2 with psy-rd (−1 below 0.25), another −1 or −2 with psy-trellis, and +6 for 4:4:4 with psy on. |
| `--aq-mode` | 1 | Adaptive quantization: `0` off, `1` variance AQ, `2` auto-variance, `3` auto-variance biased toward dark scenes. AQ moves bits from detailed to flat areas, reducing banding and blocking; mode 3 helps dark gradients. |
| `--aq-strength` | 1.0 | AQ strength, 0–3; `0` disables AQ. Tunes set 0.6 (`animation`), 0.5 (`grain`) and 1.2 (`stillimage`). |
| `-p`, `--pass` | none | Multipass: `1` writes the stats file, `2` reads it (final pass), `3` reads and rewrites it (middle passes). Use with `--bitrate` for an exact file size. |
| `--stats` | x264_2pass.log | Stats file for `--pass`. With MB-tree, x264 also writes `<file>.mbtree`. |
| `--no-mbtree` | off | Disable MB-tree, which lowers QP for blocks that later frames reference. MB-tree is a large compression gain; leave it on. |
| `--qcomp` | 0.60 | Quantizer curve compression, 0–1: 0 is constant bitrate, 1 is constant QP. Also sets MB-tree strength (higher = weaker); `1` disables MB-tree. `--tune grain` uses 0.8. |
| `--cplxblur` | 20.0 | Temporal smoothing of frame complexity before the QP curve is applied; reduces QP fluctuation in ABR and multipass. |
| `--qblur` | 0.5 | Temporal smoothing of QPs after the curve is applied (multipass). |
| `--zones` | none | Per-range overrides, separated by `/`: `start,end,q=N` (force QP) or `start,end,b=F` (bitrate multiplier), optionally followed by more `option=value` settings such as `crf=` or `deblock=`. Frame numbers are inclusive. |
| `--qpfile` | none | File of `frame type [QP]` lines that force frame types (`I`, `i`, `K`, `P`, `B`, `b`) and optional QPs. `K` is an IDR, or a recovery-point I-frame with `--open-gop`. Used to put keyframes on chapter or segment boundaries. |

</details>

<details>
<summary>Analysis</summary>

| Option | Default | Description |
| --- | --- | --- |
| `-A`, `--partitions` | p8x8,b8x8,i8x8,i4x4 | Macroblock partitions searched: `p8x8`, `p4x4`, `b8x8`, `i8x8`, `i4x4`, `none`, `all`. `p4x4` needs `p8x8`; `i8x8` needs 8×8 DCT. `slower` and above use `all`. |
| `--direct` | spatial | Direct motion-vector prediction in B-frames: `none`, `spatial`, `temporal` or `auto` (picks per frame; used from `slow` up). |
| `--no-weightb` | off | Disable weighted prediction in B-frames. |
| `--weightp` | 2 | Weighted prediction in P-frames, mainly for fades: `0` off, `1` weighted references, `2` also adds duplicate references with different weights. Some players mishandle `2`; `--bluray-compat` limits it to 1. |
| `--me` | hex | Integer-pel motion search: `dia` (fastest), `hex`, `umh` (uneven multi-hexagon, used by `slower` and `veryslow`), `esa` (exhaustive), `tesa` (exhaustive with Hadamard transform). Beyond `umh` the gains are tiny. |
| `--merange` | 16 | Motion search range in pixels, 4–1024. With `dia` and `hex` anything above 16 is ignored; `veryslow` uses 24 with `umh`. |
| `--mvrange` | -1 (auto) | Maximum vertical motion-vector length in pixels. Auto uses the level's limit; lower it only for a decoder that needs it. |
| `--mvrange-thread` | -1 (auto) | Minimum row buffer between frame threads, in pixels. Limits how far motion vectors may reach into a frame still being encoded; leave on auto. |
| `-m`, `--subme` | 7 | Subpixel refinement and mode decision, 0–11: 1–5 progressively more quarter-pel search, 6 RD mode decision on I/P-frames, 7 on all frames, 8–9 RD refinement, 10 QP-RD (needs `--trellis 2` and AQ), 11 full RD. Psy-RD needs 6 or higher. |
| `--psy-rd` | 1.0:0.0 | Psychovisual strengths as `rd:trellis`, each 0–10. Psy-RD (needs `--subme` 6+) keeps detail and grain instead of blurring them; psy-trellis (needs trellis) does the same during quantization. A single number sets psy-RD and zeroes psy-trellis. Tunes: `film` `:0.15`, `grain` `:0.25`, `animation` `0.4:`, `stillimage` `2.0:0.7`. |
| `--no-psy` | off | Disable all psychovisual optimizations that lower PSNR and SSIM, including psy-RD and psy-trellis. Used by `--tune psnr` and `--tune ssim`; the result looks worse. |
| `--no-mixed-refs` | off | Choose references per macroblock instead of per 8×8 partition. Slightly faster and less efficient; irrelevant with `--ref 1`. |
| `--no-chroma-me` | off | Use only luma in motion search. Slightly faster, slightly worse. |
| `--no-8x8dct` | off | Disable the adaptive 8×8 transform, a High-profile tool. Main and Baseline profiles turn it off. |
| `-t`, `--trellis` | 1 | Trellis (rate-distortion optimized) quantization: `0` off, `1` on the final encode of each macroblock, `2` in all mode decisions (`slow` and above). Psy-trellis needs it. |
| `--no-fast-pskip` | off | Disable early skip detection in P-frames. Slower; can help flat areas and gradients. `placebo` uses it. |
| `--no-dct-decimate` | off | Keep the small coefficients that DCT decimation would zero in inter blocks. Preserves fine detail and grain at a bit cost; used by `--tune grain`. |
| `--nr` | 0 (off) | Fast noise reduction in the DCT domain, 0–65536. Values of a few hundred are typical; a real denoising filter does a better job. |
| `--deadzone-inter` | 21 | Inter luma quantization deadzone, 0–32: larger values discard more small coefficients. Only applies where trellis is not used (everything with `--trellis 0`, mode decisions with `--trellis 1`). `--tune grain` sets 6. |
| `--deadzone-intra` | 11 | Intra luma quantization deadzone, 0–32. Same rules as `--deadzone-inter`. |
| `--cqm` | flat | Quantization-matrix preset: `flat` or `jvt` (the JVT default matrices). Non-flat matrices need High profile. |
| `--cqmfile` | none | Read custom matrices from a JM-format file. Overrides all other `--cqm*` options. |
| `--cqm4` | flat | Set all four 4×4 matrices: 16 comma-separated integers. |
| `--cqm8` | flat | Set all 8×8 matrices: 64 comma-separated integers. |
| `--cqm4i`, `--cqm4p`, `--cqm8i`, `--cqm8p` | flat | Set intra or inter (`p`) 4×4 or 8×8 matrices for luma and chroma together: 16 or 64 integers. |
| `--cqm4iy`, `--cqm4ic`, `--cqm4py`, `--cqm4pc` | flat | Set one 4×4 matrix (intra/inter × luma/chroma): 16 integers. |

</details>

<details>
<summary>Video Usability Info (Annex E)</summary>

| Option | Default | Description |
| --- | --- | --- |
| `--overscan` | undef | Overscan hint: `undef`, `show` or `crop`. |
| `--videoformat` | undef | Analog source format flag: `component`, `pal`, `ntsc`, `secam`, `mac` or `undef`. |
| `--range` | auto (from input; `pc` for RGB) | Signalled sample range: `tv` (limited) or `pc` (full). If it differs from the input range, the CLI converts the samples. |
| `--colorprim` | undef | Colour primaries flag, e.g. `bt709`, `bt470bg`, `smpte170m`, `bt2020`. |
| `--transfer` | undef | Transfer characteristics flag, e.g. `bt709`, `smpte2084` (PQ), `arib-std-b67` (HLG). |
| `--colormatrix` | auto (`GBR` for RGB, otherwise `undef`) | Matrix coefficients flag, e.g. `bt709`, `bt470bg`, `smpte170m`, `bt2020nc`. |
| `--chromaloc` | 0 | Chroma sample location type, 0–5. `0` (left) suits most 4:2:0 video; `2` (top-left) is used for BT.2020/UHD. |
| `--mastering-display` | none | HDR10 mastering display SEI: `G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)`, chromaticity in 0.00002 units and luminance in 0.0001 cd/m². |
| `--cll` | none | Content light level SEI: `MaxCLL,MaxFALL` in cd/m². |
| `--alternative-transfer` | undef | Alternative transfer characteristics SEI, same values as `--transfer`. Used for HLG: `--transfer bt2020-10 --alternative-transfer arib-std-b67`. |
| `--nal-hrd` | none | Write HRD parameters and buffering-period/picture-timing SEI: `none`, `vbr` or `cbr`. Requires VBV. Needed for broadcast and Blu-ray; `cbr` pads with filler and is not allowed in MP4. |
| `--filler` | off | Hard CBR: add filler data so the stream never drops below `--vbv-maxrate`. Implied by `--nal-hrd cbr`. |
| `--pic-struct` | off | Always write pic_struct in picture-timing SEI. Pulldown and interlaced coding write it anyway. |
| `--crop-rect` | 0,0,0,0 | Add `left,top,right,bottom` to the bitstream cropping rectangle, so decoders hide those pixels. Values must be multiples of the chroma subsampling. |

</details>

<details>
<summary>Input/Output</summary>

| Option | Default | Description |
| --- | --- | --- |
| `-o`, `--output` | required | Output file. The extension selects the container: `.mkv`, `.flv`, `.mp4` (needs L-SMASH or GPAC), anything else raw H.264; `-` writes raw H.264 to stdout. |
| `--muxer` | auto | Force the container: `auto`, `raw`, `mkv`, `flv` or `mp4`. |
| `--demuxer` | auto | Force the input reader: `auto`, `raw`, `y4m`, plus `avs`, `lavf` and `ffms` when compiled in. |
| `--input-fmt` | none | Force the libavformat input format (lavf builds only). |
| `--input-csp` | i420 (raw) | Pixel format of raw input, e.g. `i420`, `nv12`, `i422`, `i444`, `rgb`. Y4M, lavf and ffms inputs carry their own. |
| `--output-csp` | i420 | Chroma format to encode: `i400`, `i420`, `i422`, `i444` or `rgb`. The CLI converts other inputs to it, so a 4:2:2 or 4:4:4 source is encoded as 4:2:0 unless you set this. |
| `--input-depth` | 8 (raw) | Bit depth of raw input, 8–16. Y4M carries its own. |
| `--output-depth` | 8 (10 in a 10-bit-only build) | Encoding bit depth, 8 or 10. Current builds support both in one binary; input of another depth is converted, with dithering when reducing. |
| `--input-range` | auto | Range of the input: `auto`, `tv` or `pc`. Overrides what the demuxer reports. |
| `--input-res` | required (raw) | Size of raw input as `WIDTHxHEIGHT`. |
| `--index` | none | Index file for the ffms demuxer; written on the first run and reused afterwards. |
| `--sar` | from input | Sample (pixel) aspect ratio as `W:H`, e.g. `1:1` or `40:33`. Set it for anamorphic video. |
| `--fps` | from input (25 for raw) | Frame rate as a decimal or rational (`24000/1001`). Forces constant-frame-rate timestamps. |
| `--seek` | 0 | First input frame to encode (0-based). |
| `--frames` | all | Maximum number of frames to encode. |
| `--level` | auto | H.264 level to signal, e.g. `4.1`, `41` or `1b`. Without `--ref`, x264 reduces the reference count to fit; it only warns about VBV and other limits, so set `--vbv-maxrate` and `--vbv-bufsize` for real compliance. |
| `--bluray-compat` | off | Blu-ray restrictions: at most 3 B-frames and 6 references, strict pyramid, `--weightp` 1 or lower, AUDs, HRD (vbr), no intra refresh, `--min-keyint 1`. Combine with the other Blu-ray settings (level, VBV, slices, keyint). |
| `--avcintra-class` | 0 (off) | Produce AVC-Intra class 50, 100, 200, 300 or 480 (300 and 480 need `--avcintra-flavor sony`). Requires a matching resolution, frame rate and pixel format, and overrides most settings. |
| `--avcintra-flavor` | panasonic | AVC-Intra variant: `panasonic` or `sony` (XAVC). |
| `--stitchable` | off | Don't optimize headers for the content, so separately encoded segments can be joined. |
| `-v`, `--verbose` | off | Print statistics for every frame (debug log level). |
| `--no-progress` | off | Hide the progress line. |
| `--quiet` | off | Suppress all log output. |
| `--log-level` | info | Log verbosity: `none`, `error`, `warning`, `info` or `debug`. |
| `--psnr` | off | Compute and report PSNR. x264 warns that the numbers are invalid unless psy is off and AQ is off (`--tune psnr`). |
| `--ssim` | off | Compute and report SSIM. x264 warns unless psy is off and AQ is on (`--tune ssim`). |
| `--threads` | auto (1.5 × logical CPUs) | Frame-encoding threads, up to 128. Auto is also limited to one thread per two macroblock rows. Very high counts cost a little compression. |
| `--lookahead-threads` | auto | Threads for the lookahead; auto derives a count from `--threads` and the analysis settings. |
| `--sliced-threads` | off | Thread by slices within a frame instead of by frames: no extra latency, but less efficient. Used by `--tune zerolatency`. |
| `--thread-input` | auto (on with more than one thread) | Read and decode input in its own thread. |
| `--sync-lookahead` | auto (`bframes` + 1) | Frames buffered between the threaded lookahead and the encoder; `0` disables threaded lookahead for lower latency. |
| `--non-deterministic` | off | Let frame threads use slightly more information for marginally better quality, at the cost of run-to-run repeatability. |
| `--cpu-independent` | off | Produce identical output on different CPUs by not letting them pick different algorithms. |
| `--asm` | auto | Override CPU feature detection with a bitmask or comma-separated names (e.g. `sse2,avx2`). For debugging. |
| `--no-asm` | off | Disable all assembly optimizations. Much slower; for debugging. |
| `--opencl` | off | Use OpenCL for the lookahead (OpenCL builds, 8-bit only). |
| `--opencl-clbin` | none | File for caching the compiled OpenCL kernel. |
| `--opencl-device` | 0 | OpenCL device index. |
| `--dump-yuv` | none | Write reconstructed frames to a raw YUV file, for debugging. |
| `--sps-id` | 0 | ID written into the SPS and PPS, 0–31. |
| `--aud` | off | Write access unit delimiters. Some broadcast, transport-stream and Blu-ray targets need them. |
| `--force-cfr` | off | Ignore input timestamps and generate constant-frame-rate ones. |
| `--tcfile-in` | none | Take timestamps from a Matroska timecode v1 or v2 file for VFR output. Can't be combined with `--fps`. |
| `--tcfile-out` | none | Write the input timestamps to a timecode v2 file. |
| `--timebase` | from input | Timebase as `num/den`. A single integer is the numerator with `--tcfile-in` and the denominator otherwise. Not allowed with CFR input. |
| `--dts-compress` | off | Remove the initial delay caused by B-frames by shifting DTS in FLV and MP4 output. |

</details>

<details>
<summary>Filtering</summary>

| Option | Default | Description |
| --- | --- | --- |
| `--vf`, `--video-filter` | none | Input filter chain, filters separated by `/`: `crop:left,top,right,bottom`, `select_every:step,offset1[,...]`, and `resize` (scaling, SAR and pixel-format conversion) in builds with libswscale. |

</details>

<details>
<summary>Additional accepted flags and aliases</summary>

| Option | Default | Description |
| --- | --- | --- |
| `-V`, `--version` | — | Print the version and build configuration and exit. |
| `--no-b-adapt` | off | Same as `--b-adapt 0`. |
| `--nf` | off | Old spelling of `--no-deblock`. |
| `--filter` | 0:0 | Old spelling of `--deblock`. |
| `--interlaced` | off | Encode interlaced; field order defaults to top field first. |
| `--no-interlaced` | off | Encode progressive even if the input is flagged interlaced. |
| `--cabac` | on | Use CABAC entropy coding (the default). |
| `--stdout` | auto | Old alias of `--muxer`; takes the same values. |
| `--stdin` | auto | Old alias of `--demuxer`; takes the same values. |
| `--analyse` | p8x8,b8x8,i8x8,i4x4 | Old spelling of `--partitions`. |
| `-w`, `--weightb` | on | Weighted prediction in B-frames (the default). |
| `--psy` | on | Psychovisual optimizations (the default). |
| `--mixed-refs` | on | Per-partition reference selection (the default). |
| `-8`, `--8x8dct` | on | Adaptive 8×8 transform (the default). |
| `--fast-pskip` | on | Early P-frame skip detection (the default). |
| `--mbtree` | on | MB-tree rate control (the default). |
| `--no-sliced-threads` | on (frame threading) | Thread by frames (the default); cancels `--sliced-threads`. |

</details>

## Complete FFmpeg libx264 private options

The private `libx264` options in FFmpeg 9.0.2; the last column names the x264 setting each one sets. A default of `-1`, `auto`, `unset` or `INT_MIN` means not set: FFmpeg passes nothing and x264's preset value applies, so `-crf -1` does not mean CRF −1. Generic FFmpeg options also reach x264: `-b:v` (`--bitrate`), `-maxrate` and `-bufsize` (VBV), `-g` (`--keyint`), `-keyint_min`, `-bf` (`--bframes`), `-refs`, `-qmin`, `-qmax`, `-qcomp`, `-trellis`, `-me_range`, `-subq`, `-threads` and the stream's colour metadata. `-x264-params` and `-x264opts` take x264 library settings, not CLI-only options such as `--output` or `--demuxer`.

<details>
<summary>All libx264 private options</summary>

| Option | Type | Default | Range / values | Maps to and meaning |
| --- | --- | --- | --- | --- |
| `-preset` | `string` | `medium` | string | x264 `--preset`. |
| `-tune` | `string` | `unset` | string | x264 `--tune`; combine with commas, e.g. `film,fastdecode`. |
| `-profile` | `string` | `unset` | string | x264 `--profile`: `baseline`, `main`, `high`, `high10`, `high422`, `high444`. |
| `-fastfirstpass` | `boolean` | `true` | `0` to `1` | With `-pass 1`, use x264's fast first-pass settings. `0` is the same as x264 `--slow-firstpass`. |
| `-level` | `string` | `unset` | string | x264 `--level`, e.g. `4.1`. |
| `-passlogfile` | `string` | `unset` | string | Same field as `-stats`. On the `ffmpeg` command line this name belongs to the generic two-pass prefix option, which sets `stats` to `<prefix>-<stream index>.log` (default `ffmpeg2pass-0.log`). |
| `-wpredp` | `string` | `unset` | string | x264 `--weightp` as a string (`0`, `1`, `2`). Older duplicate of `-weightp`, which wins if both are set. |
| `-a53cc` | `boolean` | `true` | `0` to `1` | Write A/53 closed captions from the input frames as SEI. |
| `-x264opts` | `string` | `unset` | string | x264 settings as `key=value:key=value`; a bare `key` means `key=1`. Applied after the other wrapper options. An unknown key or bad value stops the encode. |
| `-crf` | `float` | `-1` | `-1` to `FLT_MAX` | x264 `--crf`. Takes priority over `-b:v` and `-qp`; ignored with `-pass 2`. |
| `-crf_max` | `float` | `-1` | `-1` to `FLT_MAX` | x264 `--crf-max`. Ignored with `-pass 2`. |
| `-qp` | `int` | `-1` | `-1` to `INT_MAX` | x264 `--qp` (constant QP, `0` = lossless). Used only if `-crf` is not set; ignored with `-pass 2`. |
| `-aq-mode` | `int` | `-1` | `-1` to `INT_MAX`; `none`=`0`, `variance`=`1`, `autovariance`=`2`, `autovariance-biased`=`3` | x264 `--aq-mode`. |
| `-aq-strength` | `float` | `-1` | `-1` to `FLT_MAX` | x264 `--aq-strength`. |
| `-psy` | `boolean` | `auto` | `-1` to `1` | x264 `--psy` (`0` = `--no-psy`). |
| `-psy-rd` | `string` | `unset` | string | x264 `--psy-rd`, as `rd:trellis`. |
| `-rc-lookahead` | `int` | `-1` | `-1` to `INT_MAX` | x264 `--rc-lookahead`. |
| `-weightb` | `boolean` | `auto` | `-1` to `1` | x264 `--weightb`. |
| `-weightp` | `int` | `-1` | `-1` to `INT_MAX`; `none`=`0`, `simple`=`1`, `smart`=`2` | x264 `--weightp`. |
| `-ssim` | `boolean` | `auto` | `-1` to `1` | x264 `--ssim`: report SSIM at the end. For PSNR use the generic `-flags +psnr`. |
| `-intra-refresh` | `boolean` | `auto` | `-1` to `1` | x264 `--intra-refresh`. |
| `-bluray-compat` | `boolean` | `auto` | `-1` to `1` | x264 `--bluray-compat`; setting it also forces constant-frame-rate timestamps. |
| `-b-bias` | `int` | `INT_MIN` | `INT_MIN` to `INT_MAX` | x264 `--b-bias`; `INT_MIN` means not set. |
| `-b-pyramid` | `int` | `-1` | `-1` to `INT_MAX`; `none`=`0`, `strict`=`1`, `normal`=`2` | x264 `--b-pyramid`. |
| `-mixed-refs` | `boolean` | `auto` | `-1` to `1` | x264 `--mixed-refs`. |
| `-8x8dct` | `boolean` | `auto` | `-1` to `1` | x264 `--8x8dct`. |
| `-fast-pskip` | `boolean` | `auto` | `-1` to `1` | x264 `--fast-pskip`. |
| `-aud` | `boolean` | `auto` | `-1` to `1` | x264 `--aud`. |
| `-mbtree` | `boolean` | `auto` | `-1` to `1` | x264 `--mbtree`. |
| `-deblock` | `string` | `unset` | string | x264 `--deblock` (`alpha:beta`). |
| `-cplxblur` | `float` | `-1` | `-1` to `FLT_MAX` | x264 `--cplxblur`. |
| `-partitions` | `string` | `unset` | `p8x8`, `p4x4`, `b8x8`, `i8x8`, `i4x4`, `none`, `all` | x264 `--partitions`, comma-separated. |
| `-direct-pred` | `int` | `-1` | `-1` to `INT_MAX`; `none`=`0`, `spatial`=`1`, `temporal`=`2`, `auto`=`3` | x264 `--direct`. |
| `-slice-max-size` | `int` | `-1` | `-1` to `INT_MAX` | x264 `--slice-max-size`, in bytes. |
| `-stats` | `string` | `unset` | string | x264 `--stats`. The `ffmpeg` CLI fills it in from `-passlogfile` when you use `-pass`. |
| `-nal-hrd` | `int` | `-1` | `-1` to `INT_MAX`; `none`=`0`, `vbr`=`1`, `cbr`=`2` | x264 `--nal-hrd`; needs `-maxrate` and `-bufsize`. `cbr` is not allowed in MP4. |
| `-avcintra-class` | `int` | `-1` | `-1` to `480` | x264 `--avcintra-class`; 300 and 480 also select the Sony flavor. |
| `-me_method` | `int` | `-1` | `-1` to `4`; `dia`=`0`, `hex`=`1`, `umh`=`2`, `esa`=`3`, `tesa`=`4` | x264 `--me`; same field as `-motion-est`. |
| `-motion-est` | `int` | `-1` | `-1` to `4`; `dia`=`0`, `hex`=`1`, `umh`=`2`, `esa`=`3`, `tesa`=`4` | x264 `--me`. |
| `-forced-idr` | `boolean` | `false` | `-1` to `1` | Code forced keyframes (e.g. from `-force_key_frames`) as IDR frames. Otherwise they are x264 keyframes, which are non-IDR recovery points with open GOP. |
| `-coder` | `int` | `default` | `-1` to `1`; `default`=`-1`, `cavlc`=`0`, `cabac`=`1`, `vlc`=`0`, `ac`=`1` | Entropy coder: `cabac`/`ac` or `cavlc`/`vlc`. `default` keeps x264's choice (CABAC unless the profile or tune disables it). |
| `-b_strategy` | `int` | `-1` | `-1` to `2` | x264 `--b-adapt` (0, 1, 2). |
| `-chromaoffset` | `int` | `0` | `INT_MIN` to `INT_MAX` | x264 `--chroma-qp-offset`; `0` leaves x264's value. |
| `-sc_threshold` | `int` | `-1` | `INT_MIN` to `INT_MAX` | x264 `--scenecut`; `0` disables scene-cut detection. |
| `-noise_reduction` | `int` | `-1` | `INT_MIN` to `INT_MAX` | x264 `--nr`. |
| `-udu_sei` | `boolean` | `false` | `0` to `1` | Write user-data-unregistered SEI from the input frames' side data. |
| `-x264-params` | `dictionary` | `unset` | `key=value` list | x264 settings as `key=value:key=value`, using x264's long option names without `--` (e.g. `no-mbtree=1`). Applied last, so it overrides everything else. An invalid entry only logs a warning and is skipped. |
| `-mb_info` | `boolean` | `false` | `0` to `1` | Pass per-macroblock hints (`AVVideoHint` side data) to x264. Only useful for applications using the API. |

</details>

## Related pages

- [H.264 / AVC](/codecs/video/avc/)
- [x265](/tools/software-encoders/x265/)
- [FFmpeg](/tools/utilities/ffmpeg/)
- [MKVToolNix](/tools/utilities/mkvtoolnix/)
- [Psychovisual optimization](/start-here/psychovisual/)
