Camera Stabilisation with FFmpeg

Now before you shout me down with your “Blender can do that!” patriotism, let me first explain how you would do it in Blender:

  • Open Blender, Import the footage into the Movie Clip Editor
  • Track a few markers (which might be tricky, since your footage is so shaky)
  • Enable 2D stabilization and assign those markers
  • Enable Display Stabilization and be shocked at how cropped your video is now
  • Spend the next half hour tweaking settings until you’ve got an acceptable video
  • And finally render it out (without forgetting the audio!) to a format (you hope) your TV or YouTube will understand using a limited number of encoding controls.

So that works, sure, but if you’re looking for something really quick and easy that gives you a huge amount of optional control over the output file, give our friend FFmpeg a try!

Just like ImageMagick, FFmpeg is an extremely useful command-line program. It has no interface, you simply type commands into a console. This might sound intimidating if you’ve never done it before, but it really is this easy:

ffmpeg -i -vf deshake

ffmpeg is the command that does all sorts of things to videos.
-i tells ffmpeg which video to convert.
-vf deshake is the stabilisation filter is of course the output file, keeping the original video unchanged.

While I’m sure it’s not at powerful as Blender, it is really quick. There are some options detailed in the ffmpeg documentation such as the maximum extent of movement and contrast threshold, but for my purposes the defaults are fine.

Like I mentioned above, Blender has a (relatively) limited number of encoding controls, whereas FFmpeg has as many as you could possibly imagine, and probably a few more. You just need to google something like “ffmpeg h264 encoding options” and you’ll quickly find several articles that detail things such as CRF factors, lossless compression and presets.

Although Blender uses FFmpeg internally, you will need to install FFmpeg yourself and add it to the system path, which I’ve detailed in a separate post here: Installing FFmpeg for Dummies.

I really, really recommend you explore the possibilities of this great tool, it’s useful for many more things, like converting an image sequence into a video, a video into an image sequence, rotate and scale videos, discover information about a video, stabilize that shaky video you took at you Great Aunt’s 4th wedding, stream the webcam you planted in your girlfriend’s ex-boyfriend’s bedroom, or convert your 250 frame cube render to a super-crispy lossless h264 of unparalleled awesomeness.

If you’re interested in more possible uses of FFmpeg, take a look at the Use It section of my installation tutorial.

  • Samuel Nicholas

    Even so video stabilisation software sucks compared to what it could be.

    You want to use the vidstabdetect and vidstabtransform filters from ffmpeg

    It’s far superior to the deshake filter

    What i would like to see is a de_barrel->motion_detect->de_shake->horizon_correct->re-barrel toolchain.. sigh, perhaps when i get close to the end of my uni course..

    the de-barrel is to avoid the warping you will get at the corners

    • Samuel Nicholas

      it would be nice to have a compositor node to do this stuff, not sure how it would work..

    • John

      There is a problem with vidstabdetect and vidstabtransform filter – if the video happens to zoom in – the image stabilization cause worse image stabilization.

      as in wildly shaking left and right

  • John

    Any support for opencl to do some of the computation? throwing a 4K video really slow it down (about 0.07fps)