11

How can I deshake my video?

I try to use transcode:

transcode  -J stabilize --mplayer_probe -i "input.MTS"

But it causes a segfault.

Trying to use ffmpeg filters:

ffmpeg -i "input.MTS" -vf vidstabdetect=shakiness=5:show=1 out.avi
ffmpeg -i "input.MTS" -vf deshake out.avi

But always have an error "No such filter".

I want to create a simple nautilus script for this.

19

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

|improve this answer|||||
  • config step of building ffmpeg fails for me with ERROR: vidstab not found using pkg-config. What am I missing ? – expert Dec 11 '15 at 8:41
  • Also Doug's PPA doesn't have libvidstab-dev – expert Dec 11 '15 at 8:45
  • 1
    @guettli It shouldn't. That was a typo. Thanks for pointing it out. I edited the answer. – llogan Mar 1 '17 at 18:40
  • For all (like me), who read too fast: you need to use ffmpeg2 – guettli Mar 1 '17 at 18:43
  • doesn't seem to work with ubuntu 17.04 – wotanii Jul 17 '17 at 8:44
3

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...

|improve this answer|||||
  • 1
    I tried the deshake for my helmet mounted GoPro bicycle footages but it looked like almost didn't do anything. Deshake is part of the official Ubuntu version of ffmpeg, maybe there's some parameter combination it'd work better, but reading on the net sounds like vid.stab will be better. – Csaba Toth Aug 19 '17 at 19:39
  • Yes, vidstab is better, but more complicated. – llogan Aug 22 '17 at 5:35
1

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.