STFN

How to make a timelapse with a Raspberry Pi

10 minutes

12 hours in 24 seconds.

Spring is here and it’s time to put some plants into the soil. When the seeds started to sprout I got this idea that it would be cool to record a timelapse to see how plants grow.

My fiancee and I, we now have several trays of seedlings on our windowsills, and I chose the largest one as the actor in the timelapse. The largest plants are the pumpkins, in the front there are cauliflowers, and on the right we are waiting for celery to appear. In some time, all those plants will go into the soil in our garden. In other trays we have more pumpkins, watermelons, a lot of tomatoes and bell peppers.

Going back to the topic of making timelapses, I assembled some hardware, did some searching on the intertubes, and came up with the following plan of work:

Hardware and Software

First, the hardware part.

To make the timelapse, I am using a Raspberry Pi 4b with the Camera Module 3 NoIR.

The case is the Raspberry Pi Cluster Case from PiHut to which I attached the camera with a metal l-bracket and some bolts.

For the software part, I am using Pi OS Bookworm Lite 64bit and libcamera library to control the camera. For info how to do an initial configuration the camera, refer to libcamera docs. Batch editing of the timelapse images I am doing in darktable, and the final assembly of images into a video happens in good old ffmpeg.

Running the timelapse

photo of a
Raspberry Pi 4b placed on a construction made from a table, a stool, and a
cardboard box. The Pi is leaning downwards, supported from the back by another
small cardboard box. The Pi has a camera attached, the camera is looking at a
large tray of freshly sprouted plants placed in individual pots.

I placed the Pi on a very janky construction made from stools and cardboard boxes. In the future I want to find a way to add a tripod mount to the base of the cluster case, that will save me a lot of hassle and allow for very precise positioning of the camera.

The Pi is running headless as all my other Raspberries, so I sshed into it from my PC.

First I made a few test images to check the framing, to do it quickly I ran

rpicam-still -n -o test.jpg && scp test.jpg <PC IP>:/home/<user dir>

This command takes the picture and copies it from the Pi to my computer in one go. I will talk about the different arguments in a moment. Once the framing is good, it’s time to run the actual timelapse:

rpicam-still -n --timelapse 60000 -t 0 -o capture_%05d.jpg

rpicam-still is the name of the app for taking still images. I know, nobody would have guessed that. -n means “no preview window”. We have no video output from the Pi, so there is no way to a preview window. An alternative would be to run a full desktop image of the Pi OS, and open the desktop remotely using a VNC client. But I prefer to just ssh. --timelapse 60000 defines that it should be a timelapse, 60000 is the number of microseconds between frames. 60000 microseconds is 60 seconds, so one minute between captures. -t 0 is for setting how long the timelapse should take, in microseconds. 0 means indefinitely, until you cancel the app with ctrl+c, or the Pi turns off. -o capture_%05d.jpg is about the naming of the images. %05d means 5 digits, so the first captured image will be capture_00000.jpg, the second capture_00001.jpg etc. If there was no digit placeholder defined, all timelapse images would be saved to the same file.

If the timelapse gets interrupted, and you want to continue it without breaking file numeration, the initial number of the frame can be defined with:

rpicam-still -n --timelapse 60000 --framestart 389 -t 0 -o capture_%05d.jpg 

With that, the timelapse will start with the first image saved as capture_00389.jpg

There is much more configuration available for the rpicam apps, refer to the libcamera docs for a full list.

And now the timelapse is running. Leave the Pi alone for a few hours, and occasionally check if new images are being created. You can open another ssh connection to the Pi and ls the image folder.

To copy the images from the Pi to my PC I use rsync. It ignores the files that are already copied to the destination, so I can run it from time to time to just copy the new batch.

rsync --progress capture* <PC IP>:/home/<user dir>

Preparing the files

Once the timelapse is done and the files are copied to a PC, it’s time to do some editing.

I have a Camera Module that does not have the IR filter. I bought it for astrophotography and have not used it for this means so far. So yeah, not great. Anyway, not having an IR filter means that when shooting in daylight, the colours are off. And so I needed to correct them. My timelapse turned out to be 730 images, so editing them one by one was not feasible. GIMP does not have a tool to do batch editing, so I turned to darktable.

Kudos for people in this thread for sharing how to do it.

In darktable, I imported all 730 images, and went to edit the first one. When the colours were much better I came back to the library view, and on the right, under styles, I selected create. This created a new style, a preset from the edit history of that first image. Then I selected all images with ctrl+a and double clicked on the saved style. This applied the edits to all files in one go. Then all that was left was exporting. Again in the library view, I went to export in the right hand bottom corner, changed the size to 1920x1080 and exported all images to a new folder. Editing was done, and the last part that was left was…

Creating a video

To create the video from images, I took my inspiration (meaning I copied and pasted) from this article

Here’s the command to create video from images, with my edits:

ffmpeg -framerate 30 -pattern_type glob -i "*.jpg" -s:v 1920x1080 -c:v libx264 -crf 17 -pix_fmt yuv420p my-timelapse.mp4

And that’s it! The timelapse is done! Finally, to embed the video here on my blog I used video.js

Thanks for reading! Spring is coming so in the upcoming weeks there probably will be more posts about gardening and other outdoor stuff, and less about tinkering with computers and solder. I’ve been having some doubts whether this blog should be computers-only, or should it just be about anything I do and find worthwhile sharing. For now I am leaning towards option 2, but I would love to hear your feedback on it. Thanks fo reading! Please leave a comment or reach out to me via email or Mastodon.

and random linguistic fact: in Polish those small plants that you grow on your window sill to later put into soil are called “flance”, from German pflanzen.

If you enjoyed this post, please consider helping me make new projects by supporting me on the following crowdfunding sites: