Fanning Software Consulting

Setting the MPEG Frame Rate

QUESTION: I have 40 frames in my MPEG file and I would like to play these at one frame per second. How can I do this?

ANSWER: The short answer is: "You can't". The longer answer -- provided by our MPEG Guru, Rick Towler -- is still "You can't", but he gives you a bit more information. Here is his October 1, 2002 post on the IDL newsgroup.

You can't. Since MPEG was designed for video the frame rate is tied to industry standards (PAL/NTSC). While some MPEG codecs [coder/decoder, ala modem = modulate/demodulate] may allow you encode at non-standard rates, the resulting file will probably only be decoded by the same codec. You lose your portability.

QUESTION: At the moment I have set the FRAME_RATE keyword to 2, which is apparently 24 frames per second. And then I used a loop to replicate each frame 24 times, but the MPEG file is HUGE! Is there a better way to do this?

Don't use MPEG. Or I should say, don't use MPEG-1 or MPEG-2.

While it is probably the most portable video file format (MPEG-1 that is), it just can't compete with newer codecs. Plus, MPEG wasn't designed with scientific animations in mind and it produces terrible results unless the quality settings are very high. Yes, probably *no* codec programmers were thinking of the scientists but there are codecs that do scientific animations better.

To choose a codec, think of your audience. You will end up trading file size and quality for codec availability. The best decoders are freely available for PC and Mac. There are a few better one's available for Xanim.

In my experience, the best codecs for sci anim ("best" being based on file size and quality) are:

Sorenson video 3 (PC & Mac - codec ships with quicktime)
Ligos Indeo Video 5 (PC, Mac, UNIX Xanim -
DivX (MPEG-4) (PC, Mac & Linux - free codec

If you have access to a PC, I highly recommend Ronn Kling's AVI2IDL windows only .dlm based on Oleg Kornilov's code which provides an interface to the Win32 AVIFile interface. This is by far the easiest way to create high quality animations using IDL. If not, you'll want to write the individual frames to disk and find a program that can stitch them together. I'm sure there are many for the Mac, but it might be more difficult to find good ones that run on Linux or other UNIX systems (mainly because the codecs aren't available, at least for free).

Web Coyote's Guide to IDL Programming