brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: rpicam-still --timelapse 2000 takes a photo every two seconds

Media
~/tips/tip-rpicam-still-timelapse

rpicam-still --timeout 30000 --timelapse 2000 -o timelapse/image%04d.jpg

Captures a numbered series of still photos at a fixed interval for a time-lapse.

A time-lapse with a Raspberry Pi camera does not need a script. The camera app has the loop built in, and the files come out numbered, ready for a video tool.

This is the command from the Raspberry Pi camera documentation:

rpicam-still --timeout 30000 --timelapse 2000 -o timelapse/image%04d.jpg

The --timeout is how long the whole run lasts in milliseconds, here 30 seconds. --timelapse is the wait between captures, also in milliseconds, so 2000 means a picture every two seconds. The %04d in the output name becomes 0000, 0001 and so on. Make the timelapse folder first, since I would not assume the app creates it.

The docs also describe -n (--nopreview) to suppress the preview window entirely, which is what you want when the Pi has no screen and runs over SSH:

rpicam-still -n --timeout 30000 --timelapse 2000 -o timelapse/image%04d.jpg

The numbering fits the ffmpeg image sequence pattern, so you can turn the stills into a clip afterwards on the same machine or on a laptop:

ffmpeg -framerate 10 -i 'timelapse/image%04d.jpg' timelapse.mp4

With 30 seconds of shooting and a picture every two seconds you get 15 pictures, which is only 1.5 seconds of film at 10 frames per second. For a real time-lapse you need a longer timeout and a smaller interval, and the arithmetic of picture count against frame rate is worth doing before you leave a camera running for an hour.

The caveat is disk space: every JPEG is a full still, and a long run adds up quickly on a small SD card. I would look at the size of one file, multiply by the number of shots, and compare that with the free space shown by df -h before I start. The command names above are the current rpicam- ones, so on an older OS image the tools may carry another name.

Further reading: Raspberry Pi documentation: camera software, ffmpeg formats documentation: image2 demuxer

More Media tips avconvert -s clip.mov -o clip-720.m4v -p Preset1280x720 avmediainfo holiday.mov ffmpeg -f lavfi -i testsrc2=size=1280×720:rate=30 \ wp media regenerate --only-missing --yes All Media tips (5) All topics

Link