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.
Encoding reduces the size of video files while ensuring playback compatibility across devices. It’s essential for:
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:
These settings can usually stay consistent across encodes.
The preset determines how fast or slow the encoder works. Slower presets take longer but provide better compression and quality.
--preset placebo
The level limits the encoder’s features to ensure compatibility with playback devices.
--level 41
(suitable for most hardware)Motion estimation helps the encoder predict and compress motion between frames.
--me umh
This setting determines how far ahead the encoder can look when distributing bits.
--rc-lookahead 250
60
on systems with limited RAM.These settings depend on the type of video you’re encoding.
Defines the encoder’s features and compatibility with playback devices.
--profile high
(for 8-bit 4:2:0 content)--profile high444
(for 10-bit 4:4:4 or lossless content)Controls how bits are distributed across frames.
--crf 16.9
15.0
) increase quality but produce larger files.vspipe -c y4m script.vpy - | x264 --demuxer y4m --preset placebo --pass 1 --bitrate 8500 -o /dev/null -
vspipe -c y4m script.vpy - | x264 --demuxer y4m --preset placebo --pass 2 --bitrate 8500 -o out.h264 -
Smooths edges between blocks, reducing artifacts.
--deblock -2:-1
--deblock 0:0
.Adjusts how bits are allocated to chroma (color) channels.
--chroma-qp-offset -1
Adjusts bit distribution between complex and simple scenes.
--qcomp 0.70
(when using macroblock tree)Improves bit distribution within complex scenes.
--mbtree
Distributes bits within frames and across adjacent frames.
--aq-mode 3 --aq-strength 0.80
Improves perceptual quality by slightly distorting frames for sharpness.
--psy-rd 1.00:0
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 -
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.