Web Cam and Time Lapse

I’ve got a web camera attached to my Mac Mini. First, I wanted to set it up to take pictures out of my office window every 5 minutes or so, and upload them to this site. That might seem like a simple thing, but none of the easy-to-use Apple applications offered any help. With a little poking around, I found isightcapture, and wrote a short python script to call it every 5 minutes and ftp the resulting picture to my server.

while True:
    # take a picture
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    filename = "/tmp/pic-%s.jpg" % timestamp
    print "Say Cheese!"
    os.system('isightcapture -w 960 -h 720 %s' % filename)

    # upload it
    try:
        file = open(filename, 'r')
        print "uploading..."
        connection = ftplib.FTP('ftp.atomicspatula.com', 'henry@atomicspatula.com', 'password')
        connection.storbinary('STOR pic.jpg', file)
        file.close()
        connection.quit()
        print "done"
    except exception:
        print exception
    time.sleep(60)

This code writes timestamped pictures into /tmp, and uses it to upate a single file on the server.

With a nice sequence of pictures, I wanted to use QuickTime to make a nice time-lapse movie. But QuickTime seems to require that the pictures all have the same name with a sequence number, such as pic00001.jpg, pic0002.jpg, etc. Why Apple couldn’t have just suck in all the pictures in the folder in alpha-numeric order is beyond me. So, I wrote another little script to rename them:

rootdir = "/Users/henry/time-lapse"
files = sorted(os.listdir(rootdir))
i = 1
for file in files:
    print file
    shutil.move(file, "pic%.6d.jpg" % i)
    i = i  + 1

Tomorrow, I’m going to run it all day at 1 picture per minute, and see what that looks like at 15 fps.

Stay tuned!

Leave a Reply