April 20, 2005 The writeup here is getting outdated. MPlayer is now up to version 1.0pre7, and I believe there may have been significant changes to mjpegtools and libquicktime. But as far as I know, the basic commands for making movies using e.g. mencoder still work. When I get some spare time, I'll try and get this document up to date. George May 10, 2004 (revised June 27 2004) MAKING USEFUL SCIENTIFIC MOVIES USING FREE OR OPEN-SOURCE SOFTWARE (Notes from George H. Fisher) 0. INTRODUCTION Making scientific video clips or movies has proven to be one of the most complex, fragmented, and frustrating technical subjects I've ever dealt with, especially if one is interested in using only open-source or freely available software. The difficulty seems to be the huge number of different proprietary movie formats, the large number of different encoding/decoding algorithms available, most of which are mutually incompatible, and the labyrinth of legal and copyright issues associated with audio and video media in general. This is a summary of the notes I've made on how to make scientific movie clips that can be displayed at meetings on computer projectors or on the web. The objective is to make movies that can be viewed by as wide a cross-section of commonly used media players as possible, such as windows media player, realplayer, quicktime, and linux players such as xanim, mplayer, and xine. It is especially important that the files be playable in powerpoint presentations, which at most meetings will mean that the underlying movie player is windows media player on some kind of microsoft windows machine. Most of the software described here will generate either AVI (.avi) or MPEG1 (.mpg) files. AVI stands for "audio-video-interleaved" and was originally introduced by Microsoft, but has since been abandoned by them in favor of windows media format files, though microsoft media players still play .avi files. The .avi file structure has now become widely used in the open source community. The structure of .avi files is such that the coding/decoding algorithm (known as a 'codec') for both audio and video is not specified by the file format itself, but rather is specified within each file. Thus, while .avi videos have a common file structure, they are extremely diverse because of the hundreds of different audio and video codecs that are commonly used. To make things especially confusing, many .avi files to be discussed here encode video with versions of the mpeg family of codecs (especially mpeg4 recently). When creating scientific .avi files for wide distribution, it is important to encode the movies with codecs that are widely available, if you want your movies to be playable by a broad audience. In contrast to the chaotic situation with .avi files, .mpg files are tightly defined, and have only one specified video codec (MPEG1) and one audio codec (mp2) in the file definition. While the MPEG1 encoding algorithm is not particularly efficient, the standardized nature of the file structure means that a properly formatted .mpg file should play in most video players. Unlike the interleaved structure of audio and video in .avi files, the standard structure of .mpg files is that the audio and video parts are stored in different parts of the file. The 3rd common movie file type is the quicktime movie .mov or .qt file. Thus far, I know of only two free or open-source software paths to create widely playable quicktime movies, neither of them perfect, but that could well be just ignorance on my part. The claim is that mencoder (see section 4) can create .avi movies with quicktime codecs, but I haven't been able to do so successfully thus far. One method of creating quicktime video clips is through the use of the 'libquicktime' package for linux. This is a set of low-level and not terribly well documented utilities rather than a complete movie encoding package, but the 'qtrechunk' utility from libquicktime will allow you to create a quicktime video clip from a sequence of .jpg images, although little or no compression is done so the resulting movie clips can be large. The use of qtrechunk is described in section 6. This utility will allow you set an arbitrary frame rate. The other way I've discovered to create a widely playable quicktime movie is to first encode an .avi movie with the mjpeg codec using mencoder (see section 4c) and then use the lavtrans tool in mjpegtools (see section 5) to translate that movie to quicktime format. This results in a high-quality quicktime clip which is playable by the standard apple quicktime movie player. Here, the frame rate will be 25fps. The remainder of this document is organized as follows: Section 1 is devoted to describing a simple IDL tool for generating sequences of .jpg files suitable for movie generation. A descripion of 2 easy-to-use tools for generating .avi and .mpg movies respectively, namely JPGVideo and ImageMagick is given in sections 2 and 3, and then a long discussion of encoding video and audio in .avi movies with mplayer/mencoder is given in section 4. We then discuss the use of mjpegtools to generate .mpg movies with video and audio, and to translate .avi movies into quicktime in section 5. In section 6, the libquicktime package is briefly described, along with the use of the qtrechunk utility to encode quicktime video clips. JPGVideo runs only in Windows, ImageMagick runs in Both Windows and Linux, Mplayer/Mencoder runs in Linux (but there is an experimental version for Windows), Mjpegtools runs only in Linux, and libquicktime is a linux package. 1. GENERATING MOVIE COMPATIBLE JPEG IMAGES IN IDL The first step in making scientific movies is to create a series of images which can then be encoded into one of the common movie formats. For simplicity, I'll only discuss .jpg images. I begin by describing a way to generate sequences of .jpg images in IDL that is pretty straightforward. There are lots of other ways to do this, but since IDL is extremely common in Solar Physics, it's a good place to start. Note also that IDL is neither open source nor free, but since it is widely used in the Solar community, we'll make an exception and assume you have access to IDL and are familiar with it. The first thing to note is that the sequence of .jpg files *must* be created using 24-bit color. If you generate your .jpg files in IDL using write_jpeg with the default (8 bit color) settings, these files WILL NOT WORK. The following IDL procedure, 'write_jpeg24', called in a loop, will generate an ordered series of acceptable 24 bit color .jpg files: ;----------------------------------------------------------- pro write_jpeg24,namebase,icount ; ; - - Reads image and color table from the default device, and ; - - creates a 24bit color .jpg file of the image, with a file name ; - - of namebase (a string array), to which a 0-filled integer ; - - encoded as an ascii string will be appended. This is intended ; - - for a series of images that will be turned into a movie. ; nparms=N_params() if (nparms ne 2) then begin Message, 'Usage: write_jpeg24,namebase,icount', /info Message, 'Purpose: Create a high quality 24-bit color .jpg file of ', /info Message, ' image on the screen, using the loaded colormap', /info Message, ' (to be called in a loop with index icount to', /info Message, ' create a series of images to be used in a movie).', /info Message, 'Input: namebase (string) - root name of file', /info Message, 'Input: icount (integer) - last bit of file name (0 fill)', /info Message, 'Written: George H. Fisher UCB/SSL 05/31/2004 (version 0.0)', /info return endif i=long(icount) image=tvrd() tvlct,r,g,b,/get imsize=size(image) nix=imsize(1) & niy=imsize(2) ; image3d=bytarr(3,nix,niy) image3d(0,*,*)=r(image) image3d(1,*,*)=g(image) image3d(2,*,*)=b(image) ; ind=string(i+100000,format='(i6)') ind2=strmid(ind,1) namef=strcompress(namebase+ind2+'.jpg',/remove_all) write_jpeg,namef,image3d,true=1,quality=100 ; return end ;-------------------------------------------------------------- Here is an example of such a loop creating images: filebase='test' for i=0,nt-1 do begin write_jpeg24,filebase,i endfor 2. USING JPGVIDEO TO CREATE .AVI MOVIES JPGVideo is a freeware (but not open source!) software package available from http://www.ndrw.co.uk that runs in MS Windows. No linux or mac versions are available as far as I can tell. JPGVideo is a simple, easy to use package that will convert a directory full of .jpg images into a file called JPGVideo.avi in a directory of the user's choice. It allows you a choice of frame rate and codecs for encoding. When the program is opened, you get a gui with 6 buttons on it: run, stop, close, help, configure, and about. First hit the configure button, and select desired frame-rate. If you want a choice of codecs, be sure the "remember codec" box is not checked. Select the directory of .jpgs and the directory for the output movie, and click OK. When that dialog box disappears, hit the run button, and a new dialogue box will pop up with a menu of available codecs. You should have, among others, the microsoft mpeg 4 (version 1 or version 2) codec. That seemed as good or better than any of the others available (cinepak, intel indeo, microsoft video 1, etc). Depending on the codec, you may get additional dialogue boxes to configure the codec. JPGVideo will not add sound to your movie. If you want to do that, I have heard that "virtual dub" software can do this. Virtual Dub is open-source software that runs under Windows only and is available from here: http://www.virtualdub.org/ . You can also add sound with mencoder in linux (see section 4). One annoying feature of JPGVideo generated movie clips: When installed into powerpoint presentations, an error message along the bottom border of the movie pops up as soon as the movie is clicked on in the .ppt slide. Or at least that happens to me, for JPGVideo version 1.04. It isn't a show-stopper, but it does subtract from the level of professionalism of the presentation. If this bugs you, and you really want an .avi clip, try using mencoder (section 4). 3. USING IMAGEMAGICK TO CREATE MPEG1 (.mpg) MOVIES ImageMagick is a very useful set of command-line tools for image manipulation. It runs under linux and Windows, and possibly solaris and the Mac. If it is not already installed on your system, you can get the software from http://www.imagemagick.com . It has a simple, easy to use command-line technique for generating mpeg1 (.mpg) movie clips. The attraction of ImageMagick is that mpeg1 (.mpg) files are in principal playable by most media players, and that most linux machines probably already have ImageMagick installed. For some reason (probably licensing issues), however, the encoder needed for doing the mpeg encoding is typically missing. To find out if you have it, you can type "locate mpeg2encode" and see if it shows up. If it doesn't, then you can download the source tarball from http://www.mpeg.org/MPEG/MSSG/#source . The current version of the source tarball is mpeg2vidcodec_v12.tar.gz . Once you've downloaded and unpacked the tarball, you can go into the top level directory of the distribution and type 'make', followed by 'make test'. Then descend into the src/mpeg2dec and src/mpeg2enc directories, and as root, copy mpeg2encode and mpeg2decode into e.g. /usr/local/bin or somewhere else in your path. Make sure they're executable. For MS Windows machines, there are pre-compiled binaries of ImageMagick available from their website at www.imagemagick.org . The windows version thankfully already has the mpeg encoder built-in, so it works out of the box, using a command-line interface identical to the linux version. Once that's done, and assuming you have already created a directory full of .jpg images you want to animate, you can go to that directory and type convert *.jpg blah.mpg and after a lot of grinding, voila - the movie blah.mpg exists! Several notes: Almost all encoders and players of .mpg movies assume the frame rate will be 25fps, so the easiest thing is to plan on this from the beginning when you create your .jpg images. If you want a 5 second clip, this means you'll need about 125 images. Movies made with the default settings tend to look a little fuzzy, but they *do* play in wmp, realplayer, and quicktime. A cautionary note: Movies consisting of more than 100-200 frames of high quality jpeg images take a lot of time and memory to convert to an .mpg movie with ImageMagick. If your movie consists of many frames, you should consider using mjpegtools (see section 5a) rather than ImageMagick. You can increase the quality (but also the size) of the movie by setting the quality parameter in convert to any value up to 100, for example: convert -quality 80 *.jpg blah.mpg The default quality level is set to 75. While increasing the quality setting definitely increases the visual quality of the movie, it has 2 negative side-affects: (1) The size of the movie file is increased, but more importantly (2) the increased bit-rate needed to play the movie causes many common players to fail. My experience, using a 150 frame test movie with an image size of roughly 700x500 pixels, is that changing the quality setting from the default to 80 had this affect on common media players: (1) Realplayer choked, (2) quicktime played the movie haltingly, and (3) wmp was only just able to keep up. Increasing the quality setting from default to 80 resulted in about a factor of 2 increase in movie filesize; increasing quality to 100 resulted in a size increase of more than a factor of 20! The linux movie player mplayer was able to play all qualities of the .mpg movies without problems. It is possible that this problem can be side-stepped by using smaller image sizes, but I haven't really explored this. In a cheasy way, you can change the effective frame-rate by using the delay flag to slow down the movie: convert -delay 10 *.jpg blah.mpg The delay parameter is in units of 1/100 of a second, so -delay 4 would be the default setting. In reality, rather than changing the frame rate, the encoder just inserts repeated frames, giving the viewer the impression that a slower frame rate is being used, but instead the movie file is simply larger (has more frames). The Windows version of "convert" seems to ignore the delay parameter, at least for me. You can use both the "delay" and "quality" flags at the same time, if you want. If you want to create a sound-track with your movie, you are S.O.L. with ImageMagick. If you want sound in your .mpg movies, you can encode the sound track using mp2enc and multiplex the audio with the video using mplex. mp2enc and mplex are tools from Mjpegtools (see Section 5). There are a few other useful uses of "convert" within ImageMagick, including the conversion of video format into a series of .jpg images. For example, suppose you wish to create a series of .jpg images from an animated gif: convert blah.gif test%03d.jpg This will create a numbered series of .jpgs from the animated gif, with file names of test000.jpg, test001.jpg, etc. The % symbol in the file name tells convert that you will be using a C-style format statement to define the series of file names, the 03d means 3 digits, 0-filled from the left. This would be a necessary step to e.g. creating an .avi file, using mencoder (see section 4). To create an animated gif from a series of .jpg images, you can reverse the calling sequence: convert *.jpg blah.gif In addition to its ability to create simple .mpg videos, ImageMagick can play animations, from a series of images, or from a .mpg or an animated gif. For example, to test your .mpg movie, you can try animate blah.mpg and then compare that to an animation of your original images: animate *.jpg 4. USING MENCODER/MPLAYER TO CREATE .AVI MOVIES In contrast to the ease of installing ImageMagick, installing mplayer and mencoder is quite involved, if you build from source. However, because of the wide range of what you can do, it is definitely worth it, in my opinion. Mplayer can play almost all movie formats. Mencoder can encode a wide variety of formats, but is most useful in encoding .avi movies using either the mpeg4/divx codec or a Microsoft Mpeg4 compatible codec. The user has great latitude in controlling quality and framerate, and soundtracks can be added if you want. The mencoder software is geared primarily toward copying movies from DVD to the hard drive in other formats, but is also useful for creating movie clips for scientific purposes. Dave Bercik's guide to installing mplayer/mencoder is extremely good and is available at http://solarmuri.ssl.berkeley.edu/~bercik/team/software/applications/MPLAYER/mplayer_build_HOW-TO.html The MPlayer manpage documentation (man mplayer or man mencoder) has a huge amount of information about encoding movies. For version 1.0pre4, there are minor discrepancies between the even more extensive HTML documentation included in the source distribution c.f. the man pages. As far as I can tell, the man pages contain the most up-to-date information. Information on mencoder in this writeup refers specifically to version 1.0pre4, so if you have a different version of mplayer, the command-line syntax may differ slightly from what is described here. NOTE: Although mencoder can encode .mpg (MPEG1) movies, no movie player plays them correctly except mplayer. Therefore no information is included here on MPEG1 encoding with mencoder. Use ImageMagick (Section 3) or Mjpegtools (section 5) if you want to create .mpg movies. 4a. MAKING MPEG4/DIVX .AVI MOVIES The most robust and efficient encoding format for .avi movies under mencoder is divx or mpeg4, which seem to be roughly equivalent. However, Mpeg4/divx movies will require that the user (or the computer hooked up to the LCD projector at your meeting) has a divx codec installed to play the movies under windows or (presumably) on macs. This is necessary if you want divx movies to play in powerpoint. You can get the divx codec for windows/mac machines from www.divx.com/divx . Get the free, non-adware version of the codec and the movie player. Depending on the version of Windows, there is the strong likelihood (see section 4b) that movies encoded with the msmpeg4v2 codec will play *without* the DIVX codec installed. This is an important consideration if you have no control over the machine on which your movie will be displayed. Assuming for the moment you want to go ahead with DIVX encoded movies, then if you have a directory with a series of ordered .jpg files, (created in the same order that an "ls" command would display), you can create a simple mpeg4/divx movie "output.avi" as follows: mencoder "mf://*.jpg" -o output.avi -ovc lavc -lavcopts vcodec=mpeg4 This movie will have the default frame rate, and may look a little fuzzy, depending on details of the .jpg files. To include parameters which increase the quality (but also the length) you can specify a higher video bit rate (vbitrate) and toggle on the "very high quality" (vhq) flag as in this example: mencoder "mf://*.jpg" -o output.avi -ovc lavc -lavcopts \ vcodec=mpeg4:vbitrate=3000:vhq To change the frame rate to e.g. 6fps in this example, you can do this: mencoder "mf://*.jpg" -mf fps=6 -o output.avi -ovc lavc -lavcopts \ vcodec=mpeg4:vbitrate=3000:vhq Finally, if you want to add a sound-track to your movie, you can record annotations using e.g. the gnome sound-recorder, which creates a .wav file. The .wav file can be converted to an .mp3 file with lame or bladeenc, e.g. lame file.wav file.mp3 If you followed Dave Bercik's instructions for building mplayer, you should have lame installed, but if not, you can download the latest version of the source tarball from www.lame.org and compile/install it. To use the file "file.mp3" as a sound track for your divx5/mpeg4 movie, you can do this: mencoder "mf://*.jpg" -mf fps=6 -o output.avi -ovc lavc -lavcopts \ vcodec=mpeg4:vbitrate=3000:vhq -oac copy -audiofile file.mp3 If you have the divx codec installed under windows, it will play the soundtrack along with the movie (or at least it does for me). If, for some reason, instead of using the open source libavcodec, you decide to install the commercial (but free) divx codec for linux from www.divx.com/divx , and you have built support for this into mplayer (see Dave Bercik's mplayer installation writeup), you can use that codec for encoding as follows: mencoder "mf://*.jpg" -o output.avi -ovc divx4 This will create the movie file output.avi with the default frame rate (25 fps). To create a movie with a different frame rate, e.g. 12 fps, try this: mencoder "mf://*.jpg" -mf fps=12 -o output.avi -ovc divx4 4b. MAKING .AVI MOVIES THAT WORK IN WINDOWS MEDIA PLAYER AND POWERPOINT If you have no control over the computer which will be playing your movie, and you are confident that it is a MS Windows machine of some kind, you probably will want to use the msmpeg4v2 codec under mencoder's libavcodec, since there will be no guarantee that the divx codec will be installed. My experiments thus far have shown that the msmpeg4v2 codec works in Windows XP, Windows 2000, and Windows 98 1st edition machines (other versions not yet tested). To see if this codec is installed on the windows machine, you can check this: Under Windows start -> control panel -> sounds and audio devices -> -> hardware -> video codecs -> properties -> properties, there should be a microsoft mpeg-4 video codec v1 listed as installed. [This doesn't seem to square with the v2 listed on the mencoder libavcodec's video codec!] Here's an example showing how to make an msmpeg4v2 encoded movie with a user-defined frame rate of 6fps and a user specified video bitrate: mencoder "mf://*.jpg" -mf fps=6 -o output.avi -ovc lavc -lavcopts \ vcodec=msmpeg4v2:vbitrate=3000:vhq The .avi movie made in this way seems to play OK in windows media player and in powerpoint. They both honor the frame-rate specified when mencoder made the movie. Unfortunately, if you try to include a sound-track in the same way as the earlier DIVX example, the windows media player won't play the movie at all. Instead, try encoding the audio from a .wav file into mp3 using the mp3 audio codec in lavc as follows: mencoder "mf://*.jpg" -mf fps=6 -o output.avi -audiofile file.wav -ovc \ lavc -oac lavc -lavcopts acodec=mp3:vcodec=msmpeg4v2:vbitrate=3000:vhq This works for me, at least in my windows xp machines. It has also been demonstrated to work (video and audio) on a windows 2000 laptop without the divx codec installed. The video works on a windows 98 laptop with an old version of the windows media player, but the audio is silent. Do not use a .mp3 file as the audiofile in this case! It will cause mencoder to get stuck in an infinite loop. If the soundtrack is already encoded into an mp3 file, you can convert it back to .wav format using lame: lame --decode brian.mp3 brian.wav 4c. MAKING MJPEG ENCODED .AVI MOVIES For very high quality video (but also large file sizes), you can try using the mjpeg video codec: mencoder "mf://*.jpg" -mf fps=12 -o output.avi -ovc lavc -lavcopts vcodec=mjpeg Unfortunately, the codec to read mjpeg encoded video is only available for a price ($) for windows machines, or at least that's what my investigations led me to conclude. One additional point about using the mjpeg codec: Movies encoded with it can be translated into quicktime format using the lavtrans utility from mjpegtools (see section 5b). But be careful to only use the default frame rate (ie omit the -mf fps=12 option above): Any other specified rate used to build the .avi movie will result in an error when it is translated into quicktime. 4d. CREATING ANIMATED GIFS WITH MPLAYER Some movie formats, like animated gifs, can be created directly from the movie player mplayer, by specifying the "vo" parameter to be gif89a . For example, to convert the movie output.avi (created in any of the ways described above) to an animated gif, enter this command: mplayer output.avi -vo gif89a This will create the animated gif file out.gif . The animated gif can be viewed in a browser. Unfortunately, the color reproduction seems to vary from frame to frame, although the movies are still viewable. 4e. CONVERTING STREAMING MEDIA FORMAT VIDEO TO .AVI MOVIES mplayer and mencoder can be combined to convert streaming media videos to .avi files. While in principle it is possible to encode streaming media directly into mencoder, my experiments with this resulted in videos that looked like a bad acid trip. Instead, it is better to first use mplayer to dump the video stream into a file, and then use mencoder to encode that file into a more standard media format. The streamdumping procedure looks like, for example: mplayer -dumpstream or mplayer -dumpstream Wait for mplayer to exit after the stream stops (there is a several minute delay between the end of the network streaming and when mplayer finally decides nothing more is coming.) This creates a file called ./stream.dump . To convert stream.dump into e.g. a divx movie with an mp3 soundtrack, the format would be: mencoder stream.dump -o test.avi -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4 Note however, that if one is converting from real streaming format, that that format is considerably more compressed than divx5 - the divx5 video in the experiments I did was 50-80% larger than the stream dumped real format video file. This may be a bit off-topic, but it is interesting to note that for purely audio streaming media, these can be captured by mplayer and stored in pcm/wav format, for later playing as a raw .wav file, or by converting the .wav file to the much more compressed mp3 or Ogg Vorbis format. For example, to record a live KQED windows media audio stream, you can try this: mplayer -cache 500 -playlist http://www.kqed.org/streamingfiles/kqed_wmp.asx \ -ao pcm -vo null -vc dummy This creates a file called audiodump.wav (and that file can either be played or converted to mp3 with lame - see earlier examples). The -vo null -vc dummy just tells mplayer not to bother with any video processing. If you actually try this example, you should note that KQED is particularly stingy with bandwidth and it will sound crappy, but the live audio sounds crappy too. 4f. CONVERTING MOVIES FROM OTHER FORMATS TO .AVI MOVIES Mencoder and mplayer can be used to convert just about any format into an mplayer formatted movie, and hopefully, a power-point friendly movie. For example, to convert a quicktime movie (which doesn't play in powerpoint unless you have a mac) into an msmpeg4v2 formatted movie (assuming there's no audio) you can do this: mencoder T171_020624_19.mov -oac copy -ovc lavc -lavcopts vcodec=msmpeg4v2 \ -o test.avi To slow down the frame rate is trickier. If you try and use the ofps and fps parameters in mencoder to reduce the output frame rate, it assumes you want to keep the total playing time the same, and so will simply skip over frames to keep the total playing time an invariant. If you want to keep the same number of frames, but just play them slower, I have found the simplest solution is to first play the movie with mplayer, but specify the vo (video out) option as 'jpeg', which will create an ordered sequence of .jpg frames in the current directory: mplayer T171_020624_19.mov -vo jpeg Then, convert the .jpgs to eg an msmpeg4v2 formatted movie as before: mencoder "mf://*.jpg" -mf fps=6 -o output.avi -ovc lavc -lavcopts \ vcodec=msmpeg4v2:vhq 5. USING MJPEGTOOLS TO CREATE MPEG1 (.mpg) MOVIES AND TO TRANSLATE .AVI TO QUICKTIME MOVIES Mjpegtools is a set of command-line utilities that appears to have been developed primarily to record video-cd's and super video-cd's from e.g. TV programs, camcorder recordings, DVDs, or other movie formats (like DIVX). VCDs use MPEG1 encoding, and SVCDs evidently use MPEG2 encoding. You'll need to download the mjpegtools and MMX JPEG tarballs from this website: http://sourceforge.net/projects/mjpeg/ . They also recommend you install libquicktime ( http://sourceforge.net/projects/libquicktime ). I did that, but I am wary -- according to some mailing lists on mplayer I've seen, people who installed libquicktime had problems with playing quicktime movies in mplayer. Anyway, aside from that caveat, carefully follow the installation instructions in the mjpegtools tarball. The notes about command line options given here could differ, depending on the version of mjpegtools you install. I installed version 1.6.2 . Briefly, the installation goes like this: After unpacking the mjpegtools, MMX JPEG, and libquicktime (if you decide to do include it) tarballs, go first into the MMX JPEG directory, and type './configure' and then 'make' . Do *not* type 'make install'. Note that before doing this, you must have the nasm assembler installed. To check to see if it's there, just type 'which nasm'. It is typically included in many linux distributions, but if not, you can download and install it from the nasm homepage at http://www.cryogen.com/Nasm/ Then, if you decide to install libquicktime, go into the libquicktime directory, and type './configure' , then 'make' , and then as root, 'make install', followed by 'ldconfig'. Finally, go into the mjpegtools directory, and type './configure --with-jpeg-mmx=/path/to/jpeg-mmx' where /path/to/jpeg-mmx is the directory where you just compiled JPEG-MMX. If you don't want libquicktime, be sure and add a '--with-quicktime=no' to the ./configure line. After that, type 'make', and then as root, 'make install'. 5a: MPEG1 MOVIES: VIDEO AND AUDIO When using the tools to create .mpg files, the frame rate should be fixed at 25fps. Trying other values results in fatal errors. To create the video part of an .mpg clip from a series of .jpg frames: jpeg2yuv -f 25 -j file-%02d.jpg -I p=none | mpeg2enc -b 2500 -o result.m1v The -f parameter: The frame rate. Best leave it at 25 or errors result. The -j parameter: The list of files. This is a mixture of the file name combined with a C-style integer format statement. Here, it means that the file names will have 2 digits after "file-" and they will be 0 filled from the left. The -b parameter is the video bit rate. On my laptop values 3500 and greater resulted in errors. The video-only file here is called result.m1v . If you don't want to add a sound track, you can rename it as a .mpg file and it should play fine with the standard movie players. There are many, many parameters to both jpeg2yuv and mpeg2enc that I haven't explored. To create an .mpg file with both an audio and a video track, the sound *must* be encoded with mp2 format. This is done with the Mjpegtools mp2enc utility. To convert e.g. brian.wav to an mp2 file, do the following: cat brian.wav | mp2enc -v 2 -V -o brian.mp2 These choices of mp2enc parameters are evidently consistent with what is done in VCDs. I haven't explored the available parameters. Programs I've found thus far (I haven't looked very hard, I admit) that can play the audio-only mp2 files are the command-line utilities plaympeg or mpg123, eg: plaympeg brian.mp2 To multiplex the video and the sound-track together, use the mjpegtools utility mplex: mplex brian.mp2 result.m1v -o testmpjpegtools.mpg It is not necessary to restrict oneself to .m1v or .mpg video generated by mjpegtools. For example, I have successfully added sound using mplex to video .mpg files created with ImageMagick. You may get an error message during the mplex operation if the video runs out before the audio does, but it creates the file anyway, and both the audio and video play until the end of the video steam. (Actually, the outcome is movie-player dependent. Mplayer stops as soon as the video is over; windows media player stops the video and waits till the audio finishes, for example) 5b. TRANSLATING AVI MOVIES INTO QUICKTIME MOVIES Mjpegtools has a command-line utility, "lavtrans", that can convert back and forth between .avi and .qt or .mov (quicktime) file format (most likely, this won't work unless you have libquicktime installed). However, I've noticed a lot restrictions, based on my own trial-and-error experience. No frame rate other than 25 fps works, and the .avi movie must be encoded with the mjpeg codec -- nothing else seems to work. To create a .avi file with the mjpeg codec, use mencoder (see section 4c). Don't forget to use the default frame rate. Once you've created such a movie, convert it use this command: lavtrans -o moviename.mov -f q input.avi Here, input.avi is the movie you created with mencoder, and moviename.mov is the output quicktime movie. The "-f q" option tells lavtrans that the output file format is quicktime. lavtrans can be used to convert the other direction as well. If you just type "lavtrans" it will give you the command line options. There is also a manpage for lavtrans. I have found the resulting quicktime movie looks good and plays well in the standard Apple quicktime movie player I downloaded onto the windows part of my laptop. I have not yet investigated whether sound present in the .avi file will be copied into the quicktime file. 6. USING LIBQUICKTIME TO CREATE QUICKTIME VIDEO CLIPS As mentioned in Section 5, it is not clear to me whether installation of libquicktime might interfere with the playing of quicktime movies by mplayer, so I remain cautious so far about whether installing it is a good idea or not. Nevertheless, if you do install it, it has a crude capability for encoding .jpg images into quicktime movie clips. Details of installation are outlined in section 5 where the installation of mjpegtools is described. As far as I can tell, libquicktime consists primarily of a library of C functions for which one can construct much more detailed quicktime encoding and playing applications. It also contains a crude movie encoding utility, called qtrechunk. In contrast to the method for creating quicktime videos described in section 5b, qtrechunk *will* allow you to use frame rates other than 25fps. On the other hand, only the "jpeg" codec appears to make movies that play in e.g. Apple's quicktime player, and the movies are pretty much uncompressed from the original jpeg frames, so the movies have high quality, but can be very large. One can download the libquicktime source from http://sourceforge.net/projects/libquicktime . Once installed, make sure qtrechunk is in your path. If you go to your directory of .jpg images, enter this: qtrechunk -f 10 -c jpeg *.jpg test.mov Here, -f 10 means a frame-rate of 10fps, and -c jpeg means the fourcc identity of libquicktime's "jpeg" encoder. For me, I get a couple of error messages: Open failed: no such file or directory (repeated twice), but the movie test.mov is successfully created. I don't yet know the significance of the error messages. The movie plays fine in Apple's quicktime movie player, and movies created with all frame rates I tried appeared to work correctly. For me, omitting the frame rate results in an error; the frame rate must be specified. Note that these movies have little or no compression, and if you aren't careful the file size can be gigantic. Although libquicktime appears to have a lot of codecs installed, I couldn't get movies encoded with any of them to work with Apple's quicktime player except jpeg. In particular, mjpeg (fourcc of mjpa) resulted in a movie that Apple's quicktime player told me was "corrupted", although mplayer played the movie fine. 7. Random Notes: Have discovered a problem in which certain .jpgs created by IDL using hard- coded colored arrows, won't display properly in mplayer when encoded into movies using any of the tools described here, even though the .jpg images look fine. Seems to be a subtle bug that depends on video hardware, specifically intel on-board video under linux, played with mplayer. A work-around: Use the -vf yuy2 option in mplayer, and then the movie plays properly. This problem doesn't seem to occur when the movies are displayed in windows with the same intel hardware.