Skip to main content

x265

x265 is a software library and command line application for encoding H.265 / HEVC developed by MulticoreWare, written in C++ and x86 assembly, and released in 2013.

By default, x265 is tuned for low-bitrate content due to the blurring filters it applies. However, it can be tuned using CLI options to be very effective for high-fidelity content as well. It is a more efficient and modern encoder compared to x264, and is currently a popular choice for both high-fidelity and mini encodes.

x265 is currently not recommended for lossless encoding. For that niche, x264 is considerably faster without meaningful efficiency loss.

FFmpeg​

x265 is available in FFmpeg via libx265, to check if you have it, run ffmpeg -h encoder=libx265.

Installation​

Pre-built binary (Recommended):

Parameters​

This section will overview the most important parameters for controlling output and quality in x265. The parameters will be listed in the format used by the standalone x265 binary, but all of the parameters should also be usable in ffmpeg in the format e.g. -x265-params pass=1.

Preset​

--preset slow

If encoding speed is a priority, x265 is probably not the best choice. x264 at --preset veryslow will likely be faster than x265 at --preset fast, while providing comparable efficiency. However, x265 finds its sweet spot at --preset slow, and this is the preset most people should use. This preset provides high quality while not being unreasonably slow.

The exception where you may want to tax your CPU by going to --preset veryslow is when doing lower bitrate encodes (e.g. crf >=22). This is because the veryslow preset provides better motion estimation at low bitrates. However, it is exceptionally slow, so it is not generally recommended for everyday use.

CRF​

--crf

CRF, standing for Constant Rate Factor, is a method for selecting a level of quality-to-filesize tradeoff. CRF is preferable to bitrate targeting because CRF only requires one encoding pass, so bitrate targeting should only be used if you need to target a specific filesize. Nowadays, those situations are uncommon and it is preferred to use CRF to target a quality level. CRF is preferable to QP because CRF allows the encoder to vary the quality level from frame to frame for better viewing quality in areas of the video that need it the most.

What CRF to use will vary depending on your goals. The range of valid CRF values is 0-51, with larger values providing smaller filesize but lower quality. Some amount of experimentation may be needed to find the value you prefer. A decent "balanced" target will be around 17 or 18, providing good quality without inflating filesize too much. For a focus on maximum quality, a value of 12 or 13 will result in visually lossless output for most videos, but will result in a much larger filesize. For miniature encodes, try raising the CRF as much as you feel comfortable before the quality becomes unbearable. CRFs of 22 or higher are generally considered "low bitrate", so how high you raise the CRF depends on how low of a filesize you are trying to achieve.

bframes​

--bframes

B-frames are bi-directional predictive frames, this means that they can reference frames both before and after themselves, which makes them very efficient. The --bframes parameter controls how many B-frames can be used consecutively. Higher values can result in better compression, but this value has diminishing returns, as the encoder won't use extra B-frames in situations where it would reduce efficiency.

The default value at preset slow is 4. It is recommended to increase this to --bframes 5 for live action and CGI content, or --bframes 8 for anime and cartoons. Content with little motion benefits more from high B-frames values, but even on anime where there are many still scenes, there is no measurable benefit to using a value higher than 8, and it would just slow down the encoder for no benefit.

SAO​

--sao, --limit-sao, --no-sao

SAO stands for Sample Adaptive Offset, and is a loop filter used by x265 to prevent artifacting. However, it has the side effect of losing sharpness on details. It is recommended to leave this on (default) at high CRF values (>=22). For medium values between 17-21, you can use --limit-sao which will limit the effects of SAO to have less of a significant effect. For low CRF values (<=16), you can safely use --no-sao to prefer detail preservation, as the higher bitrates will naturally lead to fewer artifacts.

Deblock​

--deblock

Deblock is another loop filter, this one intended to reduce blocking in videos, but may have a blurring effect at high strengths. For most encodes, it is fine to leave this at the default value. At lower CRF values, it may be desirable to lower this to --deblock -1:-1 for anime or --deblock -2:-2 for live action, in order to preserve more grain and detail.

Psy-RD​

--psy-rd and --psy-rdoq

The parameters control psychovisual rate distribution. What this means is the redistribution of bits to make a video more pleasing to human eyes. These options may be harmful to metrics that compare videos mathematically, but are better for viewing human eyes because they prioritize facets of the video that humans prefer.

--psy-rd biases toward matching the level of energy in the source image, which makes it good for retaining detail. For standard anime, it is recommended to use --psy-rd 1.0. The more grain, detail, and dark scenes in a source, the higher this should be raised. Many modern anime tends to have more detailed backgrounds and surfaces, so --psy-rd 1.5 may be a better default for modern anime. For live action, a --psy-rd 1.5 or possibly even 2.0 may be preferred, as live action naturally has more detail and grain than anime.

--psy-rdoq biases toward energy in general, which makes it key for preserving grain. --psy-rdoq 1.0 is a safe default for anime. Like psy-rd, this value should be increased more for sources with more grain. For grainy anime, --psy-rdoq 2.0 or even 3.0 can be preferable. Likewise, for many live action series, a default of --psy-rdoq 3.0 can be preferable, or even 4.0 with heavy grain.

These are two settings that should be tweaked according to the source material.

Adaptive Quantization​

--aq-mode 3 --aq-strength <variable>

Adaptive quantization, shortened to AQ, is a mechanism to redistribute bitrate within a frame to improve visual quality by reducing artifacts. x265 has several different AQ modes, and --aq-mode 3 is nearly always best, because this mode adds a bias favoring dark scenes, which greatly reduces the effects of banding and blocking. The strength of AQ can also be set with --aq-strength. The optimal setting for this may vary depending on the type of content you are encoding. For anime, --aq-strength 0.7 will typically produce good results. For live action, a slightly higher 0.8 may be a better default. Higher values, up to --aq-strength 1, can be helpful for sources with heavy grain, although this will also increase overall bitrate.

CU-Tree​

--no-cutree

CU-Tree is a mechanism very similar to MB-Tree in x264, which is intended to redistribute bitrate in a more optimal psychovisual manner. However, many people find CU-Tree to be harmful to quality, especially when attempting to encode videos with considerable amounts of grain, and therefore many people recommend disabling this with --no-cutree.