# Video Stabilization with \`ffmpeg\` and \`VidStab\`

DevFeed: [Video Stabilization with \`ffmpeg\` and \`VidStab\`](<https://devfeed.tech/articles/video-stabilization-with-ffmpeg-and-vidstab-21682.md>)

Original publisher: [Read original article](<https://paulirish.com/2021/video-stabilization-with-ffmpeg-and-vidstab/>)

Author: Paul Irish

Published: 2021-04-30T18:33:00Z

Content type: tutorial

Language: en

Sources: [Paul Irish](<https://devfeed.tech/sources/paul-irish.md>)

Topics: [FFmpeg (Fast Forward Moving Picture Experts Group)](<https://devfeed.tech/topics/ffmpeg.md>), [Homebrew](<https://devfeed.tech/topics/homebrew.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [make](<https://devfeed.tech/topics/make.md>)

Tags: [commands](<https://devfeed.tech/tags/commands.md>), [comparison](<https://devfeed.tech/tags/comparison.md>), [diy](<https://devfeed.tech/tags/diy.md>), [ffmpeg](<https://devfeed.tech/tags/ffmpeg.md>), [guide](<https://devfeed.tech/tags/guide.md>), [install](<https://devfeed.tech/tags/install.md>), [installation](<https://devfeed.tech/tags/installation.md>), [linux](<https://devfeed.tech/tags/linux.md>), [mac](<https://devfeed.tech/tags/mac.md>), [mac-os](<https://devfeed.tech/tags/mac-os.md>), [make](<https://devfeed.tech/tags/make.md>), [video](<https://devfeed.tech/tags/video.md>)

## AI overview

A practical guide to stabilizing video with FFmpeg and VidStab. It covers installation on Mac OS and Linux, the two-pass detection and transformation workflow, and commands for creating vertically stacked or side-by-side comparison videos.

## Source excerpt

Way back in Dec 2015, @maxogden wrote a nice guide on stabilizing your own video with ffmpeg. I return to it on occasion and have updated my gist comment to offer some updated commands. Since enough has changed regarding installation and use, I figure a new, spiffy, and working guide deserves a non-gist home. Presenting the 2021-era guide to pretty easy DIY video stabilization! On Mac OS, install ffmpeg and vidstab from homebrew: 1 2 brew install ffmpeg brew install libvidstab On linux, you can sudo make install. Run stabilization in two passes There are plenty of options for libvidstab, like shakiness, accuracy, smoothing. The defaults are good, but you may want to experiment. There's even a visual diagnostic mode. Assuming the source video is named clip.mkv... 1 2 3 4 5 6 # The first pass ('detect') generates stabilization data and saves to `transforms.trf` # The `-f null -` tells ffmpeg there's no output video file ffmpeg -i clip.mkv -vf vidstabdetect -f null - # The second pass ('transform') uses the .trf and creates the new stabilized video. ffmpeg -i clip.mkv -vf vidstabtransform clip-stabilized.mkv You now have a clip-stabilized.mkv! Bonus: create a comparison video Use the vstack or hstack filter, depending on if you want them stacked vertically or side-by-side: 1 2 3 4 5 # vertically stacked ffmpeg -i clip.mkv -i clip-stabilized.mkv -filter_complex vstack clips-stacked.mkv # side-by-side ffmpeg -i clip.mkv -i clip-stabilized.mkv -filter_complex hstack clips-sxs.mkv Double bonus: A two-liner that does everything (because repeating these filenames gets annoying) 1 2 export vid="sourcevid.mkv" ffmpeg -i "$vid" -vf vidstabdetect -f null -; ffmpeg -i "$vid" -vf vidstabtransform "$vid.stab.mkv"; ffmpeg -i "$vid" -i "$vid.stab.mkv" -filter_complex vstack "$vid.stacked.mkv"