How to Set psy-rd Manually in FFmpeg
This guide explains how to manually configure the
-psy-rd (psychovisual rate-distortion optimization)
parameter in FFmpeg. You will learn the correct syntax for both the
libx264 and libx265 encoders, what the
individual values represent, and how to apply these settings to optimize
your video encoding quality.
Understanding psy-rd
Psychovisual rate-distortion optimization (psy-rd) is a
feature in x264 and x265 encoders that biases the encoder toward keeping
high-frequency details (like film grain and textures) rather than
discarding them to save bitrate.
The parameter consists of two parts, written as
strength:trellis (for x264) or configured as separate
variables (for x265).
- Strength (Psy-RD): Controls the overall strength of psychovisual optimization. Higher values keep more detail but can cause blockiness at lower bitrates.
- Trellis (Psy-Trellis / Psy-RDOQ): Controls psychovisual quantization. It helps preserve textures and reduces blurriness, particularly in dark or complex areas.
Setting psy-rd in libx264
In FFmpeg, you can configure psy-rd for the H.264
encoder in two different ways: using the direct -psy-rd
flag or using the -x264-params option.
Method 1: Using the Direct Flag
You can pass the values directly using the -psy-rd flag.
The format is -psy-rd strength:trellis.
ffmpeg -i input.mp4 -c:v libx264 -crf 20 -psy-rd 1.0:0.15 output.mp4Method 2: Using -x264-params (Recommended)
Using the -x264-params flag is often preferred because
it prevents conflicts with FFmpeg’s internal mapping.
ffmpeg -i input.mp4 -c:v libx264 -crf 20 -x264-params psy-rd=1.0:0.15 output.mp4Note: The default value for x264 is 1.0:0.0 (or
1.0:0.15 when Trellis is enabled).
Setting psy-rd in libx265
For HEVC (H.265) encoding via libx265, FFmpeg does not
support a direct -psy-rd flag. Instead, you must pass these
settings using the -x265-params argument.
In x265, the two components are defined as psy-rd and
psy-rdoq.
ffmpeg -i input.mp4 -c:v libx265 -crf 22 -x265-params psy-rd=2.0:psy-rdoq=1.0 output.mp4- psy-rd (default is
2.0): Adjusts the psychovisual rate-distortion. - psy-rdoq (default is
1.0): Adjusts psychovisual rate-distortion quantization (similar to x264’s trellis).
Recommended Values
If you are customizing these values to improve film grain retention or sharp details, use these starting baselines:
For H.264 (libx264)
- Animation / Clean Content:
-x264-params psy-rd=0.4:0.0(Lower values prevent ringing artifacts) - High-Detail / Film Grain:
-x264-params psy-rd=1.0:0.20(Higher values keep grain intact)
For H.265 (libx265)
- Animation / Clean Content:
-x265-params psy-rd=0.5:psy-rdoq=0.5 - High-Detail / Film Grain:
-x265-params psy-rd=2.0:psy-rdoq=1.5