Configure libx265 Tune in FFmpeg

This article explains how to configure the tune parameter in FFmpeg when encoding video with the libx265 (HEVC) encoder. You will learn the correct command-line syntax, the available tuning options—such as grain, animation, and zero-latency—and how to apply these settings to optimize your video output based on the specific type of source content you are compressing.

Understanding the Tune Parameter

The -tune parameter in libx265 optimizes the encoder’s settings for specific types of video content or use cases. By adjusting internal settings like deblocking filters, psychovisual rates, and QP offsets, tuning ensures the highest possible visual quality or performance for your specific media.

There are two primary ways to specify the tune parameter in FFmpeg:

  1. Using the direct -tune flag:

    ffmpeg -i input.mp4 -c:v libx265 -crf 22 -tune grain output.mp4
  2. Using the -x265-params flag:

    ffmpeg -i input.mp4 -c:v libx265 -crf 22 -x265-params tune=grain output.mp4

Available Tune Options for libx265

The libx265 encoder supports several tuning options. Each option is tailored for a specific scenario:

Practical Examples

Encoding Film with Preserved Grain

To compress a movie while keeping the original cinematic film grain intact:

ffmpeg -i movie.mkv -c:v libx265 -crf 20 -tune grain output.mkv

Encoding Animated Content

To encode cartoons or anime to keep edges sharp and colors clean:

ffmpeg -i anime.mp4 -c:v libx265 -crf 18 -tune animation output.mp4

Low-Latency Live Streaming

To configure a stream with the lowest possible delay:

ffmpeg -i input.mp4 -c:v libx265 -tune zero-latency -f mpegts udp://127.0.0.1:1234