How to Stabilize Video with FFmpeg Deshake

Shaky video footage can be easily corrected using FFmpeg’s built-in deshake filter. This guide provides a straightforward, single-pass approach to stabilizing your videos directly from the command line, explaining the essential parameters and providing ready-to-use commands to improve your playback quality without the need for complex, multi-pass workflows.

The Basic Deshake Command

The deshake filter works by analyzing motion between frames and applying a counter-shift to minimize camera shake. For a quick, automatic stabilization using default settings, use the following basic command:

ffmpeg -i input.mp4 -vf deshake output.mp4

This command takes your shaky input file, applies the default single-pass stabilization, and exports the corrected video.

Fine-Tuning Deshake Parameters

While the default settings work well for mild camera shake, you can customize the filter parameters to achieve better results for highly unstable footage. The syntax for adding parameters is:

-vf "deshake=parameter1=value1:parameter2=value2"

Here are the most useful parameters you can adjust:

Advanced Single-Pass Example

If you are dealing with a handheld video with moderate shake and want to ensure the edges are cleanly mirrored while widening the motion search area, use this optimized command:

ffmpeg -i input.mp4 -vf "deshake=rx=24:ry=24:edge=mirror:blocksize=16" -c:a copy output.mp4

In this command: * rx=24:ry=24 increases the search window to catch larger shakes. * edge=mirror seamlessly blends the shifting edges. * blocksize=16 balances processing speed and motion tracking accuracy. * -c:a copy copies the audio stream without re-encoding to save processing time and preserve original audio quality.