Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active March 16, 2023 15:18
Show Gist options
  • Save max-mapper/43219d6dcb9006042849 to your computer and use it in GitHub Desktop.
Save max-mapper/43219d6dcb9006042849 to your computer and use it in GitHub Desktop.
Video stabilization using VidStab and FFMPEG (Mac OS X)

Video stabilization using VidStab and FFMPEG

Examples here use the default settings, see the VidStab readme on GitHub for more advanced instructions.

Here's an example video I made

Install ffmpeg with the vidstab plugin from homebrew

brew install ffmpeg --with-libvidstab

Analyze your video to create a .trf file

This won't modify your video or create a new video, but it should create a new file called transform.trf

ffmpeg -i clip.mov -vf vidstabdetect -f null -

Use the .trf file to create a stabilized video

ffmpeg -i clip.mov -vf vidstabtransform=smoothing=5:input="transforms.trf" clip-stabilized.mov

This should create a new stabilized video called clip-stabilized.mov

Bonus: create a side by side comparison video

Found on a forum here

ffmpeg -i Clip8.mov -i Clip8-vidstab.mov -filter_complex "[0:v:0]pad=iw*2:ih[bg]; [bg][1:v:0]overlay=w" merged.mov
@davidschlachter
Copy link

@ArneAnka Homebrew is removing options for installing customizing packages, including FFMPEG with libvidstab.

@ArneAnka
Copy link

@ArneAnka Homebrew is removing options for installing customizing packages, including FFMPEG with libvidstab.

That was a bummer...

@pnbv
Copy link

pnbv commented Feb 13, 2019

@ArneAnka Regarding current state of macOS homebrew installation (with options), feel free to use the following:

brew remove ffmpeg

brew tap pnbv/homebrew-ffmpegvidstab

brew install pnbv/homebrew-ffmpegvidstab/ffmpeg

Check brew tap docs and manage your own custom formula (for vid.stab only you can just duplicate mine, above)

@kpennell
Copy link

@pnbv Thanks for making this.

https://docs.brew.sh/Taps

@kibotu
Copy link

kibotu commented Aug 23, 2019

https://github.com/varenc/homebrew-ffmpeg#installation-and-usage

brew tap varenc/ffmpeg
brew install varenc/ffmpeg/ffmpeg --with-libvidstab

@mkormendy
Copy link

@kibotu what is the difference between varenc's version over pnbv's?

@kibotu
Copy link

kibotu commented Oct 8, 2019

well not quite sure exactly, but that one worked for me and the other didn't :/ just wanted to drop this info in case someone else couldn't get the main example to work :3

@yefim
Copy link

yefim commented Dec 10, 2019

Looks like varenc/ffmpeg/ffmpeg has been superseded by homebrew-ffmpeg/ffmpeg according to https://github.com/varenc/homebrew-ffmpeg.

@silasfc
Copy link

silasfc commented Dec 10, 2020

What is -f null - do?

This (-f null -) occurs because when performing step 1 (vidstabdetect) we do not (yet) need the final video file, but only "transforms.trf", necessary for step 2 (vidstabtransform).

By the way: "-f" specifies the output format (null in this case) for ffmpeg.

@gth001
Copy link

gth001 commented Oct 31, 2021

Edits from 2021. There's some errors/inefficiencies above due to changes since it was written (in Dec 2015).

With ffmpeg -i clip.mkv -vf vidstabdetect -f null -I just get the error
No such filter: 'vidstabdetect'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment