Sample

Time-lapse office camera

One pre-spring day I was looking out my window at work and saw the big tree outside and though it'd be cool to make a time-lapse video of the tree budding. I situated the camera so that it also captured the parking lot across the street so I could do shorter week-long or day-long videos and watch the parking lot rapidly fill up and empty.

Camera Map
The camera's field of vision

Download

My script currently generates four time-lapse video files. The AVI files are mpeg4 with no audio. The MP4 files are two-pass XviD with an AAC audio track and run well in Quicktime without the need for plugins. There's a 12fps and 6fps in each format. The 6 fps will be 1 second of video per hour of elapsed time, and the 12 will be one second for every two hours.

Last Updated: 11 Apr 2007
AVI
12 fps (8.6 MB)
6 fps (17 MB)
MP4
12 fps (13 MB)
6 fps (21 MB)

The Setup

A while back I bought an iSight for no reason, so it was nice finally have a use for it. I had also bought EvoCam which is a great tool for doing automated camera stuff. So that's running on my PowerMac G4 (Quicksilver) which is conveniently located next to the window in my office. It captures an image every 10 minutes to disk. I have a cronjob setup to rsync the image directory to another server every hour so I can generate the videos and have a backup. The iSight is all right for now, but I may look into getting a camera that can handle low-light better. After dusk, the image is completely black with only a few small dots of light. I'd also like a camera that has a larger depth of field and better color.

Generating the video

I use ImageMagick to stamp the time on the images and then mencoder to generate the video. EvoCam can stamp the images with the time, but I'd rather leave the images bare and stamp them myself in post-processing so that I can easily change how I do the stamping or if I want to do it at all. Lastly I use ffmpeg to create a version of the video with an audio track, just so it's a bit more enjoyable to watch.

 1 #!/bin/bash
 2 
 3 # Audio track to add to the video. It will be clipped to match the video length
 4 atrack=/home/mroach/virtual/Music/_misc/Drummania\ -\ The\ Least\ 333\ Sec.mp3
 5 
 6 # Delete the night images. They're almost entirely black
 7 #       Month      Day         0h - 5h             Month      Day        20h+
 8 rm 2007-[0-1][0-9]-[0-3][0-9]-0[0-5]*.jpg; rm 2007-[0-1][1-9]-[0-3][0-9]-2*
 9 
10 i=1
11 
12 echo Labeling the images...
13 sh -c 'ls -1 *jpg' | while read f; do
14   # Use the image mtime for the date stamp
15   cdate=$(stat -c %y "${f}")
16 
17   # Make the label stamp in Week DayName Month Day Year Hour:Minute format
18   label=$(date +"W%V %a %b %d %Y %H:%M" -d "${cdate}")
19   newname=$(printf %08d ${i});
20 
21   #echo "Labeling $f with $label and moving to $newname.jpg"
22 
23   # Stamp the image with the label
24   convert "${f}" \
25     -fill '#0008' -draw 'rectangle 5,450,170,470' \
26     -fill white -annotate +10+465 "$label" \
27     "${newname}.jpg"
28 
29   let i=i+1
30 done
31 
32 echo Deleting the source images...
33 rm *-*jpg
34 
35 make_v() {
36   mencoder mf://*jpg -mf fps=${1} -ovc lavc -lavcopts vcodec=mpeg4 -o oc_${1}fps.avi
37 }
38 
39 make_v 6
40 make_v 12
41 
42 make_av() {
43   # Have to set the video time to the length of the movie otherwise the length of
44   # the video will be length of the song, if it's longer, which it probably will be
45   len=$(midentify oc_${1}fps.avi | grep ID_LENGTH | cut -d "=" -f2)
46   cmd='ffmpeg -y
47               -i oc_${1}fps.avi
48               -i "${atrack}"
49               -t ${len}
50               -vcodec xvid
51               -b 900k
52               -g 120
53               -async 50
54               -acodec aac
55               -ab 128k
56               -ac 1'
57 
58   eval $cmd -pass 1 oc_${1}fps_ml.mp4
59   eval $cmd -pass 2 oc_${1}fps_ml.mp4
60 }
61 
62 make_av 6
63 make_av 12