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:
- Simpler: just use a static build https://www.johnvansickle.com/ffmpeg/
- More work: install the
vid.stab
from github (https://github.com/georgmartius/vid.stab read the compile instructions, very simple), and then compileffmpeg
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...
I guess many people (me included) found this question, trying just to use ffmpeg with the filter.
Those answers about compiling are great, but it's time-consuming and may be difficult for some people.
Nowadays there is a simple option to use Docker image that is already built with many filters, codecs and more.
Personally, I used this image https://github.com/jrottenberg/ffmpeg
Sample usage is very simple for deshake filter:
docker run -v $PWD:/temp/ \
jrottenberg/ffmpeg \
-i /temp/input.MTS \
-vf deshake \
/temp/out.avi
As well for vidstab filter:
# create vectors from input file
docker run -v $PWD:/temp/ jrottenberg/ffmpeg \
-i /temp/input.MTS \
-vf vidstabdetect=stepsize=6:shakiness=8:accuracy=9:result=/temp/transform_vectors.trf -f null -
# process file using vectors from step 1
docker run -v $PWD:/temp/ jrottenberg/ffmpeg \
-i /temp/input.MTS \
-vf vidstabtransform=input=/temp/transform_vectors.trf:zoom=1:smoothing=30,unsharp=5:5:0.8:3:3:0.4 \
/temp/out.avi
Just mind that created file "out.avi" will have root
owner and that should be changed.