Stabilizing 360 Video with Hugin

Although there are plenty of tools that work well for stabilizing regular video, there aren’t any good ones for stabilizing 360 degree video. As I was unable to find any freely available software that worked, I used various command line tools from Hugin and FFmpeg. Although this worked, it was extremely slow and had some issues with the horizon drifting.1 I can’t really recommend the approach, but I figured I’d post the technique in case anyone finds it to be useful. Hopefully Facebook with open source their 360 video stabilization, since it seems much better.

# Extract frames from original video
ffmpeg -i video.webm frame%03d.png

# Create Hugin project with frames
pto_gen -o project.pto -p 4 -f 360 frame*.png

# Find control points between adjacent frames
cpfind --linearmatch -o ctrlpoints.pto project.pto

# Remove bad control points (optional)
cpclean -p -o clean.pto ctrlpoints.pto

# Optimize fit
autooptimiser -p -o optimized.pto clean.pto

# Change output size to match input and change output mode to only remap images
pano_modify --canvas=AUTO --output-type=REMAPORIG -o output.pto optimized.pto

# Stitch output
nona -o output output.pto

# Convert remapped frames back into video
ffmpeg -framerate 30 -i output%04d.tif -c:v libvpx -b:v 10M output-no-audio.webm

# Copy audio
ffmpeg -i output-no-audio.webm -i video.webm -map 0:v -map 1:a -c:v copy -c:a libvorbis output.webm


  1. Manually adding some horizontal line control points in Hugin helped in this regard. 

This entry was posted in and tagged , , , , . Bookmark the permalink.

2 Responses to Stabilizing 360 Video with Hugin

  1. Road Pirate Films says:

    where is the technique?

    • Matthew Petroff says:

      It seems that when I ran a distro upgrade on the server hosting this blog earlier this year, I broke all the code snippets and didn’t notice. I just fixed the issue, so the code snippet in this post is back. Sorry about that.

Leave a Reply

Your email address will not be published. Required fields are marked *