You are here

Quicktime Movie from JPEG Images

Error message

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).

My latest idea for an art project that I can complete in a fairly short period of time involves the animation of still images. My first thought was to go for a walk and take pictures every so often, holding the camera at approximately the same level each time, pointed forward. When spliced together into a movie at, say, 10fps, you'd get a really choppy video where each image was visible for just long enough to register but not long enough to absorb much detail.

I went on to calculate that to make a one minute video at 10 fps, I needed 600 frames, and if I shot one frame every fifty feet I'd have to walk over five miles. Well, that put an end to that idea!

It wasn't long before it occured to me to mount the camera on a tripod in the car. Not only would this permit laziness, but catching the rear view mirror and dashboard would give some "anchoring" elements that would stay in relatively the same positon throughout. And now I could shoot as fast as the camera could shoot & save images to the card (about 3 sec. per frame).

At 30mph, I would be traveling 264 feet per second, so the video would be choppier than my original idea, but it would be ok for a test. I've included the test results as a "proof of concept" below.

Well, in the interest of saving time (laziness), I googled for an existing solution, and found it in mencoder. As luck would have it, mencoder was already installed (as part of the ffmpeg installation), so all I had to do was decipher the usage syntax.

Encoding from multiple input image files (JPEG, PNG, TGA, SGI)

Mencoder is capable of creating movies from one or more JPEG, PNG or TGA files. With simple framecopy it can create MJPEG (Motion JPEG), MPNG (Motion PNG) or MTGA (Motion TGA) files.

Explanation of the process:

  1. mencoder decodes the input image(s) with libjpeg (when decoding PNGs, it will use libpng).
  2. mencoder then feeds the decoded image to the chosen video compressor (DivX4, XviD, FFmpeg msmpeg4, etc.)

Examples. The explanation of the -mf option is in the man page.

Creating an MPEG-4 file from all the JPEG files in the current directory:

mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpg -ovc lavc \
-lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

Now, I don't know exactly what all these command-line options mean. I just copied it from the mencoder web site. But this creates an MPEG4 AVI file which isn't understood by Quicktime without a plug-in. From another site:

First, RTFD: http://mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html and read the doc about "-of lavc" and "-lavfopt" in http://mplayerhq.hu/DOCS/man/en/mplayer.1.html just use the lavc codec "svq1" instead of the one used on the example and append "-of lavc -lavfopts mov" to your command line.

After consulting the reference URLS above, two typos became apparent, so I tried:

$ mencoder mf://*.JPG -mf w=800:h=600:fps=10:type=jpg \
-ovc lavc -lavcopts vcodec=svq1:mbd=2:trell -oac copy -of lavf \
-lavfopts format=mov  -o output.mov

It crunched out a movie file while reporting "duplicate frame(s)" and "unsupported pixel format" for every image/frame. The movie was unplayable. I tried the original command which generated an AVI file playable by mplayer, but I haven't figured out how to generate a valid Quicktime movie.

Mplayer Info

Creating an MPEG-4 file from some JPEG files in the current directory:

$ mencoder mf://frame001.jpg,frame002.jpg -mf w=800:h=600:fps=25:type=jpg \
-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

Creating an MPEG-4 file from explicit list of JPEG files (list.txt in current directory contains the list of files to use as source, one per line):

$ mencoder mf://@list.txt -mf w=800:h=600:fps=25:type=jpg \
-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

Creating a Motion JPEG (MJPEG) file from all the JPEG files in the current directory:

$ mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpg -ovc copy -oac \
copy -o output.avi

Creating an uncompressed file from all the PNG files in the current directory:

$ mencoder mf://*.png -mf w=800:h=600:fps=25:type=png -ovc raw \
-oac copy -o output.avi

Note: Width must be integer multiple of 4, it is a limitation of the RAW RGB AVI format.

Creating a Motion PNG (MPNG) file from all the PNG files in the current directory:

$ mencoder mf://*.png -mf w=800:h=600:fps=25:type=png -ovc copy \
-oac copy -o output.avi

Creating a Motion TGA (MTGA) file from all the TGA files in the current directory:

mencoder mf://*.tga -mf w=800:h=600:fps=25:type=tga -ovc copy \
-oac copy -o output.avi