Quantcast

Timelapse: OSS Secrets

I thought I would share a couple of helpful GPL command lines that really get the job done if you want to animate a sequence of images.

First (via Mike) is news of the jhead project. Unbelievably the ImageCapture.app application that ships with Mac OS X cannot handle more than several thousand images. ImageCapture.app will copy all of the image files, but the number sequence wraps around and it overwrites thousands of the earlier images in the sequence!! jhead fixes all that by renaming all of the image files based on the EXIF timestamp in the JPG file. brilliant! Here is the commandline he recommends:

CODE:
  1. jhead -nfpx%Y%m%d-%H%M%S -dt -ft $*

Now you have a nifty sequence of hopefully hi-res images. One of the cool things about timelapse is you can shoot 5 megapixel images and then scale them down to NTSC (720×480) or HD (1920×1024) resolution. In fact if some crazy 5 megapixel video format comes out 10 years from now, you will be able to support that as well! (As an aside, the Digital Cinema releases that are dribbling out to theaters these days are at 2,000 pixels wide. Eventually that will go up to 4,000 pixels wide, but there are not currently projectors that can support that resolution!)

So anyway, megapixels. How do you scale the images without fudging it up? A little known fact is that most video that looks crappy because of “the video compression” actually looks crappy because of the way the video was scaled down to its postage stamp resolution. So here is what you do: Use the fantastic ImageMagick “convert” command to scale your images down at even higher quality than photoshop! for free! and without using a dumb GUI scripting language. You can read about image scaling in laborious detail or you can just use this command line:

CODE:
  1. convert  -filter sinc -resize 720×480 foo.JPG foo_ntsc.JPG

I put the following bash script into a makefile to process my timelapse library:

CODE:
  1. for i in *; do  if [  ! -e “$i/ntsc_jpg/” ]; then  mkdir “$i/ntsc_jpg”; for i in orig_jpg/*.JPG; do echo $i; echo convert  -filter sinc -resize 720×480 ntsc_jpg/`basename $i`;  done fi done

And finally I would like to share the “ghetto HD” format that VJ Science came up with for doing 16:9 format on an XGA projector. This command includes cropping to get my 1600×1200 images into 16:9 aspect ratio … if you have a different source resolution, I’m going to leave it to you multiply your image width by 9 and divide by 16 to figure out the how many pixels to crop on top and bottom. The idea is to crop first and then scale down. Although I guess in terms of quality it doesn’t matter the order.

CODE:
  1. convert  -crop 1600×900+0+150 -filter sinc -resize 1024×576 foo.JPG foo_xga.JPG

Now you’ve got a nifty sequence of beautifully scaled images. Time to make video! Which of the 7 bajillion video codecs are you going to use? My recommendation is to use ffmpeg to make an mpeg-2 “master” that you can distribute by uploading to youtube, archive.org, and so on. ffmpeg understands image sequences! So here is a quick way to get your mpeg-2 video (no audio). This command assumes your images are named like “IMG_0001.JPG” and so on … I know that doesn’t jive with the jhead naming I’ve outlined above, but you are a big unix haxor and can figure that out.

CODE:
  1. ffmpeg  -i “IMG_%04d.JPG” -b 10000 test.m2v

For my purpose I am building up a video library for doing VJ/video mixing stuff. In this use case video quality and decode speed is much more important than bitrate. Since decoding mpeg-2 “I” frames is about 3x faster than decoding “P” or “B” (difference) frames I use this command to get a high quality I-frame only mpeg-2 stream:

CODE:
  1. ffmpeg  -i “IMG_%04d.JPG” -vcodec mpeg2video -intra -qscale 4 test.m2v

You can get higher quality by dropping qscale down even lower, but I think if you do qscale=1 your video basically won’t be compressed at all :-) rajbot?

So there you have it! The basics of an Open Source timelapse production pipeline. I use these tools on Mac OS X. Of course they are available on GNU/Linux. And you can also get them working under windows using Cygwin … We need more timelapse!

Link to jhead project
Link to ImageMagick project
Link to FFmpeg project

One Response to “Timelapse: OSS Secrets”

  1. November 17th, 2007 | 2:18 pm

    There is so much good stuff in this post.. Thank you!!!

Leave a reply