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.mp4Choosing the Right CU Size
ctu=64(Default): Best for 4K and 1080p videos. It provides the highest compression efficiency and best visual quality, especially in flat or low-detail areas of the frame, but requires the most CPU resources and memory.ctu=32: Recommended for 720p or standard-definition (SD) resolutions. It offers a balanced compromise between encoding speed and compression efficiency.ctu=16: Best for very low-resolution videos or real-time encoding pipelines where speed and low memory utilization are prioritized over compression efficiency.
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.