x264 is a free, open-source software encoder that converts uncompressed or decoded video into an H.264 (MPEG-4 AVC) bitstream. Among video codecs it is not a format of its own but an implementation of one: the H.264 standard defines what a decoder must understand, while x264 decides how to produce a compliant stream with the best possible quality per bit.
Developed under the VideoLAN project and released under the GPL license, x264 runs as a command-line program and as the libx264 library inside tools such as FFmpeg and HandBrake. For well over a decade it has served as the reference point for H.264 encoding quality, and many streaming, archiving and broadcast workflows still rely on it.
How x264 encodes a video stream
x264 encodes video by predicting each block of a frame from data the decoder already has and storing only the prediction residual. Every frame is split into 16×16 macroblocks, which may be subdivided into smaller partitions for motion search and transform coding.
The encoder chooses between intra prediction inside the same frame and inter prediction from reference frames, using motion vectors to describe movement. The residual is transformed, quantized and entropy-coded with either CABAC or CAVLC. The quantization step is where data is discarded, so it decides the balance between file size and visible detail.
What distinguishes x264 from a basic encoder is its decision logic. It runs rate-distortion optimization to compare many candidate modes, a lookahead buffer that analyzes upcoming frames, and macroblock-tree (mb-tree) analysis that spends more bits on blocks that later frames will reference. The following table summarizes the main internal stages.
| Stage | What it does | Effect on output |
|---|---|---|
| Lookahead | Analyzes upcoming frames, 40 by default | Better frame type and bit allocation |
| Frame type decision | Places I-, P- and B-frames adaptively | Fewer bits on predictable scenes |
| Motion estimation | Searches reference frames for matching blocks | Smaller residuals, slower encoding |
| Mode decision with RDO | Compares partition and prediction choices | Higher quality per bit |
| Adaptive quantization | Varies quantizer across regions of a frame | Less banding in flat areas |
| Entropy coding | Packs data with CABAC or CAVLC | CABAC saves roughly 10-15% of bits |
Presets, tunes and profiles
x264 hides hundreds of internal options behind presets, which trade encoding speed against compression efficiency. The ten presets run from ultrafast to placebo; the default is medium. A slower preset never lowers quality at a fixed rate factor: it reduces the file size, or improves quality at a fixed bitrate, by searching more thoroughly.
| Preset | Relative speed | Typical use |
|---|---|---|
| ultrafast | Fastest, weakest compression | Screen capture, test encodes |
| veryfast | Fast with reasonable efficiency | Live streaming on a single computer |
| medium | Default balance | General-purpose encoding |
| slow | Several times slower than medium | Files for distribution |
| veryslow | Very slow, near-maximum efficiency | Archives and final masters |
| placebo | Extremely slow | Rarely justified; gains are negligible |
Tunes adjust psychovisual settings for a content type: film, animation, grain, stillimage, fastdecode and zerolatency. The grain tune preserves film grain texture instead of smoothing it, while zerolatency disables B-frames and lookahead so that delay stays minimal for interactive streams.
Profiles limit the stream to features a target decoder supports. The High profile suits most modern devices, Baseline fits very old or constrained players, and High 10, High 4:2:2 and High 4:4:4 Predictive allow higher bit depth and chroma resolution. A separate level setting caps resolution, frame rate and buffer size for hardware compatibility.
Rate control modes in x264
Rate control decides how many bits each frame receives, and x264 offers several modes for different delivery goals. The most widely used is Constant rate factor (CRF), which targets a consistent perceived quality and lets the bitrate vary with scene complexity.
The CRF scale runs from 0 to 51 for 8-bit video, with 23 as the default. Values around 18 to 20 are often treated as visually transparent for typical content, and each increase of about 6 roughly halves the bitrate. CRF 0 combined with the right settings produces lossless output.
| Mode | How it behaves | Best suited for |
|---|---|---|
| CRF | Constant perceived quality, variable size | Files, archives, on-demand video |
| Two-pass ABR | Hits a target average bitrate accurately | Fixed file size or budget |
| Single-pass ABR | Approximates a bitrate without analysis | Rarely ideal; less consistent |
| VBV-constrained | Caps peak bitrate with a buffer model | Streaming and broadcast delivery |
| CQP | Fixed quantizer per frame type | Testing and research only |
For streaming, CRF or a target bitrate is usually combined with VBV settings (vbv-maxrate and vbv-bufsize) so that bitrate peaks never exceed what the network or player buffer can absorb. Without these limits, a complex scene may produce spikes that cause playback stalls.
x264 compared with other encoders
x264 is best understood next to other encoders, because users usually choose between software and hardware encoding or between H.264 and newer formats. Its strength is efficiency and compatibility; its weakness is CPU cost at slow presets and the older generation of the underlying standard.
| Encoder | Output format | Main advantage | Main drawback |
|---|---|---|---|
| x264 | H.264 | Excellent quality and universal playback | Less efficient than newer formats |
| x265 | H.265 | Similar quality at lower bitrates | Much slower; patchier device support |
| NVENC | H.264, H.265, AV1 | Very fast, minimal CPU load | Lower efficiency at equal bitrate |
| SVT-AV1 | AV1 | Strong compression, royalty-free format | Higher decode demands on old devices |
| libvpx | VP8, VP9 | Royalty-free web formats | Slower and less tunable |
Hardware encoders such as NVENC have narrowed the gap in recent generations, yet x264 at slow or slower presets generally still produces better quality at a given bitrate. For live streaming at constrained bitrates, that margin can decide whether fast motion looks clean or blocky.
Common mistakes and limitations
Most problems with x264 come from misused settings rather than from the encoder itself. Typical errors include the following:
- Choosing a fast preset with a high bitrate instead of a slower preset at a lower bitrate.
- Using single-pass average bitrate when CRF or two-pass would give more consistent quality.
- Ignoring profile and level limits, which leads to files that some televisions or phones refuse to play.
- Encoding 10-bit output for devices that support only 8-bit H.264 decoding.
- Applying the
zerolatencytune to file encodes, which wastes compression efficiency.
x264 also has inherent limits. It encodes only H.264, so it cannot match the compression of HEVC or AV1 at very low bitrates or high resolutions. Encoding 4K material at slow presets requires substantial CPU time, and the GPL license requires care when distributing products that embed the library.
The simple explanation
Think of H.264 as a shared language that almost every phone, browser and television understands. x264 is a very skilled writer in that language. It takes a large raw video and rewrites it in a compact form that still looks good, so the file is small enough to stream or store.
The writer can work quickly and produce a rough draft, or work slowly and find shorter ways to say the same thing. That is what the presets control. The slower the setting, the smaller the file for the same visible quality.
How it is used in practice
A small production company delivers a 12-minute documentary for online platforms. The editor exports a high-quality master and then encodes the distribution file with x264 through FFmpeg, using the slow preset with CRF 19, the film tune, the High profile at level 4.1 and VBV limits of 12 Mbit/s with a 24 Mbit buffer.
The resulting 1080p file is about 1.1 GB, plays on smart televisions, browsers and older phones without conversion, and shows no visible banding in dark interview scenes. A test encode at the veryfast preset and the same CRF produced a file roughly 25% larger with similar visible quality, so the slower preset paid off in lower storage and delivery costs.