1. How to do a time lapse with the Raspberry Pi
1. Taking the pictures (in light or dark)
2. Compressing the pictures
3. Doing it all in one script
2. My time-lapses
1. Day-time time-lapse of my Guinea Pigs
2. Night-time time-lapse of my Guinea Pigs
3. In car battery powered time-lapse
3. Jam-lapse
What is a time-lapse?
Time-lapse is where a camera takes a sequence of images of a subject with an interval of time between each image. The interval can be anything from less than a second to a day or more. When the images are played back the interval of time is speeded up creating shorter time.
How to do a time lapse with the Raspberry Pi and camera module
1. Taking the photos:
There are two main ways to take a certain number of photos at a certain interval with a Raspberry Pi. Obviosly you need a recent version of Raspbian, and you need either camera module connected to the camera connector correctly. If you want to do this in the dark, you will have to use the Pi NoIR camera module with an infrared light source.
Option 1:
You could create a python script or a shell script that runs the raspistill command in a while loop. Here is an example python script that takes 1000 photos 6 seconds apart, with the names counting up from image0000000.jpg to image0000999.
Code: Select all
import os
import time
FRAMES = 1000
TIMEBETWEEN = 6
frameCount = 0
while frameCount < FRAMES:
imageNumber = str(frameCount).zfill(7)
os.system("raspistill -o image%s.jpg"%(imageNumber))
frameCount += 1
time.sleep(TIMEBETWEEN - 6) #Takes roughly 6 seconds to take a picture
You can also use the time-lapse command built in to the raspistill API which is very convenient and easy, which we are very lucky to have (thanks Raspberry Pi!). You type one command with a few values that you specify depending on how long you want it to last and how far apart you want them to be taking in milliseconds into a terminal and it takes the photos. Eg:
Code: Select all
raspistill -t 30000 -tl 2000 -o image%04d.jpg
Compressing the photos into a video:
There are two commands that I use to compress my photos into a time-lapse video.
This is the first command:
Code: Select all
ls *.jpg > stills.txt
This is the second command:
Code: Select all
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt
Doing it all in one script
You could put these commands that compress the photos into video, at the end of a python or shell script that takes the photos so that you only have to run one script that takes the photos and compresses them. Here is example python script that takes the photos and compresses them:
Code: Select all
import os
import time
FRAMES = 1000
TIMEBETWEEN = 6
frameCount = 0
while frameCount < FRAMES:
imageNumber = str(frameCount).zfill(7)
os.system("raspistill -o image%s.jpg"%(imageNumber))
frameCount += 1
time.sleep(TIMEBETWEEN - 6) #Takes roughly 6 seconds to[url][/url] take a picture
os.system(ls *.jpg > stills.txt)
os.system(mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt)
Daytime Guinea Pig Time Lapse: http://www.youtube.com/watch?v=yzTJ3xnY5sk
This was pretty simple. I have plenty of plug sockets in my garage, so I brought across my TV, a lamp and a micro USB 5v power supply and plugged them in. I hooked a pi up to an SD card with the latest raspbian, a normal raspberry pi camera module with the camera connector, the TV via HDMI, a keyboard via USB and the power supply. I positioned the camera module so it could see most of the enclosure (to see a constant live preview from cam module on screen, type: 'raspivid -t 0') with a mount and some tape. I then bashed in the commands spoken about previously.
Nighttime Guinea Pig Time Lapse: http://www.youtube.com/watch?v=dkheeVw_3Fc
I did this the same as above, but I did not want to keep my Guinea Pigs awake with light (specifically light that they can see). Fortunately, they make a version of the raspberry pi camera that doesn't filter out IR light. I bought this, and as it works exactly the same as the normal module, I used the same method as previously, but I used a 48 LED IR CCTV ILLUMINATOR from amazon or ebay instead of the lamp as it emits light that the Pi NoIR can see, but the Guinea Pigs can't.
In Car Time Lapse: http://www.youtube.com/watch?v=p8RxZKCX2DY
This was a bit of a nightmare. As I do not have a plug sockets in the car, I had to battery power the pi. I used a 5v USB battery pack phone charger to power the Pi. As I could not have any sort of screen in the car, I entered the commands blindly. I powered the pi (with a keyboard and camera plugged in), waited a minute or so, entered my username, entered my password, then entered the first command (raspistill) to take the photos. I could tell that I had done this correctly as the camera light flashed every 6 seconds (I wanted a photo to be taken every six seconds). After the journey, I just took the power supply away from the Pi. This was very risky, and could've ruined my sd card. Luckily it didn't, and when I was home, a hooked it up with my TV and compressed the photos.