Deshaking videos using script

Currently, ffmpeg from the repository only supports the simpler deshake filter, but does not support the better vidstab filters.

You have a few options to get vidstab support: compile or use a PPA.


Compiling

This is the best option if you also want to customize your ffmpeg or use the latest version.

First you will have to compile libvidstab or use the libvidstab-dev package. Currently only 19.04 Disco Dingo and newer provides this package. Alternatively, 16.04 Xenial Xerus users can use the libvidstab-dev package from the mc3man PPA).

To compile libvidstab:

$ sudo apt-get install build-essential cmake
$ mkdir ~/ffmpeg_sources ~/ffmpeg_build
$ cd ~/ffmpeg_sources
$ wget -O https://github.com/georgmartius/vid.stab/archive/master.zip
$ unzip master.zip
$ cd vid.stab-master
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=~/ffmpeg_build .
$ make
$ make install

Now follow How to Compile FFmpeg on Ubuntu. When you get to the step where ffmpeg is configured then add --enable-libvidstab to the list of configure options.


mc3man PPA

FFmpeg current release plus git PPA for 16.04 Xenial Xerus:

sudo add-apt-repository ppa:mc3man/ffmpeg-test
sudo apt-get update
sudo apt-get install ffmpeg-static

Now run ffmpeg2 (note the "2").


Usage

See the vid.stab usage instructions.


Also see

  • deshake, vidstabdetect, and vidstabtransform FFmpeg filter documentation.

As others mention above that Doug's PPA doesn't support Zesty (17.04) - as of 08/19/2017. As 17.10 will come out in October 16.04 solutions will be more and more obsolete. Two possible solutions for Zesty users:

  1. Simpler: just use a static build https://www.johnvansickle.com/ffmpeg/
  2. More work: install the vid.stab from github (https://github.com/georgmartius/vid.stab read the compile instructions, very simple), and then compile ffmpeg https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

Since I don't have too much time, I like the first solution, worked flawlessly.

The vidstab first pass works on 1 core only, but since my GoPro footage is in many chunks, I could process 4 video simultaneously if I'd want 100% system load. The second pass utilizes all 4 cores.

My laptop i7-6820HK but both passes only progress with about 0.12x speed. So it's pretty slow, but I won't care if the result will be nice.


Update: my helmet mount footage seems to be so shaky that shakiness 10 is not enough. I don't know what to do, that's the max...