Loading DesignSpark, please wait...

We apologise for the slowness of this page You are using Internet Explorer 6, upgrading your browser will greatly enhance your experience using DesignSpark

The gateway to online resources and design support for engineers, powered by RS ComponentsAllied

Blog

Time-lapse Photography with the Raspberry Pi Camera

Posted by Andrew Back on

163023 views

title

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!

Configuring Raspbian

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.

With Raspbian installed on a 32GB SD card I went through the usual process of upgrading packages to the latest versions and upgrading the firmware.

To enable support for the Camera it was necessary to add two lines to /boot/config.txt:

start_file=start_x.elf

fixup_file=fixup_x.dat

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:

arm_freq=300

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.

Hardware setup

title

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.

title

Capture script

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:

ROLL=$(cat /var/tlcam/series)

SAVEDIR=/var/tlcam/stills

while [ true ]; do

filename=$ROLL-$(date -u +"%d%m%Y_%H%M-%S").jpg

/opt/vc/bin/raspistill -o $SAVEDIR/$filename

sleep 4;

done;

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.

Power consumption

title

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.

title

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

Results

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

  • jpeg quality

  • 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.

Conclusion

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!

Andrew Back

Build this project yourself 

Follow

27 comments

Comments

  • designspark Avatar designspark

    Posted by designspark at

    Hi Pleky

    The original Model A and B's both had 256MB SDRAM, If you're only seeing 128MB, this may be the way your Pi is set up. The ram is shared between the CPU and the GPU.

    Re Camera Mounts

    http://uk.rs-online.com/web/p/power-man ... s/7877517/

    http://uk.rs-online.com/web/p/general-p ... s/7846197/

    DesignSpark

  • pleky Avatar pleky

    Posted by pleky at

    Great blog, as someone ordered the bundle pi+camera from RS ? It is a pack with a Pi A and a camera. I would like to know if it is a old pi A with only 128mb of ram or if it is a "regular" A with 256 mb ?

    Have someone find a way to mount a basic case to a camera screw (BSW 1/4-20) ?

    Thanks for your feedback,
    Pleky

  • grassynolan Avatar grassynolan

    Posted by grassynolan at

    Andrew, great project. I have followed your lead and setup my pi using one of the metal pice cases built to contain the camera and attaches to a standard tripod. I'm running a series of pictures now to check it out. Thanks, GrassyNolan

  • daw007 Avatar daw007

    Posted by daw007 at

    FYI, there's a similar project out there called PiCamera that provides a python interface to control the camera.

    It has some code showing how to do timelapse photos in python if you're more comfortable with that then system scripts and is a little more robust.

    http://picamera.readthedocs.org

  • cottonpickers Avatar cottonpickers

    Posted by cottonpickers at

    If you need to switch your pi on at a certain time, you may be interested in my "Pi Timer" - its a 5v / usb 7 day timer originally designed for use with my Raspberry Pi Solar Battery cases, but can be used for lots of other stuff. So you could set it so that your Pi comes on off whenever you want. -Andrew - drop me a mail if you would me to send you one. Available from http://cgi.cottonpickers.plus.com/~cott ... ?f=4&t=493

  • pete wood Avatar pete wood

    Posted by pete wood at

    Hi Va-Bigfoot, We have a projects section on DesignSpark where you can seek collaborators to help you with your project, might be worth you posting your project here and ask for help, http://designshare.designspark.com/eng/

  • va-bigfoot Avatar va-bigfoot

    Posted by va-bigfoot at

    Hello everyone!

    I am new to the group and have a keen interest in the time lapse board kit. I am seeking assistance from anyone here who is interested in helping me program the time lapse board kit to take a picture every three to five seconds and save the pictures to the SD card. The time lapse camera will be used as part of an underwater surveillance system I am designing and building to hopefully document lake monsters that people have witnessed across the globe. The underwater surveillance systems will be deployed in many of the lakes where people have seen these creatures. I've used other time lapse camera systems and they work well but the costs are too high since I'm conducting this research using my own money and my funds are limited.

    The time lapse camera will be deployed in a watertight container I am building and will need to take pictures between 3 and 5 seconds, maybe more, maybe less depending on conditions such as memory card storage and battery capabilities.
    There will be other sensors to document water temperature and an audio recorder that will record audio from a hydrophone. There is plenty of room for batteries so the unit can be deployed underwater for at least a month or so without servicing it.

    If there is anyone willing to help please let me know. I can affort to donate funds or pay someone to help out but I can't affort much as most of my available funds will be needed to purchase many of the time lapse camera boards and other equipment such as the audio recorders and batteries.

    Basically I need to purchase a turn key time lapse board kit with a camera and wide angle lens and maybe a software program where I can change record time between pictures and exposure control. I have no real knowledge of electronics or programming so any help would be appreaciated. Once the first unit is tested I will purchase many, many more of them as the lakes are large and many systems would be needed to cover areas of interest. My intent is only to see if the stories of lake monsters are true and this is one way for me to live out the dreams I had when I was a child.

    Thank you and look forward to posting many pictures of sea and lake monsters.

    William Dranginis
    23891 Aldie Dam Rd.
    Aldie, VA. 20105 USA
    mobile phone number 703-919-6202

  • torna Avatar torna

    Posted by torna at

    Hello,

    Very nice article :)

    I'm just working on a very similar project : Rapsberry Pi based timelapse device running on batteries.

    I use a HD webcam with autofocus and luminosity adaptability for taking pictures. The thing is I need to run the timelapse device about 10 days with batteries :)
    I finaly figured out how to do that with an home made tempo circuit. Every thing is explained here : http://www.magdiblog.fr/category/boa-pi-timelapse/

    My blog is writen in French, but you can easily translate it using the Google language translator on the right colomn :)
    I hope you will enjoy it :) Feel free to share your ideas on comments :)

    IMG_4746-1024x768.jpg
    IMG_4746-1024x768.jpg (191.25 KiB) Not viewed yet

  • torna Avatar torna

    Posted by torna at

    Hello,

    Very nice article :)

    I'm just working on a very similar project : Rapsberry Pi based timelapse device running on batteries.

    I use a HD webcam with autofocus and luminosity adaptability for taking pictures. The thing is I need to run the timelapse device about 10 days with batteries :)
    I finaly figured out how to do that with an home made tempo circuit. Every thing is explained here : http://www.magdiblog.fr/category/boa-pi-timelapse/

    My blog is writen in French, but you can easily translate it using the Google language translator on the right colomn :)
    I hope you will enjoy it :) Feel free to share your ideas on comments :)

    IMG_4746-1024x768.jpg
    IMG_4746-1024x768.jpg (191.25 KiB) Not viewed yet

  • erik123 Avatar erik123

    Posted by erik123 at

    Nice article, thanks. But why not use:
    $ raspivid -t 600000 -o video.h264 -fps 1 (this will produce a 10 minute video @ 1 fps)
    for timelapse video? Far easier then collecting stills and merging them into a video.

  • velcrow Avatar velcrow

    Posted by velcrow at

    @ fabiant7t

    Hi Fabian, I had the same issue - I'm using solar power and a batterypack and need a timer to shutdown ( and more importantly wake up the raspberry pi when there is light). This thread was great and the person involved is now developing a timer.

    http://cgi.cottonpickers.plus.com/~cott ... =120#p1027

    Hope this helps.

    Velcrow

  • stevesquirrel Avatar stevesquirrel

    Posted by stevesquirrel at

    Great work! I have expermented with the code and done some really cool things. The one thing I really don't understand yet is the part about having the Pi start capturing when it boots. Can you give me more detailed instructions on how to create a init script and where to put it please?

  • lior Avatar lior

    Posted by lior at

    Great post, thanks for sharing.
    I recently made this project on https://github.com/LiorKirsch/timelapsePi that enables you to control and generate timelapse video on the raspberry Pi.
    You can control it using your browser (also from the mobile).
    I would love some feedback, also I would like to know if it works on the Pi camera (I used a usb webcam)

    -- Lior

  • fabiant7t Avatar fabiant7t

    Posted by fabiant7t at

    Thanks for sharing, Andrew!

    I wonder how to keep the power consumption low for a long term time lapse, when one picture per hour is sufficiant and replacing the power bank should be required only every 1 to 2 weeks. Do you know any timer component that let's the current pass in defined intervals? The raspberry pi could take a picture upon startup and shut itself down immediately after that, so that is does not need power when being idle. Unfortunately, I did not find such a thing. How would you, as a native speaker, call it?

    I tried to sketch my use case, a construction yard:

    timer.jpg
    timer.jpg (258.14 KiB) Not viewed yet


    Best,
    Fabian

  • andrew back Avatar andrew back

    Posted by andrew back at

    This has now been created as a project on the recently launched Designshare:

    http://designandmake.designspark.com/en ... tage/brief

    (see the Design stage for the scripts and instructions)

    The hope is to develop this project over time into something more flexible and robust.

    Andrew

  • mclera Avatar mclera

    Posted by mclera at

    Do you think you can use directly for the timelapse the command

    raspistill -t 60000 -tl 10000 image%d.jpg

    to take pictures every 10s for the next 60s.

    ?

  • willip5 Avatar willip5

    Posted by willip5 at

    Nice article Andrew, I have got the RPi recording the cloud formations with your instructions and a nice bit of video on YouTube.

    However I have a few problems. I cannot see how to upgrade the run counter, to keep permissions at bay I have installed things in /home/pi/tlcam, is there a script to update the counter? and where would I put it.

    I would also like to start recording at about 0530 to get some sunrise shots, any suggestions on how to do this? rather than set the alarm for 0525.

    Sorry if the questions are a bit "basic" but I will learn - I promise

    Regards
    Pete

  • britdub Avatar britdub

    Posted by britdub at

    Hello Andrew thank you for sharing your work, I new to Linux but I've worked through this as far as I can but I'n now stuck, could you please help me with a problem I'm having, when I run the script I get this error

    cat: /var/tlcam/series: Is a directory
    mmal: main: Error opening output file: /var/tlcam/stills/-27052013_1536-24.jpg
    No output file will be generated

    could it be a permission problem ?

    Thanks in advance

    Steven

  • smstext Avatar smstext

    Posted by smstext at

    hi again,i made my timelapse video with all the great help in this blog. however i was wondering one thing, how could i do the following?

    I want to time lapse say all the vapour trails left in the sky or timelapse of the traffic but merge all the pictures so say with the vapour trails i can an overall picture of all the vapour trails in the sky in one picture?

    again many thanks for an aspiring blog :)

  • sierrax Avatar sierrax

    Posted by sierrax at

    Nice manual!
    But I do not understand why you are not using parameters for raspistill in your script.

    with raspistill -? you see all possible parameters.
    -t 0 you disable the 5 second standard timeout
    -n you disable the preview


    Greets from germany

  • s0litaire Avatar s0litaire

    Posted by s0litaire at

    I'm still playing around with the script (changing image size and other values)

    Save the script text in /home/pi/ (that's what I did.)

    Make sure it's executible
    in the terminal type "sudo chmod +x <your file name goes here>" (e.g. sudo chmod +x timelapse.txt )

    Then make sure you have created the folders
    /var/tlcam/stills
    /var/tlcam/series

    Then all you need to do is type ./<name of your script> and it should start running.

    Each 1920x1080 image is around the 1.6Mb mark and you'll get around 3h30m worth of images in 1.9Gb (if you take pictures 10 seconds apart that will give you around 1260 jpg's.)

    So depending on how much room you have and how long you want to film you might want to change the "sleep 4;" value in the script to give a longer pause between images.

    sleep 24; will give images every 30 seconds. (10h 30m worth of images)
    sleep 54; will give images every 60 seconds. (21h worth of images)


    play around with the values and read the docs to see what other things you can try.

    https://github.com/raspberrypi/userland ... amDocs.odt

  • smstext Avatar smstext

    Posted by smstext at

    Hi what do I save the capture script as and which directory do I save it to? Sorry for the stupid question but I can't see where I would save it to or as what??? Many thanks and thanks for a great blog

  • mganis Avatar mganis

    Posted by mganis at

    Looks very cool. I did something similar - http://mganis.blogspot.com/2013/02/rasp ... amera.html

    I set up my Pi to take a time lapse movie of a plant bud opening and ice melting. The idea was to "wake up" every 5 minutes, turn
    on a light, snap a frame or two, then go back to sleep (and then repeat). I complied them with something called jpgvideo

    ice melting: https://www.youtube.com/watch?v=4MWl8k259bE

    Plant: https://www.youtube.com/watch?v=lF3k7W8YH3A

    --Matt Ganis

  • lstacey Avatar lstacey

    Posted by lstacey at

    This is awesome. I guess you could also set it up to do other photographic stuff like HDR...

    Fun times ahead!

  • recantha Avatar recantha

    Posted by recantha at

    Great quality time lapse. I'd done something very similar a few weeks ago with a pre-release camera but didn't really know how to use mencoder, so thanks for the pointers. http://www.recantha.co.uk/blog/?p=3201

  • tap5 Avatar tap5

    Posted by tap5 at

    Speaking of ImageMagick for post processing. When I made my first time-lapse I used the following scripts. Could be useful to someone.
    I cropped the images with +1px offset for each image so that it would look like a slow pan from left to right.

    http://www.youtube.com/watch?v=AGRX3O2jY5s

    I used a DSLR but the steps after that will be the same for a time lapse taken with the Raspberry Pi's camera board.

    This is how I made it:
    * I used a Nikon D300 and mostly open source software.
    * Set it to JPEG, manual focus, manual exposure.
    * Activated time lapse on the Nikon D300
    And the post processing:
    * Removed dust in Lightroom (if you don't have dust then obviously you can skip this step)
    * Exported the images into a little larger than full HD: 1920+number of frames=2320 x 1080.
    Ran the following shell scripts:


    #echo "Copying files into generator-friendly filenames..."
    mkdir -p originals_in_order
    x=1;for i in *.jpg; do counter=$(printf %04d $x); ln "$i" originals_in_order/img"$counter".jpg; x=$(($x+1)); done

    echo "Blending images..."
    mkdir -p blend
    cd originals_in_order
    x=1;for i in *.jpg; do counter=$(printf %04d $x);counter2=$(printf %04d $(($x+1))); convert "$i" img"$counter2".jpg -average ../blend/img"$counter".jpg; x=$(($x+1)); done
    cd ..

    echo "WARNING: Assuming files are already resized into 1920x1275!"
    echo "Cropping files into 1080p..."
    mkdir -p crop

    x=1;for i in blend/*.jpg; do counter=$(printf %04d $x); convert -crop 1920x1080+"$x" "$i" crop/img"$counter".jpg; x=$(($x+1)); done

  • pete wood Avatar pete wood

    Posted by pete wood at

    Great blog Andrew! A selection of RS battery packs for the Raspberry Pi should be on sale at RS by the end of May 2103, I'll post the details as soon as I have the part numbers.

Leave a comment