Skip to content

Comperas Midterm: Image Time Comparator

March 5, 2012

While working on The Image Time Comparator for my Where-When Picture Project, I felt like it was on a good trajectory for a nice-sized midterm project. In the previous iteration, the user can compare a current webcam image with an image from 24 hours ago by moving the mouse up and down on the screen. Here are the enhancements I made from most significant to least:

  • Viewer can select how far back in time they want to go, from 5 minutes to 6 days
  • Viewer can view embedded time-lapse videos for the past 24 hours and all hourly images since the project started
  • A floating welcome screen introduces the viewer to the project
  • The server now pulls the images from an IP camera instead of a firewire webcam. The firewire webcam was entirely unreliable and the quality of the new camera is better (a little).
  • Mouse movement left to right now moves time forward (instead of up to down)
  • Image was resized so as to fit into browser window without cropping

Coding the interface to select a time frame was incredibly time consuming. I wanted to ensure that the link bar on the bottom indicated which view was selected and that took quite a bit of PHP coding. I also spent many hours tweaking a bash scripts to generate both time-lapses. Here’s what one of them looks like:

# creates timelapse video from all the jpgs saved in the 24 hour folder
# copy files starting from 24h ago to a work directory, named sequentially:
for (( i=1439; i > 0; i-- )) do
  infile="/Users/matt/Sites/images/`date -v-${i}M +%H%M`.jpg"
  newfile=$(printf "/Users/matt/Sites/vid/work/%04d.jpg" ${b}) #04 pad to length of 4
  cp ${infile} ${newfile}
  let b=b+1
# make video from those files: (flags: -r: frame rate, -b: bit rate, -y: force overwrite, -i: input
/usr/local/bin/ffmpeg -r 30 -b 3800 -y -i /Users/matt/Sites/vid/work/%04d.jpg /Users/matt/Sites/vid/work/full24hvid.mp4 &> /Users/matt/Sites/vid/vid.log
# making the videos takes time, we don't want public files
# to be written while they're being accessed by the web user
# so move the ffmpeg output file to replace the public filename:
mv /Users/matt/Sites/vid/work/full24hvid.mp4 /Users/matt/Sites/vid/full24hvid.mp4 
# clean up work files:
rm /Users/matt/Sites/vid/work/*

I am especially proud of this because I haven’t done much bash scripting at all, and this is actually rather complex. It goes through each archived image (which uses a timestamp as a filename), copies it to a working directory with new names (representing the appropriate frame number), 0 through 1439 for each minute in 24 hours. Then it calls ffmpeg to assemble the jpegs into an MP4 and finally, it deletes the work files. This operation is run once an hour, as set up in the crontab.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: