Documenting opengl

I have been thinking about and looking for ways to document the output of my opengl programs for some time now. Most of my opengl software is very dependent upon sets of libraries and a specific environment, which mean that it is difficult to keep them all running over a period of time. Also as a peice of software is developed earlier (and often quite interesting) formative stages are lost.

The solution I’ve chosen is to add functionality into the software to output frames as images, this causes some complications to the usual opengl event/timing loop, as timing has to be absolute. A “recording” generates thousands of image files which can take up many gigabytes. Ironic since the software itself to generate them is only a few hundred KBytes.

Initially I tried using quicktime pro to open the image sequence and then save as a streaming h264 mpeg4. But with 50,000 images, file shared from my atholon 64 (on which I write the software) to my macintosh, quicktime just wouldn’t do it. Once the image file was open it then took a long time to encode (many hours), all in all a very manual process.

For a while I used Cinerella a linux open source video editing package, but this was also cumbersome, and when I switched from Fedora Core 4 linux to Ubuntu Breezy, buiiding the software looked painful (It seems impossible to find a linux distribution where everything is good). I spent some time looking for simple ways to write quicktime lossless files, and gave up in the end. Eventually I found that mencoder and ffmpeg looked like they had the ability to do what I wanted. I wanted to use the h264 and mpeg4 because they are standards based, smaller than divx and should work for some time. There is a new addittion to the ffmpeg project for h264, but of course it wasn’t fully supported in the ubuntu software builds I had access too. Mencoder looked easier to use, but would have involved getting caught up in software building hell, so I settled on using ffmpeg which was easier to update (get the debian sources, and rebuild the package with —enable-h264). Using ffmpeg I can generate a h264 data stream in a mpeg4 container with:

ffmpeg -b 400 -r 25 -an -i ./output/rib%5d.png -vcodec h264 -f mp4 -s 768x576 story.mp4

Ffmpeg is pretty fussy about the ordering of options, the -s switch for image size needs to be after the -i flag to to work, also the image sequence needs to be numered consecutively from 0, e.g. 00001,00002,00003 etc for %5d otherwise it throws a not very helpful error.

Then using another opensource tool mp4creator from the mpeg4ip project its quite easy to create a streaming hint track with

mp4creator -O -hint=1 story.mp4

which is then ready to archive or go up onto the web. With very little intervention and close to realtime processing, as opposed to many hours and quite a lot of fiddling with quicktime.