Configure FFmpeg Deshake Block Size and Threshold

This article explains how to configure the blocksize and contrast (threshold) parameters for FFmpeg’s deshake filter to improve video stabilization. You will learn the exact syntax for these parameters, how they influence motion detection, and how to choose the best values for your specific footage.

The Deshake Filter Syntax

The deshake filter in FFmpeg uses block matching to detect camera motion between frames and apply corrective shifts. The basic command structure for applying the filter with custom parameters is:

ffmpeg -i input.mp4 -vf "deshake=blocksize=VAL:contrast=VAL" output.mp4

Configuring the Block Size (blocksize)

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

How to Choose the Right Block Size

Example Command (16x16 block size):

ffmpeg -i input.mp4 -vf "deshake=blocksize=16" output.mp4

Configuring the Contrast Threshold (contrast)

The contrast parameter acts as a threshold to determine which blocks are stable enough to be used for motion estimation. FFmpeg ignores blocks with a contrast level below this threshold to prevent flat areas (like a clear sky, solid walls, or shadows) from generating false motion vectors.

How to Choose the Right Contrast Threshold

Example Command (Lower threshold for low-contrast scenes):

ffmpeg -i input.mp4 -vf "deshake=contrast=80" output.mp4

Combining Parameters for Optimal Stabilization

For the best results, you should tune both parameters together based on your footage type.

For high-resolution, detailed, and shaky handheld video, use larger blocks with a standard threshold:

ffmpeg -i input.mp4 -vf "deshake=blocksize=32:contrast=125" output.mp4

For dark, low-contrast footage where tracking is difficult, lower both the block size and the contrast threshold to capture enough tracking points:

ffmpeg -i input.mp4 -vf "deshake=blocksize=8:contrast=50" output.mp4