How to Adjust Deshake Search Range and Block Size in FFmpeg

This article provides a practical guide on how to configure the search range and block size parameters within the FFmpeg deshake filter. By adjusting these specific settings, you can fine-tune the video stabilization process to match the severity of your camera shake, balancing stabilization quality against processing speed.

Understanding the Deshake Filter Parameters

The deshake filter stabilizes shaky footage by dividing video frames into a grid of blocks, tracking the motion of those blocks across frames, and applying corrective transformations. Two critical settings dictate how this motion is detected: Block Size and Search Range.

1. Adjusting Block Size (blocksize)

The blocksize parameter defines the size of the squares (in pixels) used for motion estimation.

2. Adjusting Search Range (rx and ry)

The search range parameters determine how far (in pixels) the filter looks in the horizontal (rx) and vertical (ry) directions to find matching blocks from the previous frame.

Practical FFmpeg Command Examples

To apply these settings, pass them as key-value pairs separated by colons inside the -vf deshake filter argument.

Example 1: Stabilization for Large, Slow Shakes

If your camera experienced large, jarring movements, increase both the block size and the search range to capture the wide displacement:

ffmpeg -i input.mp4 -vf "deshake=rx=32:ry=32:blocksize=16" output.mp4

Example 2: Stabilization for Fast, Micro-Jitters

If you have high-frequency vibration (like a drone or a camera mounted on a moving vehicle) and want fast processing, use a smaller search range:

ffmpeg -i input.mp4 -vf "deshake=rx=8:ry=8:blocksize=8" output.mp4

Example 3: Maximum Stabilization (High CPU Usage)

For extreme stabilization on highly distorted footage where processing time is not a concern, maximize the search range:

ffmpeg -i input.mp4 -vf "deshake=rx=64:ry=64:blocksize=16" output.mp4