Video Stabilization with Deshaker in Blender

Action video is often lacking clear persistent references to stabilize video with – they either are not present in the frame for very long, or often compressed out of frame as the codec is trying to spend most of its bandwidth on moving objects in the shot.

Deshaker, a plugin for Windows program VirtualDub, with its capability to find and track multiple visual references (literally hundreds of them) automatically from frame to frame is the king of action video stabilization. (It works on Linux, too, see below).

Deshaker scanning a file

Deshaker works in 2 passes – analysis and stabilization. During pass 1, a log file is created that contains correction numbers necessary for each frame.

This file could be used in Blender as a source for transform track. Here is how:

Creating Deshaker Log

  1. Export video from Blender, audio is not necessary. It’s OK to use 50% render resolution (IMPORTANT: make sure to use the same resolution during Deshaker log import).
  2. Run VirtualDub.exe with Deshaker plugin installed in VirtualDub’s “plugins” folder
  3. Enable Deshaker with Video > Filters > Add > Deshaker
  4. Set or note location for log file, click OK – OK
  5. Open Blender video made in step 1
  6. I like to right-click and reduce input (left) video window to 25% at this point
  7. Make sure Video > Full Processing Mode is set
  8. Run analysis by invoking File > Save as AVI and setting some dummy file name. This file is discardable.
  9. Use Deshaker.log file for next step:

Using Deshaker Log in Blender

  1. Install one of 2 plugins from https://github.com/sergem155/blender-deshaker-log-import . There are 2 versions, using different stabilization algorithms (more below, but “damper” version is working well, “sinc” version is experimental).
  2. Import the plugin into Blender: File > User Preferences > Add-ons > Install from File
  3. Right-click the video (movie) track to stabilize. (It might make sense to make a metastrip out of the composition first.)
  4. IMPORTANT: make sure to use the same render resolution % used to render file for Deshaker analysis, as the log numbers are divided by that %!
  5. Import Deshaker log: File > Import > Import Deshaker log
  6. To speed things up a little, in Graph Editor, set interpolation type: Key > Interpolation Type > Linear
  7. Now you can scrub through video and see the Deshaker tracking data applied

Example output

Simple damper algorithm – the distance from center is reduced by 10% in each frame:

 

Music is Skeewiff – Blue Crystal (feat Rayna)

The black bars are kind of large, I’ve done a couple of attempts to reduce them, using a digital filter to remove low frequency motion from stabilization movement and remove “DC bias” building up. I still like simple damper better, but maybe I wasn’t playing with settings long enough, or windowed sinc’s ripples were acting up, and another algo would have been better.

Windowed sinc filter (17 points) – remove all motion < 1Hz, but with less steep roll-off:

 

Raw video without stabilization, for comparison:

Other Cool Features of Deshaker

I implemented just motion. Deshaker can also do adaptive zoom, rolling shutter rubber panning effect correction and can paint black bars with contents of previous frames, to name a few. If you’d like to code that, be my guest, the code is open.

What About Manual Correction?

It would have been awesome to put a second transform track and correct the movement a bit, but sadly, Blender’s transforms are fully applied and cropped between strips, so you get a crop upon crop:

second-transform-strip-cropping

I also tried to put the sequence as a source strip in another scene’s sequence, with a smaller viewport. While this is possible, the strip is scaled to the second composition’s size, even with image offset option turned on, so it is, unfortunately, useless too:

another-scene-scaling

Running VirtualDub on Linux

It works very nice:

  1. Install Wine Windows Emulator
  2. Install MP4 Windows codec https://sourceforge.net/projects/x264vfw/files/latest/download
  3. Enable vcrun2005 in winetricks (Wine utility)
  4. Download and unpack VirtualDub
  5. Download Deshaker and put Deshaker.vdf into virtualdub’s plugin folder
  6. Run virtualdub.exe

Update

There was a bug (sorry) in the code that was shifting all transforms 2 frames back, that is now fixed in github. (And once again, make sure to import the log with the same render resolution % you used to export it).

Leave a Reply

Your email address will not be published.