FLV metadata performance

One of worst-kept secrets of “Wii Transfer”:http://www.riverfold.com/software/wiitransfer/ is that the movie playback is not as good as what you might see on an Apple TV, Xbox 360, or PS3. I do my best to improve the quality with every release, but let’s face it: while the Wii is perfectly capable of playing fullscreen video, it stumbles when put to that task inside the Opera web browser through Flash.

In the upcoming version 2.6, I’ve added the ability to skip directly to any part of a playing movie by clicking on the timeline with the Wii remote. It was frustrating not to be able to do that in previous versions and made it difficult to watch or fast-forward through long movies.

The way many Flash movie players handle skipping is by inserting metadata into the FLV file that contains a map between seconds in the timeline and file positions for the keyframes, and that’s the way Wii Transfer works as well. Unfortunately this requires rewriting the entire FLV file when post-processing movies. (“Ian Baird”:http://blog.skorpiostech.com/ suggested a future optimization would be to store the metadata separately and redo the player to send seconds instead of file offsets to the server.) I was initially using the open source flvtool2.rb to achieve this, but it was extremely slow, so I rewrote it in Objective-C. (Not a port. The Objective-C version was written from scratch and is significantly shorter than the Ruby version in terms of lines of code. It does a little bit less, but it’s optimized for exactly what Wii Transfer needs.)

This chart shows the performance improvements when processing a couple large movie files. Measured in seconds, so shorter bars are better.

FLV chart

The other good thing that came out of all this work is that I can now look at a FLV file in a hex editor and not be totally confused. “Hex Fiend”:http://ridiculousfish.com/hexfiend/ was one of the best ways to debug what my code was doing when it failed.