Configure libx265 Psy-Visual Quantization in FFmpeg

This article explains how to configure and fine-tune the psycho-visual quantization settings in the FFmpeg libx265 encoder. You will learn the specific command-line parameters used to adjust psycho-visual rate-distortion (psy-RD) and psycho-visual rate-distortion optimization quantization (psy-RDOQ) to optimize the perceived visual quality of your HEVC/H.265 video encodes.

Understanding Psycho-Visual Quantization in x265

Psycho-visual quantization adjustments prevent the encoder from discarding fine details, textures, and film grain in favor of flat, blurry surfaces. In libx265, this behavior is primarily controlled by two parameters:

  • psy-rd (Psycho-visual Rate Distortion): Compares the source pixels to the encoded pixels using a metric that favors human visual perception over purely mathematical similarity. It helps preserve original textures and sharpness.
  • psy-rdoq (Psycho-visual Rate Distortion Optimization Quantization): Specifically guides the quantization process to retain high-frequency details (like grain or complex textures) that standard quantization matrices usually discard.

Configuring the Parameters in FFmpeg

Because these options are specific to the libx265 library, they must be passed to FFmpeg using the -x265-params argument, separated by colons.

The syntax for configuring both settings is as follows:

ffmpeg -i input.mp4 -c:v libx265 -crf 22 -x265-params psy-rd=1.5:psy-rdoq=1.0 output.mp4

Adjusting these values depends on the type of content you are encoding:

  • psy-rd (Default: 2.0):
    • Range: 0.0 to 5.0
    • For high-quality film/grain preservation: Increase to 2.0 or 2.5.
    • For clean animation/clean sources: Lower to 0.5 or 1.0 to avoid introducing unwanted ringing artifacts.
  • psy-rdoq (Default: 1.0):
    • Range: 0.0 to 50.0
    • For high-quality film/grain preservation: Set between 1.0 and 2.0. Higher values prevent flat areas from becoming blocky but require more bitrate.
    • For animation: Set between 0.0 and 0.5.

Example: Encoding Film with Grain Preservation

To preserve film grain and high-frequency textures in a high-definition movie, you can use higher psycho-visual settings:

ffmpeg -i input.mkv -c:v libx265 -crf 18 -preset slow -x265-params psy-rd=2.0:psy-rdoq=1.5 output.mkv

Example: Encoding Clean Animation

For flat, clean animated content, lower psycho-visual settings prevent the encoder from wasting bitrate on artificial noise:

ffmpeg -i animation.mkv -c:v libx265 -crf 20 -preset slow -x265-params psy-rd=0.5:psy-rdoq=0.2 output.mkv