Configure libx265 Max CU Size in FFmpeg

This article explains how to configure the maximum Coding Unit (CU) size when using the libx265 encoder in FFmpeg. By adjusting this parameter, you can optimize the HEVC (H.265) encoding process for either higher compression efficiency or faster processing speeds based on your target video resolution.

In HEVC encoding, the Coding Tree Unit (CTU) acts as the basic processing block, and its size determines the maximum Coding Unit (CU) size. By default, libx265 uses a maximum CU size of 64x64, which is highly efficient for high-resolution content like 4K. However, for lower resolutions like 1080p or 720p, reducing this size can improve encoding speed and lower memory usage.

To configure the maximum CU size in FFmpeg, you must pass the ctu option inside the -x265-params flag. The valid values for ctu are 16, 32, or 64.

FFmpeg Command Example

Use the following syntax to set the maximum CU (CTU) size to 32:

ffmpeg -i input.mp4 -c:v libx265 -x265-params ctu=32 output.mp4

Choosing the Right CU Size

By utilizing the -x265-params ctu=<size> option, you can precisely tailor your FFmpeg encoding pipeline to fit your hardware capabilities and target video specifications.