Making movies from individual frames
To produce movies of Paterson’s Worms, I needed to concatenate a couple thousand images into an animation. You would think that Windows XP, with its “advanced digital media features”, would have everything you would need. But no. First, Windows Movie Maker refuses to contemplate displaying any bit of media for less than an eighth of a second, so you can’t make a movie that plays at more than 8 fps. Second, it can’t handle more than about 200 images without running out of memory – it must decompress them all in memory before running them through the codec. So you have to create lots of little movies first, and then paste those together in a second pass. Besides being a huge pain, that causes visible skips in the quality between those segments. Kudos to the Microsoft Monkeys.
So, with a sigh, it’s off to Google. Slide Show Movie Maker and VirtualDub appear to be good free media editing packages, but I chose VideoMach for its ability to read PNG files, which give the best lossless compression of the individual frames – using lossy compression on each frame and then again during the movie encoding will give worse results than if the movie codec uses the exact original data. It also has a nice interface, and can handle any number of frames.
The next question was which codec to use. But before you can do that, you have to be able to compare the results. Once again, the Windows media tools fall down: only once instance of Windows Media Player can be alive at a time, which means you can’t look at two movies side by side. Hyplay is a free AVI player which, despite its rather strange UI, solved that problem for me.
After a lot of experimentation, I settled on the Xvid codec, which won the Doom9 codec comparison. Xvid.org distributes only source code, but binaries are available in several places; here are compiled versions for Windows (click “Xvid binaries” on the right) and Linux. For the same file size, it produced noticeably better results than Microsoft MPEG4, DivX, 3ivx, and several others that I tried. A few requirements for using VideoMach and Xvid:
- Make sure the width and height of your frames are both even numbers. Xvid appears not to work otherwise.
- The input must be 24-bit color. If it’s not, you can force it in the VideoMach video settings dialog. Otherwise Xvid will not show up as an available codec.
- The last two frames seem to get lost – at least when you move the position slider all the way to the right, you see the third-to-last frame. I don’t know if this is a problem with the players or the encoding, but both Windows Media Player and Hyplay behaved the same way. In my case I was pretty interested in the last frame, since it has the completed image and step count, so I worked around it by adding two extra copies of the last frame at the end of the sequence.
After trying just about every combination of Xvid settings, I ended up with these changes from the defaults:
- Quantization type MPEG (smaller files at same quality level than H.263)
- Motion search precision: 6 (Ultra high)
- VHQ mode: 4 (Wide search)
Of course these were best only for my rather unusual input set. I used only single-pass encoding because I couldn’t see a difference with two-pass. The movies on the worms page were made with a target bitrate of 250kbps.
I was pretty pleased with the final result of the space/quality tradeoff. The movies are linked off my page on Paterson’s Worms.
You can find me at chaffin@gmail.com