Filming long videos with the Raspberry Pi camera

I’ve been interested in trying to use the Raspberry Pi to film really long videos which can last for several days. If you set the time flag (-t) for raspivid to 0, then the camera will record until you kill the program. The command is below; note that I’m only filming at 10 frames per second and that the “-n” flag cancels video preview:

raspivid -n -fps 10 -t 0 -o $temp

I tried this, and it works… until your video file reaches 4 GB (I was also recording to an external hard drive). The reason for this in a nutshell, is that a 32 bit computer like the Raspberry Pi can only address about 4 GB of memory. So I started to Google for solutions, and I saw a few potential options, but it looked like a pain to download and recompile the rapsivid program with different settings. So I wrote a short Bash script workaround:






raspivid -n -fps 10 -t 100 -o $temp

while true; do

raspivid -fps 10 -n -t 3000000 -o $temp




This script will combine the three variables dir, type and increment into the temp variable which will become the name of the video file. The first video file (in this example) will be called “filename0.h264” and will be located in the “/media/DRIVE2” directory on my external hard drive. Once 50 minutes (or 3000000 milliseconds) of filming at 10 fps have passed, this video is ~4 GB in size. At this point, the increment variable will increase by 1 and I’ll start recording a new video called “filename1.h264”. This will continue indefinitely, until you exit the terminal.

You can save this script in a text file called (for instance) “”, which you can execute by typing “bash”. I should mention one caveat here: the Raspberry Pi camera footage takes about a second to calibrate once you start it up, so if you’re interested in writing computer vision software to analyse your footage, I’d recommend ignoring the first 1-2 seconds from each video file.

The following two tabs change content below.
Computational biology PhD candidate at the Australian National University. I love writing (both articles and software), learning more about the world around us, and beekeeping. I also write for

Latest posts by Jack Simpson (see all)

Comments are closed.