Configure Psycho-Visual Quantization in FFmpeg libx264

This article explains how to configure and fine-tune psycho-visual quantization strength in the libx264 encoder using FFmpeg. You will learn the specific command-line parameters to adjust these settings, understand how the underlying psycho-visual rate-distortion (psy-RD) and psycho-visual Trellis (psy-trellis) systems work, and find recommended configurations for different types of video content.

Understanding Psycho-Visual Options in libx264

Psycho-visual optimization biases the encoder toward visual quality rather than strict mathematical metrics like PSNR (Peak Signal-to-Noise Ratio). It helps retain fine details, film grain, and textures that human eyes notice, preventing the encoder from smoothing them out to save bitrate.

In libx264, this is controlled via two parameters passed as a pair: 1. Psy-RD (Psycho-visual Rate-Distortion): Controls the strength of detail preservation. 2. Psy-Trellis (Psycho-visual Trellis): Controls the strength of detail preservation during the final quantization steps.

The ffmpeg Command Syntax

To configure these strengths, you must pass the psy-rd parameter using the -x264-params or -x264opts flag. The format is psy-rd=psy-rd_strength:psy-trellis_strength.

Here is a standard FFmpeg command template:

ffmpeg -i input.mp4 -c:v libx264 -crf 20 -x264-params psy-rd=1.0:0.15 output.mp4

In this command, 1.0 is the strength of the Psy-RD, and 0.15 is the strength of the Psy-Trellis.

Parameter Breakdown

You do not always need to manually set these values; the -tune flags in libx264 configure them automatically. However, manual tweaking is beneficial for custom encodes: