Deshaking videos using script

20,314

Solution 1

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

Solution 2

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

Solution 3

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.

Share:
20,314

Related videos on Youtube

Crantisz
Author by

Crantisz

Updated on September 18, 2022

Comments

  • Crantisz
    Crantisz over 1 year

    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.

  • expert
    expert over 8 years
    config step of building ffmpeg fails for me with ERROR: vidstab not found using pkg-config. What am I missing ?
  • expert
    expert over 8 years
    Also Doug's PPA doesn't have libvidstab-dev
  • llogan
    llogan about 7 years
    @guettli It shouldn't. That was a typo. Thanks for pointing it out. I edited the answer.
  • guettli
    guettli about 7 years
    For all (like me), who read too fast: you need to use ffmpeg2
  • wotanii
    wotanii almost 7 years
    doesn't seem to work with ubuntu 17.04
  • llogan
    llogan almost 7 years
    @wotanii More detailed information is required to be able to determine the actual issue.
  • wotanii
    wotanii almost 7 years
    @LordNeckbeard Because I was missing 'export LD_LIBRARY_PATH=path/to/install_dir/lib:$LD_LIBRARY_PATH' ffmpeg couldn't find libvidstab. I added it and now it works.
  • Andreas Mueller
    Andreas Mueller almost 7 years
    There's no ppa for 17.04 :-/
  • Csaba Toth
    Csaba Toth over 6 years
    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.
  • llogan
    llogan over 6 years
    Yes, vidstab is better, but more complicated.