Average Ticker

The Raspberry Pi Camera Module: Part 3 – Making Time-Lapse Videos

The Raspberry Pi Camera Module: Part 3 – Making Time-Lapse VideosMy time-lapse position

In Part 1 we set up your Raspberry Pi camera module with your Pi to enable us to start taking shots. In Part 2 we went through some simple commands to take standard “out of the box” photos and videos with the camera module. 

Here in Part 3 I’ll show you how to make a clever time-lapse video using the camera module to take the pictures, and a Windows PC to compile them into a video. I’m still figuring out how to get the Pi to complete all of these tasks without the need for a PC, but I’ve come up against some bugs so will leave that for another day.

Let’s get started…

A time-lapse video is simply a large number of photos taken from the same physical position over a period of time, stitched together to make a video. This then gives the appearance of time progressing much faster than usual, and works well on things that take a long time in real life, such as sunset/sunrise, tides and retirement!
What we want to achieve here is a photo taken by the Pi every so often (say 5 seconds) over a period of time (say 2 hours) and then put these together into video file format (Avi in this example).

Setup

Ideally you will have followed the first two parts in this series, which means you’ll have your camera module hooked up and the necessary applications installed on your Pi. If not, go back now and make sure you have.

This part is actually quite simple in terms of the Pi, as we’re already set up and ready to go. We just need to alter the code we use.

Location

Now I’ve been talking about doing a beach sunset time-lapse for a while, but I haven’t taken delivery of my power bank yet (to power the Pi away from home) so for now i’m just going to use the window of my apartment to capture sundown after work on a Friday evening. I’ve taped my Pi Pod case to my window rail using a bit of masking tape…classy!

PiPod mounted

The wife loved this…


When doing yours, try and choose a scene that will change gradually over time, or that has a lot of movement. Sunsets, long journeys, busy roads etc are perfect for this.

Code

The code we use for a time-lapse shot is very similar to the command we used in Part 2 for taking regular pictures, just with a few bits added. I’ll show you what I used for a 2 hour duration, and you can change what you like to suit your needs. I think a bit of trial and error is needed here to work out what different settings will produce

I used:

 raspistill -o timelapse%04d.jpeg -tl 5000 -t 7200000  

Let’s break it down so you can see which bits you can change:

  • raspistill – this is the command to say to the Pi “we’re going to take a picture”
  • -o – this tells the Pi to save the output, rather than just giving us a preview and discarding
  • timelapse%04d.jpeg – this sets the output file names (because we’re going to take a lot of shots). ‘timelapse’ is the first part, then the ‘%04d’ is telling the Pi to save file names with a 4 figure number at the end. ‘.jpeg’ is the image file type we will use.
  • -tl 5000 – this is saying to the Pi “take a shot every 5000 milliseconds (every 5 seconds for us non-robots)
  • -t 7200000 – this is telling the Pi to do all of this over and over for 7200000 milliseconds (2 hours to you and me) and then stop.

So as you can see, there are a lot of numbers and names you can play with. 

You could change that 5000 to 2500 to take a shot every 2.5 seconds, good if you want a smoother video with more detail. The 7200000 could be changed to 3600000 to run for just 1 hour, or whatever you want. The filename could also be changed.

Got it? Great! Let’s move on…

Lights…Camera…Action!

Fire up your Pi, jump into Terminal and pump that command in. The red LED on your camera module should be lit when it’s busy. Terminal won’t do anything, it will simply sit with a clear space under the command until it has completed. 

Raspberry Pi Camera Module LED

This LED lights when the camera is in use


I set a timer for the same amount of time, to give me a heads up when it should be finishing my artistic masterpiece.

Once complete, use the following Terminal command to list the contents of the folder you added the images to.

 ls -al  


You should see a list of your images (starting with timelapse 0001) appear, alongside other files in that folder:

All good? Let’s continue…

Images Into Video

So you’ve got a load of images now (I had 1400-odd), all in name order (timelapse0001, timelapse0002 etc). So, it’s time to stitch these together and make a video.


There are a couple of methods floating around that get the Pi to make the video, however one only uses the slow processor (takes ages) and the other…I can’t get to work just yet. What can I say, i’m ‘Average Man’…

So for this tutorial we’ll be using a Windows PC to compile our shots. You need to get your files over to a Windows machine – I used Filezilla, and there’s plenty of tutorials around so I won’t cover that here. 

1. First, download VirtualDub (free):

VirtualDub [SourceForge]

2. Open up VirtualDub

VirtualDub icon


3. Go to File > Open Video File – select the first image from your timelapse. Make sure “Automatically load linked segments” is checked – this will grab all the other images for you, clever huh?
VirtualDub Open File
4. The first image will now show on screen, all big and nasty. It’s now time to set the framerate.

Go to Video > Frame Rate – I set mine to about 24fps, but have a play with different values and see what you prefer.
VirtualDub set frame rate


5. This step is optional, but probably worthwhile as the default Raspberry Pi camera shot is an impressive 2592×1944, and for things like YouTube, you don’t need all that. 

Go to Video > Filters – click ‘Add‘ and then find and click on ‘Resize‘. Press ‘OK‘ and a new box will show giving you options to resize your video. 
VirtualDub resize

 

Use the absolute setting if you know what size you’re looking for – I entered 1280 in the first box which automatically gave me 960 in the second box. 1280×960… that’ll do. 

Click ‘OK’ and it’s set.

6. The final bit of fiddling is compression. We’re saving this video as an Avi file, so we need to add compression manually. You’ll need the xvid codecs for this part, most of you will have them already – download from here if not.

Simply click on Video > Compression and select the Xvid MPEG-4 Codec and click ‘OK’.
VirtualDub Compression


7. We’re ready to make the video. You can preview your video, or walk on the wild side and just go for it. 

When you’re ready, click on File > Save as AVI – you’ll be asked where to save it, and what to call it, and then the conversion will commence. It shouldn’t take too long for a minute or 2 video (hardware dependant). A handy progress box shows to keep you informed.

Done!

If that all went as planned, you’ll get a fully working Avi file at the end of it. Here’s mine, made using the settings in this tutorial:


I hope that helped get you started on your photographic journey. I’m certainly going to have some fun with this, and will no doubt post up time-lapse videos of car journeys, ice hockey games, rotting food and the like. I think I’ll play with the settings a bit more to improve the output. Feel free to post links to your Raspberry Pi timelapse videos below in the comments section.

I will be creating a fourth part in this series to cover time-lapse outside of the home, and then a fifth post covering the slow motion function, keep an eye out for that on Twitter, or subscribe to get email updates.

Average Man

2 Comments on "The Raspberry Pi Camera Module: Part 3 – Making Time-Lapse Videos"

  1. Lawrence Sollanek | 21/09/2016 at 21:21 | Reply

    Really well done! I am about to tinker with my rpi 3 with the camera module for the first time.

    I know nothing about linux, so learning on the fly. Your site was one of the best I have seen!

    Thanks again!!

  2. Hi,

    Thanks for the tutorial.

    I have a couple of questions, can you set it so that it takes a picture every 15 mins between say 7am and 6pm Monday to Saturday either for a set amount of days or until you stop the script?

    Thanks

Leave a comment

Your email address will not be published.


*


This website uses cookies. Please visit our privacy policy page for more information. Privacy policy

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close