Stabilize Shaky Video Using FFmpeg Deshake Filter

Shaky camera footage can ruin an otherwise great video, but you can easily fix this using FFmpeg’s built-in deshake filter. This guide provides a straightforward tutorial on how to use the single-pass deshake video filter to smooth out camera motion, explaining the essential command-line parameters and providing practical examples to get steady results quickly.

The Basic Deshake Command

The deshake filter works by analyzing the differences between consecutive frames to detect and compensate for horizontal and vertical camera motion.

To stabilize a video using the default settings, use the following basic command:

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

This default command works well for mild, low-frequency camera shakes. It automatically detects motion in the center of the frame and attempts to smooth out the transition between frames.

Customizing the Deshake Parameters

For more challenging footage, you can fine-tune the filter using specific parameters. The syntax for applying parameters is deshake=parameter1=value1:parameter2=value2.

Here are the most useful parameters for the single-pass deshake filter:

Advanced Example Command

If you have a video with significant camera shake, you can increase the search range and use mirroring to hide the edge artifacts:

ffmpeg -i input.mp4 -vf "deshake=rx=64:ry=64:edge=mirror" output.mp4

Tips for Best Results

ffmpeg -i input.mp4 -vf "deshake=rx=32:ry=32:edge=mirror, crop=in_w-64:in_h-64" output.mp4