vidstabdetect measures the shake and vidstabtransform removes it: a 26 px average jump between frames drops to under 2 px. ReelSDK runs both passes for under three quarters of a cent at $0.02 per compute minute; one-pass deshake leaves about 11 px.

Stabilize a shaky video with ffmpeg

Two passes beat one by a wide margin. On ReelSDK they run as 2 jobs that finish in under 20 seconds together, since its ffmpeg has libvidstab and returns the motion file like any other output.

GuidesUpdated

pass 1
ffmpeg -i shaky.mp4 -vf vidstabdetect=shakiness=8:accuracy=15:result=transforms.trf -f null -

vidstabdetect tracks how each frame moved and writes it to transforms.trf. Nothing is encoded, so the output is -f null -. Raise shakiness for rough footage; accuracy is already at its top of 15 by default.

Variations

The other commands you will need

  1. Pass 2: smooth the path and sharpen

    vidstabtransform reads the file, smooths the camera path over smoothing frames each side and moves every frame onto it. unsharp restores the detail lost to the moves. This is the slow pass, over four times as long as pass 1.

    pass 2
    ffmpeg -i shaky.mp4 -vf vidstabtransform=input=transforms.trf:smoothing=30,unsharp=5:5:0.8:3:3:0.4 \
      -c:v libx264 -crf 20 -preset veryfast -c:a copy -movflags +faststart stable.mp4
  2. One pass with deshake

    If your ffmpeg says No such filter: 'vidstabdetect', it was built without libvidstab. deshake is built in and needs no file, but it searched only 64 px each way and lost track at times: it left about 11 px of shake on average, and one jump of over 100 px.

    deshake
    ffmpeg -i shaky.mp4 -vf deshake=rx=64:ry=64 \
      -c:v libx264 -crf 20 -preset veryfast -c:a copy -movflags +faststart deshaked.mp4

The flags

The options that matter

The options that matter
FlagWhat it doesUsed here
shakiness=8How shaky and quick the camera is, 1 to 10; the default is 5Pass 1
accuracy=15Detection accuracy, 1 to 15; the default is already 15Pass 1
resultWhere pass 1 writes the motion dataPass 1
inputThe motion file pass 2 readsPass 2
smoothing=30Frames each side used to smooth the path, here 61 in allPass 2
optzoomZooms in to hide the moving borders; on by default with 1Pass 2
unsharpSharpens after the moves, as the manual recommendsPass 2
rx=64:ry=64deshake's search range in pixels, 0 to 64; the default is 16Deshake

Sources: ffmpeg filters: vidstabdetect, vidstabtransform, ffmpeg filters: deshake, checked November 2026.

How we measured it

We made the shaky clip ourselves with one API job: a smaller crop window moved by sine waves over a steady 1080p video. That way we know what steady looks like. The unshaken source moves about 1 px between frames on average, from its own slow pans.

We measured the shift between every pair of frames with OpenCV's phase correlation. The shaky clip averaged 26 px. vidstab brought that under 2 px, close to the source, both locally and on the API; deshake cut it by just over half.

Picking the settings

smoothing=30 averages the camera path over 61 frames, about 2 s at 30 fps. Higher values hold the frame stiller but fight real pans. The manual gives the default as 10; ffmpeg 8.1 reports 15, so set it yourself. Keep optzoom on unless black borders are fine.

The manual adds: "Note the use of the unsharp filter which is always recommended." Every move resamples the picture, and a light unsharp brings the edges back.

Both passes on the API

We checked first: the API's ffmpeg 8.1 has libvidstab, and the pass 1 job returned transforms.trf as a file like any other output. One job runs one ffmpeg command, so the passes are 2 jobs. Here is pass 1; pass 2 is the call in the next block, with that file's URL in inputs.

Two jobs at $0.02 per compute minute cost under three quarters of a cent for this clip; see pricing.

terminalTry it
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
  -H "Authorization: Bearer $REELSDK_KEY" \
  --json '{
    "inputs": {
      "shaky.mp4": "https://api.reelsdk.com/f/out/job_pz9juy0eeq5ok0r5m0xp/shaky.mp4"
    },
    "args": [
      "-i", "shaky.mp4", "-vf",
      "vidstabdetect=shakiness=8:accuracy=15:result=transforms.trf", "-f",
      "null", "-"
    ],
    "outputs": ["transforms.trf"]
  }'

Without installing ffmpeg

The same command as one API call

This is pass 2: transforms.trf from the pass 1 job comes in as an input, and the graph writes the stable clip plus a side-by-side check. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; both passes together took under 20 seconds and cost under three quarters of a cent.

terminalTry it
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
  -H "Authorization: Bearer $REELSDK_KEY" \
  --json '{
    "inputs": {
      "shaky.mp4": "https://api.reelsdk.com/f/out/job_pz9juy0eeq5ok0r5m0xp/shaky.mp4",
      "transforms.trf": "https://api.reelsdk.com/f/out/job_kkslh4ui1p1izxs925t1/transforms.trf"
    },
    "args": [
      "-i", "shaky.mp4", "-filter_complex",
      "[0:v]split=2[raw][src];[src]vidstabtransform=input=transforms.trf:smoothing=30,unsharp=5:5:0.8:3:3:0.4,split=2[stable][fixed];[raw]scale=640:360[left];[fixed]scale=640:360[right];[left][right]hstack=2[compare]",
      "-map", "[stable]", "-map", "0:a", "-c:v", "libx264", "-crf", "20",
      "-preset", "veryfast", "-c:a", "copy", "-movflags", "+faststart",
      "stable.mp4", "-map", "[compare]", "-c:v", "libx264", "-crf", "23",
      "-preset", "veryfast", "-an", "-movflags", "+faststart", "compare.mp4"
    ],
    "outputs": ["stable.mp4", "compare.mp4"]
  }'
compare.mp4 from the API: shaky on the left, stabilized on the right.Input: shaky.mp4stable.mp4transforms.trf

FAQ

Questions, answered

How do I stabilize a video with ffmpeg?

Run two passes: vidstabdetect writes transforms.trf, then vidstabtransform=input=transforms.trf:smoothing=30 with unsharp encodes the stable video. On our test clip the shift between frames fell from 26 px to under 2 px.

Why does ffmpeg say No such filter: 'vidstabdetect'?

Your build lacks libvidstab, which needs --enable-libvidstab. Use a build that has it, or deshake, which is built in but did far worse on our clip.

Is deshake good enough?

For small shakes, sometimes. On our clip it left a mean shift of about 11 px against under 2 px for vidstab, and it took longer than both vidstab passes together.

Can I run vidstab through an API?

Yes, as 2 jobs. The first writes transforms.trf as an output; the second takes that file's URL as an input and writes the stable video.

Ready to build?

Ship video from your app today

Your first $0.50 is free, and one key covers every endpoint.

Moonlit lake with a lit cabin under the mountains