Transcode Video with FFmpeg libx265 Custom Tuning

Transcoding videos using the High Efficiency Video Coding (HEVC) standard with the libx265 encoder in FFmpeg allows for superior compression and quality. This article provides a straightforward guide on how to configure FFmpeg to transcode video files using libx265 while applying custom tuning options to optimize the output for specific content types, such as animation, film, or fast-paced action.

Basic FFmpeg Command with libx265

To transcode a video using the libx265 encoder, use the following basic command structure:

ffmpeg -i input.mp4 -c:v libx265 -crf 22 -preset medium output.mp4

Using Built-in libx265 Tuning Options

The libx265 encoder provides built-in tuning options (-tune) to optimize the encoder for specific types of source material. You can apply these by adding the -tune flag to your command:

ffmpeg -i input.mp4 -c:v libx265 -crf 20 -preset slow -tune grain output.mp4

Below are the most common built-in tuning options:

Custom Tuning with -x265-params

For precise control, you can bypass or supplement the built-in presets by passing custom parameters directly to the underlying libx265 library using the -x265-params flag. Multiple parameters are separated by colons (:).

For example, to prevent blockiness in dark scenes and disable Sample Adaptive Offset (SAO), which can sometimes cause blurriness, use the following command:

ffmpeg -i input.mp4 -c:v libx265 -crf 21 -preset slow -x265-params aq-mode=3:no-sao=1 output.mp4

Highly Effective Custom Parameters: