Saturday, July 17, 2010

Creating a Time-Lapse Video of Screen Captures

I recently came across a really interesting web site that provided a graphical representation of real-time electricity prices in the wholesale market (something relevant to my day job). The image updated every five minutes, which gave you an interesting real-time perspective. However, there was no option to view past data for a historical perspective. That was disappointing to me because as cool as it was to see the data in real-time, it had a much more significant meaning when compared to recent history.

That inspired me to find a way to capture the screen image every so often and assemble a collection of the images together to view as a video. That couldn't be hard to do, could it?

Well, it really wasn't that hard! Here's how I accomplished the task.

The web site that I wanted to capture the image from uses the Adobe Scalable Vector Graphics ("SVG") viewer. This plugin requires the use of Microsoft Windows and Internet Explorer (Yes, I know it will run on older version of OS X, but we're talking circa 2001 folks; I've updated my operating system since then!) Requiring Adobe SVG was very disappointing since I run mostly Apple Mac OS X machines in my home office. However, I use VMWare Fusion to run Windows 7 Ultimate on the Mac Pro and I also keep an old Sony Vaio desktop around to run Windows 7 Home Professional for these purposes.


For several years, I have used a very powerful and easy-to-use Microsoft Windows screen capture application called MWSnap. Windows 7 does include a built-in screen capture utility, but it is extremely simple and lacks many of the functions that can be found in the basic MWSnap application. The most significant function is the file naming capability. MWSnap allows the use of variables for date and time allowing you to automatically time-stamp the image file. The application also allows you to automatically save the image that you capture. The very best thing about the MWSnap application? It's freeware with donations accepted. Wow! With these features, we were halfway there.

Now we needed a way to automate the screen capture process. Enter the wonderful Windows freeware utility, AutoHotkey. This handy application allows the user to create a script of keyboard and mouse commands along with a powerful set of logic controls to automate almost any process on a Microsoft Windows computer. Although the application has an extremely robust set of features, we only required a relatively simple set of keyboard commands. Through trial and error, we found the biggest trick was to include several pauses to provide Windows or the subject web site sufficient time to respond to the AutoHotkey commands; a simple, but important point for you to remember.

AutoHotkey allows you to create a command script in a text file. Then when you select that script from File Explorer, the application will begin the execution of your custom AutoHotkey commands. For our purposes, we needed to perform a few different tasks. The Adobe SVG plug-in on our subject web site was set to automatically refresh the graphic image every five minutes. However, we found that this process appeared to stop on its own after an hour or two. We decided the best thing was to force a browser screen refresh; launch MWSnap; send the keyboard commands to MWSnap to select and capture the browser screen image (automatically saving the image file with a date and time stamp); and then close MWSnap and patiently wait five minutes to begin the process over again. We included a loop to execute this set of commands for a certain number of hours.

The AutoHotkey script file that we used was very similar to this:

; Pause 5 seconds before starting.
; This will give you time to close the File Explorer window and
; place your mouse pointer in the window that you want captured.
    Sleep, 5000
; Loop ( 36 hours = 432 interations )
    Loop, 432
    {
; Refresh the browser window
    Send, {F5}
; Pause 10 seconds ( 1 second = 1,000 )
    Sleep, 10000
; Page down to view the desired image
    Send, {PGDN}
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Open the MWSnap application
    Send, {LWIN}
    Send, mwsnap {ENTER}
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Select image in browser window
    Send, {ALT}
    Send, c
    Send, w
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Capture image and autosave according to MWSnap settings
    Send, {ENTER}
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Close the MWSnap application
    Send, {ALT}
    Send, f
    Send, x
; Pause ( 5 minutes = 300,000, but subtratct the time spent pausing in the script )
    Sleep, 270000
    }

You may find the AutoHotkey script commands very intuitive. If not, a quick read of the well-written documentation in the help file will quickly get you on your way to writing your own command scripts.

After testing the script a few times, it was simply a matter of navigating to the subject web site, firing-off the AutoHotkey script and letting MWSnap capture the images as planned. In the case of my script, 36 hours later I had all of the images that I wanted.

At this point I copied the image files to my Mac Pro to be imported into iPhoto, and then into iMovie where the images were easily assembled into a MPEG-4 video with informative title slides and smooth transitions. I assume that Microsoft Windows Live MovieMaker has similar capabilities, but it is an application that I have not used for many years. If MovieMaker doesn't meet your needs, there are a number of third-party applications that allow you to create a slideshow from a collection of images. Google Picasa is one that I have used in the past. However, it is limited on capabilities for titles, transitions and slideshow speed control.

The finished product from my efforts is presented below. The process was simple enough (and rather fun) that I have a number of new ideas for other time-lapse, screen capture projects. I hope that this short tutorial provides you with some helpful information so that you can create your own time-lapse video. Good luck with your project!

No comments:

Post a Comment