A simple time-lapse photography project using the new Raspberry Pi Camera with a Raspberry Pi Model A and a battery pack.
I'd long wanted to try my hand at time-lapse photography and for one reason or another had never got round to doing anything about it, but when I was fortunate enough to be given a pre-production Raspberry Pi camera I no longer had any excuse!
Since network access was required for software configuration this was carried out using a Raspberry Pi Model B, although a Model A could have been used with a USB network adapter.
To enable support for the Camera it was necessary to add two lines to /boot/config.txt:
I planned to run the Raspberry Pi and Camera from a battery pack and in a bid to keep power consumption down I tried “underclocking” the Pi by also adding:
However, this seemed to have a negligible effect on power consumption and various reports suggest that there is little to be gained by reducing the frequency of the ARM core.
The Raspberry Pi Camera is a fixed focus 5-megapixel device of the sort used in mobile phones, and is connected to the CSI port of the Raspberry Pi via a flexible flat cable.
The Model A was used due to its lower power consumption and this was housed in a small a enclosure and the cable to the camera routed out through the hole for the RJ45 socket.
The command /opt/vc/bin/raspistill is used to capture still images and I found that with the default options this took around 6 seconds to complete.
A simple script was put together to run raspistill in a loop:
while [ true ]; do
filename=$ROLL-$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -o $SAVEDIR/$filename
Every time the Pi boots an init script reads the number stored in /var/tlcam/series and increments it by 1. The above script is then executed and captures an image every ~10 seconds.
The image file name comprises a number, determined by variable $ROLL, which makes it possible to quickly determine which boot series it is from, a hyphen and the date and time. Since the Model A doesn't have a real-time clock the date and time won't be accurate, but this doesn't really matter.
The current draw when idle was measured to be 117 milliamps, rising to around 286 milliamps when the camera was active.
Using a 3200 milliamp/hour battery pack it was calculated that this should easily give 12 hours operation.
A first run
With the script tested, power consumption measured and the battery pack charged, it was time for a first run. The Raspberry Pi and battery pack were placed on a windowsill and the camera affixed to the window with tape.
The next morning the SD card was removed and 5518 jpeg files were copied across to a laptop.
Compiling video from the still images
It turned out that the final three image files were empty and this was probably due to their contents not having been flushed out of the filesystem cache (RAM) when the battery ran out.
With the empty files deleted a list was created of the remaining 5515:
$ls *.jpg > stills.txt
The mencoder software was then used to create a HD (1080p) MPEG-4 video file for upload to YouTube:
$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
As can be seen from the video it was a pretty gloomy start to the day on Saturday morning! However, it does brighten up late afternoon, around two minutes into the video.
The camera ran for just over 15 hours and since it was the first time the battery pack had been used this may not yet be up to full capacity.
Room for improvement
There is scope for experimenting with capture frequency, and raspistill options such as:
image dimensions, e.g. setting to those that will be used in the final video
camera exposure mode, e.g. night
built-in time-lapse feature
Some of these may result in improved image quality, whereas others may help to reduce power consumption.
There is also plenty of room for experimenting with mencoder options when encoding the video, and perhaps also image processing of stills prior to this stage, e.g. using ImageMagick.
The Raspberry Pi and Camera together provide an extremely flexible platform for time-lapse photography experimentation, and in the coming months I'm certain we can expect to see all manner of fun, novel and highly creative applications!Follow
1 likeLike thisLeave a comment