Sunday, 11 April 2010

Defishing Video 2

This is a follow-up to a couple of earlier posts. In the first, Machines Worked by Fire, I used the power of software to stretch out and "defish" images shot with a fisheye lens, and in the second, which does not have a name but I will call him Klarc Kumquat, I applied the same magic to video. This was a laborious process that involved transforming the video into a series of still frames, applying software correction to each frame, and then assembling the frames into a video again. It took an age, but the end result was an extremely wide field of view, impossible to achieve otherwise.

I've since found a better way to do things. Have a look at this:

It's part of my daily bicycle commute, shot with a Canon 5D MkII and a Zenitar 16mm fisheye lens, mounted on the handlebars of my bike with a Gorillapod, although it's not much use without the ball head). The camera wobbled up and down a lot, although this is much less apparent when the video is run at ten times normal speed. I suspect something like a Panasonic GH1 or a Canon 550D would be more practical for bike-mounted filming - or for that matter a motorbike! The music is by myself.

Previously I worked on individual frames, because I wasn't aware of a VirtualDub plugin or standalone piece of software that could stretch out video. Defishing fisheye images is a computationally intensive task, and the technique is very esoteric. Fortunately at least one other person in the world has had the same idea, and a handy chap called David Horman has written a bang-up-to-the-minute plugin for AVISynth that will defish images (I found it in this forum thread at Doom9, which is full of people who are experts on ripping, fiddling with, and then reconstituting digital video into new forms). It appears to date from February 2010 and is available here.

The tricky thing is that it only works with AVISynth, a free, command-line video editor which can be run independently, or invoked as part of VirtualDubMod, an older version of VirtualDub with some novel features. Being a command-line editor, there isn't a graphical user interface. None of that girly point-and-click with the mouse nonsense. In order to defish the bike ride above I had to type:

defish(fov=140, scaling="fitx")

The "fov" parameter stretches out the video, and the "scaling" parameter scales it so that the edges aren't cropped off. The end result looked like this:

And so I cropped off the top and bottom, and added a border so that the image was an even number of pixels. Several video compressors require the pixel dimensions to be a multiple of a whole number, and I chose 800x400 because they are good whole numbers, and I like the colours. Eight is yellow and four is blue and zero is water. 800x400 looks like a field of sunflowers underneath a bright blue sky, turned on its side, with water.

You'll notice that it's blurry around the edges - this is a consequence of the defishing process, but in the context of a fast-moving point-of-view shot it just looks like motion blur, as in the famous "trench run" sequence from the first Star Wars film. In fact it adds to the effect.

Of course on the day that I write this post it is overcast again. England continually fails me. I dream of a land where there is sunshine.