Automating Time Lapse Workflow with Python

I love watching time lapses. I've even made some of my own in the past, for work and for fun. So, when I moved into a new apartment with construction going on right outside my window, I knew I had an opportunity to capture its progress using time lapse photography.

This is the guide I have been using to construct time lapses from a collection of photos.

The Goal

Unlike some of the time lapses I've done in the past, this one is expected to go on for at least a year (or more depending on how long I stay in this apartment). That means that the system I set up has to be robust and reliable so I don't miss large chunks of time. However, I'm also very frugal, so I wanted to be able to do all this with a $20 android phone.

The Setup

Capture Software

In order to store thousands of photos reliably, I decided to FTP them to a server, rather than trying to store them all on the phone's SD card. I found that the impressively featured MobileWebCam app for android could save straight to an FTP server.

Hardware Setup

Originally I set up my ZTE Maven on my windowsill. Unfortunately, the charging port is on the side of this budget phone, so it had to be "upside-down" as far as MobileWebCam is concerned. This meant for a little more post-processing in VirtualDubMod to flip the image.

A sample upside-down image of the construction

 

 

 

 

 

 

 

Once I was happy with the phone's capabilities, I decided to spend a few more bucks and mount the phone properly. I got a goose-neck mount and attached it near my window. Now my phone could have a clearer view, and it isn't upside-down!

Phone in goose-neck mount

 

 

 

 

 

 

 

Making it Reliable

I wanted this system to take photos ad infinitum without me having to worry about the phone crashing or the connection to the FTP server breaking. Initially I had a calendar event every week to manually check the FTP folder and see if any new files came in. After a time, this got to be quite annoying, although I did catch the phone freezing a few times during this period.

There had to be a better way, so I thought of a reason to dust off the old raspberry pi: a python script to automatically check on the time lapse every day. I wrote the script (you can find it on my GitHub), and set up my pi to run it daily as a cron job. Basically, the script sees how many files are in the FTP folder, compares this value to what it found last time, and then sends me an email with the status. Much better than having to do it myself! Here's an example email I would get:

Timelapse is working! We got 150 more files since last time for a total of 8234

 

Creating the Video - Challenges

Every so often, I will compile the photos taken into a time lapse video. Per the guide referenced earlier, VirtualDubMod is an excellent free choice for creating such a time lapse. Though VirtualDubMod is pretty picky, and it requires all image filenames to be contiguously numbered (such as 1.jpg, 2.jpg, 3.jpg, etc rather than 1.jpg, 4.jpg, 5.jpg, 8.jpg).

Generally this problem is solved using a bit of software called Ant Renamer, which can enumerate files with ease. The tricky part is that once the files are transferred from the FTP folder, the "created date" becomes the time the file was transferred. So the only way to sort the files is by name. This soon becomes a problem when you have files named something like:

  • 1.jpg
  • 2.jpg
  • 4.jpg
  • 6.jpg
  • 11.jpg
  • 12.jpg
  • 13.jpg
  • 22.jpg

Because this sorts as:

  • 1.jpg
  • 11.jpg
  • 12.jpg
  • 13.jpg
  • 2.jpg
  • 22.jpg
  • 4.jpg
  • 6.jpg

Another Python Solution

To solve this problem, I wrote another Python script I called the "File Name Length Equalizer" to add zeros to the beginning of each file name such that they became the same length. Then they could be sorted with ease!

Before and after equalizing file names

Once the files were sortable, I used Ant Renamer to enumerate them, and then imported them into VirtualDubMod and processed them per the guide.

This project posed a lot more challenges than originally anticipated, but it was fun to be able to come up with automated solutions that allowed me to get the end result I was looking for.

Leave a Reply