Configure libx264 Tune Parameter in FFmpeg

This article provides a straightforward guide on how to configure the -tune parameter in FFmpeg when using the libx264 video encoder. You will learn what the tune parameter is, explore the available tuning options for different video types, and see practical command-line examples to optimize your video encoding workflow.

Understanding the Tune Parameter

The -tune parameter in FFmpeg allows you to optimize the libx264 encoder settings based on the specific type of video content you are compressing or the specific requirements of your playback environment. While the -preset parameter controls encoding speed versus compression ratio, the -tune parameter adjusts internal encoder settings (like deblocking filters and psychovisual optimizations) to maximize visual quality for specific content types.

Available Tune Options for libx264

You can apply the tune parameter by adding -tune <option> to your FFmpeg command. Below are the most common tuning options and when to use them:

FFmpeg Command Examples

To use these options, insert the -tune flag alongside the libx264 encoder in your command.

Example 1: Encoding an Animation Video

This command optimizes the encode for an animated video using the slow preset for better compression:

ffmpeg -i input.mp4 -c:v libx264 -preset slow -tune animation -c:a copy output.mp4

Example 2: Low-Latency Live Streaming

This command optimizes the encode for live streaming by minimizing delay:

ffmpeg -i input.mp4 -c:v libx264 -preset fast -tune zerolatency -f flv rtmp://live.server.com/app/stream

Example 3: Preserving Film Grain

This command is best for older movies or cinematic content where you want to keep the original film grain intact:

ffmpeg -i input.mp4 -c:v libx264 -crf 18 -preset medium -tune grain output.mp4