June 10, 2017

FFMPEG vs My 'Go Low' Action Cam

I got myself a really cheap action cam. Think “China copy” and “Go Pro” and you know what I bought. However, for its 35 EUR price tag that thing is pretty cool.

One problem with that cam is that it comes without any software. So you need to dig around a bit if you want to get creative with recorded movies and pictures. So far, I tried two things: time lapse videos from a sequence of photos and stabilized videos.

It is not really surprising that you can do both things with ffmpeg – if you know how. On a Mac you can install ffmpeg with Homebrew: brew install ffmpeg --with-libvidstab very easily.

Time Laps Video

Another problem with my “Go Low” is the rather stupid naming scheme of the photo sequence. It creates files named IMG-1.JPG, …, IMG-9.JPG, IMG-10.JPG, IMG-11.JPG, … ffmpeg cannot deal with this kind of numbering and expects something like IMG-00001.JPG, IMG-00002.JPG, IMG-00003.JPG, … So let us rename the files using a small bash script:

    #!/bin/bash
    n=0
    for file in $(ls -T *.JPG)
    do
        mv $file $(printf "IMG_%05d.jpg" "$n")
        let n=n+1
    done

Now we can fire up ffmpeg:

    ffmpeg -framerate 25 -i IMG_%05d.jpg -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4

As mostly everything you do with ffmpeg, this process is highly demanding on the CPU and takes some time.

Stabilized Video

Especially when you mount the camera to something like a bike, you end up with highly shaky videos.

You can compensate parts of the movement types using ffmpeg, vidstab and transform. However, especially vibrations caused by rough surfaces creates effects you cannot compensate. So do not expect wonders.

Stabilization works as follows: 1) you let vidstab compute a transformations file that describes the detected movement:

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

Then you compensate the movement using transform:

ffmpeg -i shaky.mov -vf "vidstabtransform=input="transforms.trf",pp=al" default.mov

The result looks really better:

vidstab and transform have various parameters, see above links. Finding the right configuration is close to black magic. I played with the parameters and turned up many settings to the max.

ffmpeg -i shaky.mov -vf vidstabdetect=stepsize=10:shakiness=10:accuracy=10 -f null -
ffmpeg -i shaky.mov -vf "vidstabtransform=input="transforms.trf":smoothing=10:zoom=5,pp=al" max.mov

I honestly can't tell if there is a much difference between the results created by the first and second set of commands.

So I put shaky.mov, default.mov (created by default settings), and max.mov (created by the turned up settings) next to each other, again using ffmpeg. In case you wonder how, this was the command:

ffmpeg -i shaky.mov -i default.mov -i max.mov -filter_complex \
"
  nullsrc=size=1926x1080 [bg];
  [0:v]     crop=1/3*in_w:1*in_h:0:0 [l];
  [1:v]     crop=1/3*in_w:1*in_h:1/3*in_w:0 [m];
  [2:v]     crop=1/3*in_w:1*in_h:2/3*in_w:0 [r];
  [bg] [l]  overlay=shortest=1  [bgl];
  [bgl] [m]  overlay=shortest=1:x=643  [bglm];
  [bglm][r]  overlay=shortest=1:x=1286
" \
out.mov;

© holger 2015 - 2020 |