Configure vidstabtransform Zoom and Interpolation in FFmpeg

This article explains how to configure the zoom and interpolation settings of the vidstabtransform filter in FFmpeg to stabilize shaky video footage. You will learn how to control how much the video zooms in to hide moving borders and how to select the best pixel interpolation method to maintain visual quality.

Stabilizing a video with FFmpeg is a two-step process. First, the vidstabdetect filter analyzes the motion and generates a transform file (usually named transforms.trf). Second, the vidstabtransform filter uses this file to apply stabilization. Zooming and interpolation are configured during this second step.

Here is a standard command template using both configuration options:

ffmpeg -i input.mp4 -vf vidstabtransform=input=transforms.trf:zoom=5:optzoom=1:interpol=bicubic output.mp4

Configuring Zoom Options

When a video is stabilized, the frame shifts to counteract the camera shake, which can reveal empty black borders. To hide these borders, you must configure the zoom parameters.

  • zoom: This parameter defines an additional manual zoom percentage.
    • A value of 0 means no extra manual zoom.
    • A positive value (e.g., zoom=5 for 5% zoom) scales the video up, cropping the edges to ensure no black borders are visible.
  • optzoom: This enables optimal zoom calculation, which automatically calculates the minimum zoom required to hide the borders.
    • optzoom=0: Disabled. Use manual zoom values only.
    • optzoom=1: Optimal static zoom. The filter calculates a single, fixed zoom level for the entire video. This is the recommended setting for most videos.
    • optzoom=2: Optimal dynamic zoom. The zoom level changes dynamically throughout the video depending on how shaky individual scenes are. This maximizes resolution but can cause visible zooming artifacts.

Example with optimal static zoom:

ffmpeg -i input.mp4 -vf vidstabtransform=zoom=0:optzoom=1 output.mp4

Configuring Interpolation Options

Interpolation determines how FFmpeg reconstructs and renders pixels when the video frame is rotated, shifted, or zoomed. Choosing the right interpolation method directly affects the sharpness and rendering speed of the output.

You can set the interpol parameter to one of the following values:

  • no (or 0): No interpolation (nearest-neighbor). This is the fastest method but produces jagged edges and poor visual quality.
  • linear (or 1): Linear interpolation. Fast, but can result in slightly blurry images.
  • bilinear (or 2): Bilinear interpolation. Offers a good balance between processing speed and image clarity.
  • bicubic (or 3): Bicubic interpolation. This is the default and recommended option. It requires the most processing power but produces the sharpest, highest-quality output.

Example using high-quality bicubic interpolation:

ffmpeg -i input.mp4 -vf vidstabtransform=interpol=bicubic output.mp4