derwiki

Mar 18 2010

Timelapse Photography with your spare Ubuntu Box and Digital Camera

I recently decided to give timelapse photography another go, after being disappointed with the results about 2 years ago. First, a proof of concept: using the standard Canon EOS utility, my work Macbook, and a Rebel XTi, I was able to take 100 pictures, 60 seconds apart automatically. The utility works great for that. But I didn’t have a Macbook to spare AND I wanted to do it remotely — which pretty much meant Linux and command line. This is on a fresh install of Karmic Koala on an aging Thinkpad Z60t, but I think it’s pretty straightforward on other distributions (sub in repository management where needed).

First, some apps need to be installed: 

sudo apt-get install gphoto2 mencoder

(it’s really that easy, surprisingly). Running gphoto2 without any options will give you a list of it’s commands, showing it’s full power:

derwiki@zipper:/multimedia/photos/timelapse/20100317-first-attempt$ gphoto2
Usage: gphoto2 [-?valLnPTDR] [-?|—help] [—usage] [—debug] [—debug-logfile=FILENAME] [—quiet] [—hook-script=FILENAME] [—stdout]
[—stdout-size] [—auto-detect] [—show-exif=STRING] [—show-info=STRING] [—summary] [—manual] [—about] [—storage-info]
[—shell] [-v|—version] [—list-cameras] [—list-ports] [-a|—abilities] [—port=FILENAME] [—speed=SPEED] [—camera=MODEL]
[—usbid=USBIDs] [—config] [—list-config] [—get-config=STRING] [—set-config=STRING] [—wait-event] [—capture-preview]
[-F|—frames=COUNT] [-I|—interval=SECONDS] [—reset-interval] [—capture-image] [—capture-image-and-download]
[—capture-movie] [—capture-sound] [—capture-tethered] [-l|—list-folders] [-L|—list-files] [-m|—mkdir=DIRNAME]
[-r|—rmdir=DIRNAME] [-n|—num-files] [-p|—get-file=RANGE] [-P|—get-all-files] [-t|—get-thumbnail=RANGE]
[-T|—get-all-thumbnails] [—get-metadata=RANGE] [—get-all-metadata] [—upload-metadata=STRING] [—get-raw-data=RANGE]
[—get-all-raw-data] [—get-audio-data=RANGE] [—get-all-audio-data] [-d|—delete-file=RANGE] [-D|—delete-all-files]
[-u|—upload-file=filename] [—filename=FILENAME_PATTERN] [-f|—folder=FOLDER] [-R|—recurse] [—no-recurse] [—new]
[—force-overwrite]

Don’t get overwhelmed, we only want to do a few things:

gphoto2 -I 10 -F 3150 —capture-image-and-download —filename “%Y%m%d%H%M%S.jpg”

-I is interval between pictures in seconds, -F says take a maximum of 3150 pictures, the capture one is obvious, and —filename gives a filename format. Try it out, and you should start growing a folder like this:

derwiki@zipper:/multimedia/photos/timelapse/20100317-first-attempt$ ls -lh
total 5.9M
-rw———- 1 derwiki derwiki  895K 2010-03-17 20:51 20100317205145.jpg
-rw———- 1 derwiki derwiki  1.1M 2010-03-17 20:55 20100317205523.jpg
-rw———- 1 derwiki derwiki 1011K 2010-03-17 20:55 20100317205532.jpg
-rw———- 1 derwiki derwiki  991K 2010-03-17 20:55 20100317205542.jpg
-rw———- 1 derwiki derwiki  1.1M 2010-03-17 20:55 20100317205553.jpg
-rw———- 1 derwiki derwiki 1021K 2010-03-17 20:56 20100317205603.jpg

After I was confident that this was working, I set up the camera, tripod, and laptop near a window. I ssh’ed into it and started up a screen (man screen) instance and ran:

gphoto2 -DR # delete recursively
gphoto2 -LR # list recursively

To clear any existing images off my cameras memory. After a few hours, I had all the images I wanted and it was time to string them together with mencoder:

mencoder -nosound -ovc lavc -lavcopts vcodec=mjpeg -o timelapse-10fps.avi -mf type=jpeg:fps=10 -vf scale=800:600,rotate=2 mf://*.jpg

  • -nosound is what you think
  • -ovc lavc means encode with a libavcodec codec
  • -lavcopts vcodec=mjpeg sets the video format to motion JPEG (mpeg4 works too)
  • -o specifies the output filename
  • -mftype=jpeg:fps=10 sets it to jpeg mode and sets the FPS to 10
  • -vf scale=800:600,rotate=2 downsamples the resolution (I had been getting segmentation faults without resizing), rotate2 rotates the image once counterclockwise
  • mf://*.jpg says read all .jpgs in the current directory (looks like a simple bash substitution, so as long as “ls” orders your files correctly, mencoder will read them in that order)

There are many more options for mencoder, and Linux.com has a nice write-up about mencoder that’s worth checking out.

And of course, a preview of the final product:

Comments (View)
blog comments powered by Disqus