Stabilize Shaky Video with FFmpeg Vidstab on Linux

This guide provides a straightforward, step-by-step walkthrough for stabilizing shaky video footage on Linux using the powerful vidstab filter extension in FFmpeg. You will learn how to check for library support, generate stabilization vectors in a first pass, and apply those vectors to transform your shaky camera work into smooth, professional-looking video in a second pass.

Checking for Vidstab Support

Before diving into the stabilization process, you need to ensure your installation of FFmpeg was compiled with the vidstab libraries enabled. Open your Linux terminal and run the following command:

ffmpeg -filters | grep vidstab

If your installation supports it, you will see output listing vidstabdetect and vidstabtransform. If no results appear, you may need to install a version of FFmpeg that includes these libraries from your distribution’s repository or a trusted third-party package manager.

Step 1: The Analysis Pass (Two-Pass Stabilization)

High-quality video stabilization requires a two-pass process. In the first pass, the vidstabdetect filter analyzes the video frame by frame to identify camera shakiness and writes this tracking data to a temporary file (usually named transforms.trf).

Run the following command in your terminal:

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

Key Parameters Explained

Step 2: The Transformation Pass

Once the analysis file is generated, you apply the vidstabtransform filter to create the stabilized video file. This pass reads the transforms.trf file and physically shifts the video frames to counteract the detected shakiness.

Run the following command to generate your smooth video:

ffmpeg -i input.mp4 -vf vidstabtransform=smoothing=30:input=transforms.trf -c:a copy output_stabilized.mp4

Key Parameters Explained

Advanced Optimization: Zoom and Crop

Stabilizing a video inevitably shifts the edges of the frame inward, which can leave black borders around your video. By default, vidstabtransform subtly zooms in to crop out these artifacts. If you notice remaining black edges, you can force a cleaner crop and zoom by adding the optzoom parameter:

ffmpeg -i input.mp4 -vf vidstabtransform=smoothing=30:optzoom=1:input=transforms.trf -c:a copy output_stabilized.mp4

Setting optzoom=1 tells the filter to automatically calculate the optimal zoom factor required to completely hide any empty borders throughout the duration of the clip.