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.
- Syntax:
blocksize=<value> - Allowed Values: Must be a power of two between 4
and 128 (e.g., 4, 8, 16, 32, 64, 128). The default value is
8. - Impact on Video:
- Smaller block sizes (e.g., 4 or 8): Offer high-precision tracking for fine, complex movements. However, they are highly sensitive to video noise and require more processing power.
- Larger block sizes (e.g., 16 or 32): Ignore small details and noise, focusing instead on larger, consistent structures. They process much faster but may miss subtle, fast vibrations.
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.
- Syntax:
rx=<value>:ry=<value> - Allowed Values: Integers from 0 to 64. The default
value for both is
16. - Impact on Video:
- Larger search range (e.g., 32 to 64): Necessary for highly unstable footage with large, sudden camera movements. Setting these values high drastically increases rendering times.
- Smaller search range (e.g., 8 to 12): Ideal for minor, high-frequency jitters (such as handheld camera vibrations). This reduces processing time significantly.
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.mp4Example 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.mp4Example 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