How to Make a Time Lapse Video

by SteveRoy in Circuits > Cameras

3174 Views, 4 Favorites, 0 Comments

How to Make a Time Lapse Video

LLJ Time Lapse May 5th and 6th 2018

In this Instructable I will detail the steps I use to make a time lapse video. The system and hardware I use for obtaining the images is a Linux computer and a network based IP camera. A script runs on the Linux computer and every x seconds polls the IP camera, grabs an image, re-sizes it, time and date stamps it and saves it to the computer hard drive. To create the video from the images I will cover two different freeware applications on a Windows PC and look at using Linux as an option.

When obtaining images you need to figure out the time between each image, or how many images per hour or day you will need to create a video that looks good and isn't too long or short.

In the case of my ice off video. I grabbed an image every 20 seconds from just before sunrise on the first day and went right through to sunset on the following day. I removed most of the night images before I processed them into the video, but decided to keep a "moon rise"

This leaves me with around 4,430 images. If I produce the video using 25 frames per second, the length will be:

4,430 / 25 = 177.2 seconds long. 177.2 seconds is nearly 3 minutes.

If you were wanting to capture something like a house being built, then every 3 to 5 minutes would be a good place to start.

Depending on how often and for how long I need to capture images, I use one for two different methods.

Images From an IP Camera

loop_script.jpg
timelapse_script.jpg

Most IP cameras used in either video surveillance or for full motion webcams allow you go view a still jpg image via a web browser. These IP cameras therefore have built-in web servers and we will use this to capture the still jpg image. For example with a Ubiquiti camera you can view an image via:

"http://<ip_address>/snap.jpeg"

For a Planet camera:

"http://<ip_address>/image.cgi?resolution=1920x1080"

You will need to google the url to use for your brand of camera.

Both the Ubiquiti and Planet images I grab are 1920x1080 in size (default for each camera as they are 1080 cameras). With this size you end up with a huge amount of data and a huge video file. I like to re-size the image as I grab it and write it to disk and I will show this step in my script. I use convert which is a part of the ImageMagick tools.

Capturing Images - Method 1

get.iceoff.jpg
ls.JPG

I use this method to capture shorter events like ice-off. You could use this method to capture something like a move in and setup of an event - something taking a few hours or 1 or 2 days and where you can remove any unwanted images like night time manually before processing into a video

Under Linux, a script for my Ubiquiti camera looks like this:


#!/bin/bash

# go to correct folder

cd /home/steve/iceoff

# Ubiquiti - ubnt camera

URL="http://192.168.2.114/snap.jpeg"

# where to write images

ubnt_dir=/home/steve/iceoff/ubnt

# delay between images

delay=20

# the loop

while true do

# use the time/date to stamp file name - this needs to be in the loop section

now=$(/bin/date '+%Y%m%d%H%M%S')

# get the image and write it as ubnt.jpg

/usr/bin/wget -q -O "$ubnt_dir/ubnt.jpg" -t 1 $URL

# re-size the ubnt.jpg image and write it to disk using date/time format for file name

convert -geometry 1024x "$ubnt_dir/ubnt.jpg" "$ubnt_dir/${now}.jpg"

# sleep for the delay time then get another image

/bin/sleep "$delay"

done

What the script does:

set a variable URL to where the image is on the network/camera

set the variable ubnt_dir to where we want to save images (you will need to create the directory before running the script)

set the variable delay to how many seconds between images - this makes it easy to change the time between images, just change this variable and re-run the script

start a loop with while true do - this loops should go until you stop the script with a ctrl-c

set the variable now as the year,month,day,hour,second

Feb 16th 2019 at 8 minutes and 29 seconds after 1pm would look like 20190216130829

use wget to grab an image from the URL and write it as ubnt.jpg in our image folder

convert the image ubnt.jpg (resize it) to 1024 pixels wide keeping the ratio correct, and write the output image to our image folder and rename it as date/time. e.g. 20190216130829.jpg

sleep for the number of seconds in the delay variable

go back and start at the while true do step

To run this script I login to my account and run it from the terminal - so this is good for capturing something like the iceoff of a lake - it's done in a day or two and I need an image every 20 seconds.

Capturing Images - Method 2

get.ubnt.jpg

For longer time lapses like the construction of a building or a year long time lapse project I use a different way of capturing images. For this I use cron.

Cron is a utility that runs a command once every x minutes, hours, days or months. So you can tailor when the command runs by minute, hour, day, day of month etc. A user in a Linux system can have their own cron job and it's kept in their crontab file.

For a time lapse that goes for months where I get an image every X minutes I use a cron job and a slightly different script in that it doesn't require a loop (the while true do and done) since cron will call the script every X number minutes.

Not only can you use it to run the script every X minutes, but you can restrict it to run between certain hours so you don't have to remove a lot of night images. As the season and daylight hours change I change my cron job to reflect it.

To create a cron job login to your Linux server and run: crontab -e This will start an edit of your crontab. My crontab file has a line like this:

*/5 4-23 * * * /home/steve/timelapse/get.ubnt >/dev/null 2>&1

The */5 means run every 5 minutes

The 4-23 means run it from 4am to 11pm (this changes with the season for me)

The first * means run it every day of the month

The second * means run it every month of the year

The third * means run it every day of the week

/home/steve/timelapse/get.ubnt is the script name that runs

>/dev/null 2>&1 means put standard output to null and any errors to null - if you don't have this then you will get email each time the cron job runs.

My script /usr/steve/timelapse/get.ubnt looks like this:

#!/bin/bash

cd /home/steve/timelapse

URL="http://192.168.2.114/snap.jpeg"

now=$(/bin/date '+%Y%m%d%H%M%S')

/usr/bin/wget -q -O ubnt.jpg -t 1 $URL

convert -geometry 1024x ubnt.jpg ${now}.jpg

What this script does:

change to /home/steve/timelapse

set a variable URL to where the image is on the network/camera

set the variable now to year, month, day, hour, minute, second (so we can time/date stamp the final jpg image later)

get the image from URL and write it out to ubnt.jpg

resize the image to 1024 pixels wide keeping the correct ratio and write the file as a date/time stamp.

As with the previous method/script his will make the file names sequential and enable us to create the video with the frames in the correct sequence. After I have a few days worth of images I will copy them to a folder on my Windows PC to create the video file. I normally use ftp to get the files on the the windows PC as they are on the same network and the login/pasword being clear text isn't visible on the Internet.

Copy the Images to a Windows PC

To copy the images from the Linux system to a windows PC for processing into a video I use FTP.

The windows program I use for this is FileZilla Client. You could use any ftp client you prefer, even the command line version in windows.

If you know what you are doing you could also use Samba or NFS and have the Linux files appear as a folder in Windows.

Creating the Video - Photolapse 3

photolapse_step_1.jpg
photolapse_step_2.jpg
photolapse_step_3.jpg
photolapse_step_4.jpg
photolapse_step_5.jpg

Now that we have the images, we need to stitch them together to create a video file.

There are many programs that you can use to do this and you may want to experiment with different programs.

However for a relatively small number of images like I capture during the one or two days of ice off I use the windows program Photolapse 3 - which unfortunately isn't being updated anymore and I can no longer find the original website for it. However it is available from a number of "download" sites though. A quick google search should fine one.

What is/was nice about this program is that it is a single binary, so there is no install. Just download the binary and run it. The downside is that it won't process a huge number of files. By huge I mean probably 20 thousand or more, but for something like my ice off video with approx 5,000 images it's just fine.

You start the program, in the top left box drill down or find where your images are stored, then put in the number of framers per second (a smaller number will make the video appear as slow motion). Next click the button "Load files from current folder"

Photolapse will load and preview each frame and you will get an idea on what the video will look like.

When it has finished processing the entire folder, click on the "Create Movie" button, change the file name if you want, then click "Save".

Next you need to choose a compression method for the video or leave it uncompressed. I use "Microsoft Video 1". All that's left is to click "OK"

Though you will need to go through all the steps again to choose a different compression method or codec, it's worth trying different settings here if you need the video compressed.

The images I used for the screen captures in this step were some from the original ice off images. I used 1191 images of 1024x576 pixels. They took up approx 110MB of disk space. The compressed video was 235MB in size and the uncompressed was 1.96 GB

Creating the Video - VirtualDub

virtualdub1.jpg
virtualdub2.jpg
virtualdub3.jpg
virtualdub4.JPG
virtualdub5.jpg
virtualdub6.JPG

The other program I have used is VirtualDub

Download the zip files here. There is a 32-bit and 64-bit version

Unzip the files into their own folder.

One of the things you will need to do with your images is to sequentially re-number them. Using the date/time stamp file names like my scripts create will not work with VirtualDub. There are a couple of ways to renumber the files:

First, make a backup of your files, then another backup. Then using the second copy:

Open the folder with the images, change the view to "details", highlight the first file on the list, press ctrl-a to select all files, right click and select "rename". Change the file name to 1 then hit enter.

This will process the list of files and append (1).jpg, then (2).jpg etc etc to the file name of 1.jpg

The second way is to use a program called Irfanview. It has a batch mode where you can rename the files sequentially as 1.jpg, 2.jpg, 3.jpg etc. The batch mode also allows you to batch re-size the images to a smaller size if needed.

Once the files are renamed, start VirtualDub, click "file" then "open video file". Select the first jpg in your sequence and then click "Open". This will load all the files sequentially numbered.

Click "Video" then "Frame Rate" change this to 30 (or whatever frame rate ou want to try)

Click "Video" then "Compression" - as with photolapse 3 I used "Microsoft video 1"

To start processing the images click "File" then "Save as AVI". Name the file then click "Save"

This will start the processing and show how long it will take.

Though there are more steps in using VirtualDub, it will process more files than photolapse 3.

I have made a timelapse with over 88,000 images using VirtualDub.

Conclusion

To view the timelapse videos you can use a program like VLC or Windows's own media player.

There are many, many ways of capturing images and making a timelapse.

If you have a canon camera, there is 3rd party firmware CHDK for some models which will allow you to use the camera in intervalometer mode and take a picture every x seconds.

Experiment lots! Hope you found this Instructable interesting and if you do make a timelapse be sure to leave a link to it in the comments.