Stabilize Shaky Video with FFmpeg Vidstab

This guide explains how to use the FFmpeg vidstabdetect and vidstabtransform filters to stabilize shaky video footage. You will learn how to run a two-pass stabilization process and configure virtual camera panning to create smooth, professional-looking video transitions.

To stabilize a video using FFmpeg’s vid.stab library, you must perform a two-pass process. The first pass analyzes the video’s motion, and the second pass applies the stabilization using virtual camera panning to smooth out the shakes.

Step 1: Analyze the Video (First Pass)

The first step uses the vidstabdetect filter to analyze the video frames and generate a file containing motion data (usually named transforms.trf).

Run the following command:

ffmpeg -i input.mp4 -vf vidstabdetect=shakiness=10:accuracy=15:result=transforms.trf -f null -

Step 2: Apply Stabilization and Virtual Panning (Second Pass)

Once the transforms.trf file is generated, you use the vidstabtransform filter to read this data and render the stabilized video. This is where you configure virtual camera panning to smooth out transitions.

Run the following command:

ffmpeg -i input.mp4 -vf vidstabtransform=input=transforms.trf:smoothing=30:maxshift=100:maxangle=-1:crop=black:zoom=5 output.mp4