Creating Timelapse Videos With The Raspberry Pi Camera


In this post I will explain how I made some timelapse videos using the Raspberry Pi camera module. This is a two step process which involves getting the camera module to take a series of stills over a period of time and then combining them into an MP4 video file.

We can use the “raspistill” utility to take a set of time lapsed photos as described in my Taking Hi-Res Photos With The Pi Camera Module article. Make sure you have installed the camera and updated your operating system.

Step 1 – Taking the time-lapsed photos

This command will take a photo every 60 seconds (60000 milliseconds) for 2 hours (7200000 milliseconds) resulting in a sequence of 120 images.

raspistill -o myimage_%04d.jpg -tl 60000 -t 7200000

The “%04d” will result in a four digit number appearing in each filename.


Step 2 – Combine images into MP4 video

Once you’ve got your image sequence you will need a method to stitch them together. I decided to use “avconv”. You can install this useful library with the following command :

sudo apt-get -y install libav-tools

To construct the video file from your image sequence you use the command shown below. Although it appears on multiple lines for readability it should be entered as a single line on the command line :

avconv -r 10 -i myimage_%04d.jpg 
       -r 10 -vcodec libx264 -crf 20 -g 15

The video will be the full resolution of the default image size (2592×1944).

To crop the images and create a more standard 1280×720 resolution video you can use the following command :

avconv -r 10 -i timelapse_%04d.jpg
       -r 10 -vcodec libx264 -crf 20 -g 15
       -vf crop=2592:1458,scale=1280:720

The “vf” option defines a video filter. In this case two filters which crop the incoming image to 2592×1458 and then scale them to 1280×720.

The “r” option tells avconv to create a video with a frames per second of 10. It appears twice to prevent avconv dropping frames that it thinks are similar.

The “crf” option tells avconv to aim for a quality level of “20” which is a good starting point. Lowers values are better but will increase the file size.

The “-g” option sets the GOP value. The YouTube Advanced Encoding Settings page recommends that the GOP should be set to half the frame rate so this is set to 15.

The conversion process is very slow on the Pi compared to doing the same thing on a desktop PC. For long sequences with hundreds of frames I would recommend downloading an appropriate version of Libav on your desktop or laptop and build your MP4 files much faster!


Here is a quick-n-dirty timelapse video I took out the window of my man-cave. It consists of 600 frames which were taken at a rate of 1 per minute for 10 hours. Nothing much happened in those 10 hours but it proved the Pi could do the job and that avconv could create the MP4. I got a PC to do the hard work!

When I’ve got the time I am going to make some more interesting timelapse videos. But that is for another day. Hopefully with better weather …



  1. Nice work. I’ve set a PiCam to shoot a time-lapse of our garden once every ten minutes for a week. It’s got 2 days left to run. It won’t be spectacular, but it’s all fun. I’ve seen some good ones in town centre type environments.

  2. You were not kidding about the Pi taking a ton of time to take the .jpg and construct a video file. I echo the sentiment that taking the .jpg to .mp4 is best done on a different machine than the Pi. Sure you can do it on the Pi, but it takes a long long time! Nice write-up, thanks for sharing!

  3. I just did something very similar on a desktop Linux system, using a Python script to capture images from multiple cameras – but instead of creating a bunch of individual jpeg files, I appended them together as they were captured to create a crude mjpeg file that can also be converted to mp4 using avconv. As a bonus, the Python script also adds a timestamp to each captured image. The script could be easily converted to use the raspistill tool instead of network cameras, if anyone is interested.

  4. not to worry found them, the only problem I seem to have is the first 5 jpgs are fine but after that the file size is 0

    any ideas as to why ?

    thank you


  5. I’m having problems running this command. Can you help me?

    pi@raspberrypi /home $ raspistill -o myimage_%04d.jpg -tl 2000 -t 10000
    mmal: main: Error opening output file: myimage_0001.jpg~
    No output file will be generated

    mmal: main: Error opening output file: myimage_0002.jpg~
    No output file will be generated

    mmal: main: Error opening output file: myimage_0003.jpg~
    No output file will be generated

    mmal: main: Error opening output file: myimage_0004.jpg~
    No output file will be generated

    • You must have write permissions to the directory where you are creating the image.jpg file. If you log in as “Pi” and run the command straight away you should be ok.

  6. Graham Easton on

    RE Pi timelapse
    I have the images on the sd card in a file in my home directory but I want to edit them in a video editing package on a PC. I understand that I can export the file containing the images to the PC but having now spent two days looking around I am still can not find how as the file does not show up on the SD card.
    Any guidance would be appreciated

    Many thanks in advance

  7. I have write permissions. Typed in the code as above. Get error message.
    At least one output file must be specified . How is this done?

  8. LE PONNER Sébastien on

    Un grand merci a son auteur pour ce tutorial…. Tout est clair et précis malgré la barrière de la langue…. Cela m’a été d’une aide précieuse…. Encore merci!!!!!

  9. Hey,

    I am having trouble running the cmd – Get error “No Such file or directory” every time.
    All my files are names:


    I am trying the following code:

    avconv -r 10 -i %8d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 timelapse.mp4

    avconv version 0.8.10-6:0.8.10-1+rpi1, Copyright (c) 2000-2013 the Libav developers
    built on Mar 22 2014 02:13:15 with gcc 4.6.3
    %8d.jpg: No such file or directory

    Do I need to have a name like “photo_” at the start of each file? I thought %8d would have taken the first 8 digets…

    Any help is appreciated.


  10. Hi Matt,

    Sadly, still got issues. any other tricks?

    Here is what I did:

    pi@raspberrypi ~/timelapse_201404261512 $ ls
    image_00011512.jpg image_00111654.jpg image_00211835.jpg image_00312016.jpg image_00412157.jpg image_00512338.jpg image_00610210.jpg image_00710351.jpg image_00810532.jpg image_00910713.jpg
    image_00021523.jpg image_00121704.jpg image_00221845.jpg image_00322026.jpg image_00422207.jpg image_00522348.jpg image_00620220.jpg image_00720401.jpg image_00820542.jpg image_00920723.jpg
    pi@raspberrypi ~/timelapse_201404261512 $ avconv -r 10 -i image_%08d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 -vf crop=2592:1458,scale=1280:720 timelapse.mp4
    avconv version 0.8.10-6:0.8.10-1+rpi1, Copyright (c) 2000-2013 the Libav developers
    built on Mar 22 2014 02:13:15 with gcc 4.6.3
    image_%08d.jpg: No such file or directory

    pi@raspberrypi ~/timelapse_201404261512 $

  11. The timelapse works OK but the final image remains on the monitor. Unable to construct the video file because the image is there. Rebooting does not show any images on thw SD card.
    How do I get rid of the final image?

  12. I have a lad of images on my pi named 1.jpg-100.jpg. from that what code do |i need to run to make it .mp4 file

  13. I am doing a timelapse of a vessel moving from Louisiana to California. Taking pictures every 30 seconds for 24 hours. So far at day 19, everything is working fine. This includes running Foxtrot GPS in a second window to track the voyage and be able to geocode the images at the end of the trip. Just record all 2,881 images onto a thumb drive every day and have a daily look at the video. Next trip, California to Alaska!

  14. Hello, I’ve had this set up working now for a couple of months. Recently the files have been randomly created with a ~ at the end of the file name so about have of the files that are created are named a0000.jpg~. This appears to be causing problems with the avcon process as it is looking for files named a0000.jpg not a0000.jpg~. Has anyone else experienced this type of issue?

Leave A Reply