encoding-guide

Basics of Encoding Settings: x264

Encoding video is the process of compressing raw footage into a manageable size while maintaining as much quality as possible. With x264, you can achieve excellent results by tweaking its advanced settings to match your source and goals.


What is Encoding?

Encoding reduces the size of video files while ensuring playback compatibility across devices. It’s essential for:


Understanding x264

x264 is an encoder for the H.264 (AVC) format. It balances quality, compression, and playback compatibility. With x264, you can adjust numerous settings to fine-tune your output. These settings fall into two categories:

  1. General Settings: Rarely changed between encodes.
  2. Source-Specific Settings: Adjusted based on the source material.

General Settings

These settings can usually stay consistent across encodes.

1. Preset

The preset determines how fast or slow the encoder works. Slower presets take longer but provide better compression and quality.


2. Level

The level limits the encoder’s features to ensure compatibility with playback devices.


3. Motion Estimation (ME)

Motion estimation helps the encoder predict and compress motion between frames.


4. Ratecontrol Lookahead

This setting determines how far ahead the encoder can look when distributing bits.


Source-Specific Settings

These settings depend on the type of video you’re encoding.

1. Profile

Defines the encoder’s features and compatibility with playback devices.


2. Ratecontrol

Controls how bits are distributed across frames.

CRF (Constant Rate Factor)

Two-Pass Encoding


3. Deblock

Smooths edges between blocks, reducing artifacts.


4. Chroma Quantizer Offset

Adjusts how bits are allocated to chroma (color) channels.


5. Quantizer Curve Compression

Adjusts bit distribution between complex and simple scenes.


6. Macroblock Tree

Improves bit distribution within complex scenes.


7. Adaptive Quantization

Distributes bits within frames and across adjacent frames.


8. Psycho-Visual Rate Distortion Optimization (Psy-RDO)

Improves perceptual quality by slightly distorting frames for sharpness.


Here’s a full command combining the settings above:

vspipe -c y4m script.vpy - | x264 --demuxer y4m --preset placebo --level 41 --crf 16.9 --me umh --rc-lookahead 250 --profile high --deblock -2:-1 --chroma-qp-offset -1 --qcomp 0.70 --aq-mode 3 --aq-strength 0.80 --psy-rd 1.00:0 -o output.h264 -

Conclusion

The recommended x264 settings provide a starting point for high-quality encodes. Adjust these based on your source material and playback requirements to achieve the best results.