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).


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.mp4

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.mp4

Note: 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

If you are customizing these values to improve film grain retention or sharp details, use these starting baselines:

For H.264 (libx264)

For H.265 (libx265)