How to Use rect Option in FFmpeg libx265

This article explains how to configure the rect option in the FFmpeg libx265 encoder to optimize HEVC video compression. You will learn what the rect parameter does, how it impacts your encoding speed and quality, and the exact FFmpeg command-line syntax required to apply this setting to your video files.

What is the rect Option?

The rect option in the libx265 encoder stands for “rectangular motion partitions.” When encoding video using the High Efficiency Video Coding (HEVC/H.265) standard, the encoder divides frames into blocks for motion analysis. By default, HEVC uses square prediction blocks (such as 64x64, 32x32, etc.).

Enabling the rect option allows the encoder to also use rectangular partition shapes (such as 32x16, 16x32, 16x8, or 8x16).

How to Configure rect in FFmpeg

In FFmpeg, parameters specific to the H.265 encoder are passed using the -x265-params flag. The syntax for the option is rect=1 to enable it, or rect=0 to disable it.

Enabling the rect Option

To enable rectangular motion partitions for better compression quality, use the following command:

ffmpeg -i input.mp4 -c:v libx265 -x265-params rect=1 output.mp4

Disabling the rect Option

To disable rectangular motion partitions and speed up your encoding time, use this command:

ffmpeg -i input.mp4 -c:v libx265 -x265-params rect=0 output.mp4

Combining rect with Other Parameters

If you are configuring multiple libx265 parameters, separate them with a colon (:) within the -x265-params argument. For example, to disable both rect and amp (Asymmetric Motion Partitions) for maximum encoding speed, use:

ffmpeg -i input.mp4 -c:v libx265 -x265-params rect=0:amp=0 output.mp4

Preset Defaults

The rect option is enabled by default in most libx265 presets. If you use presets like medium, slow, or veryslow, rect is automatically set to 1. If you use fast presets like ultrafast, superfast, or veryfast, the encoder disables rect automatically to prioritize encoding speed. Manually setting -x265-params rect=1 or rect=0 allows you to override these preset defaults.