Configure Minimum CU Size in FFmpeg libx265
To configure the minimum Coding Unit (CU) size in the
libx265 encoder using FFmpeg, you must pass the
min-cu-size parameter through the -x265-params
flag. This article explains how to set this parameter, the available
options, and how altering the minimum CU size affects your video
encoding speed and quality.
In the HEVC (H.265) video compression standard, frames are
partitioned into Coding Tree Units (CTUs), which are recursively split
into smaller square Coding Units (CUs). By default, libx265
uses a maximum CU size of 64x64 and allows the encoder to split these
blocks down to a minimum size of 8x8 to capture fine details.
The min-cu-size
Parameter
You can restrict the encoder from splitting block sizes down to the
smallest default size by using the min-cu-size option. The
valid values for this parameter are:
8(Default: Allows block sizes down to 8x8 for maximum detail retention)16(Limits the smallest block size to 16x16)32(Limits the smallest block size to 32x32)
FFmpeg Command Syntax
To apply this configuration in FFmpeg, pass the parameter inside the
-x265-params argument.
Here is an example command that sets the minimum CU size to 16:
ffmpeg -i input.mp4 -c:v libx265 -x265-params min-cu-size=16 -c:a copy output.mp4If you are passing multiple parameters to libx265,
separate each key-value pair with a colon (:):
ffmpeg -i input.mp4 -c:v libx265 -x265-params crf=23:preset=medium:min-cu-size=16 -c:a copy output.mp4Performance and Quality Impact
Adjusting the minimum CU size creates a direct trade-off between encoding speed and compression efficiency:
- Larger Minimum CU (16 or 32): Increasing the minimum CU size speeds up the encoding process because the encoder performs fewer recursive partition decisions. However, this can cause a loss of fine detail and introduce blockiness in complex or highly textured scenes.
- Smaller Minimum CU (8): Keeping the default value of 8 ensures the highest visual quality and best compression efficiency, but it requires significantly more CPU processing power and time.