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 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
- 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).
- Run VirtualDub.exe with Deshaker plugin installed in VirtualDub’s “plugins” folder
- Enable Deshaker with Video > Filters > Add > Deshaker
- Set or note location for log file, click OK – OK
- Open Blender video made in step 1
- I like to right-click and reduce input (left) video window to 25% at this point
- Make sure Video > Full Processing Mode is set
- Run analysis by invoking File > Save as AVI and setting some dummy file name. This file is discardable.
- Use Deshaker.log file for next step:
Using Deshaker Log in Blender
- 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).
- Import the plugin into Blender: File > User Preferences > Add-ons > Install from File
- Right-click the video (movie) track to stabilize. (It might make sense to make a metastrip out of the composition first.)
- IMPORTANT: make sure to use the same render resolution % used to render file for Deshaker analysis, as the log numbers are divided by that %!
- Import Deshaker log: File > Import > Import Deshaker log
- To speed things up a little, in Graph Editor, set interpolation type: Key > Interpolation Type > Linear
- Now you can scrub through video and see the Deshaker tracking data applied
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:
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:
Running VirtualDub on Linux
It works very nice:
- Install Wine Windows Emulator
- Install MP4 Windows codec https://sourceforge.net/projects/x264vfw/files/latest/download
- Enable vcrun2005 in winetricks (Wine utility)
- Download and unpack VirtualDub
- Download Deshaker and put Deshaker.vdf into virtualdub’s plugin folder
- Run virtualdub.exe
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).