How to Adjust FFmpeg Deshake Search Range
This article explains how to adjust the motion detection search range
in the FFmpeg deshake video stabilization filter. You will
learn which parameters control the search radius and search methodology,
along with practical command-line examples to optimize your video
stabilization process.
The FFmpeg deshake filter works by comparing blocks of
pixels between frames to estimate camera motion. To adjust how far the
filter looks to detect this shaking, you need to configure the search
range parameters: rx and ry.
Key Parameters for Search Range
rx: Sets the maximum horizontal search range in pixels. The value can range from0to64, with a default of16.ry: Sets the maximum vertical search range in pixels. The value can range from0to64, with a default of16.search: Determines the search strategy. Setting this to0enables an exhaustive search (highly accurate but slower), while setting it to1uses a less exhaustive, faster search algorithm (large diamond search).
Practical Command Examples
To adjust these settings, pass the parameters directly to the
deshake filter in your FFmpeg command.
1. Increasing the Search Range for Heavy Shaking
If your video has significant, wide-angle camera shakes, you should increase the search range to the maximum value of 64 pixels:
ffmpeg -i input.mp4 -vf "deshake=rx=64:ry=64" output.mp42. Decreasing the Search Range for Micro-vibrations
For high-frequency, small-amplitude vibrations (like drone footage or tripod vibrations), decrease the search range to save processing power and prevent false motion detection:
ffmpeg -i input.mp4 -vf "deshake=rx=8:ry=8" output.mp43. Optimizing for Accuracy with Exhaustive Search
To combine a larger search range with the most accurate detection
method, set the search parameter to 0
(exhaustive search):
ffmpeg -i input.mp4 -vf "deshake=rx=32:ry=32:search=0" output.mp4Tips for Best Results
- Keep aspect ratio in mind: If your video has mostly
horizontal shake (panning), you can set a higher
rxand a lowerryto optimize processing speed. - Performance trade-off: Higher values for
rxandryrequire more CPU processing power. If processing time is an issue, keep the values as close to the default of16as your footage allows.