Last year I wrote a short series of Raspberry Pi camera module tutorials, sharing what I’d learnt as I got to grips with the little camera board.
Between then and now, I was offered an opportunity to write a camera module article for the 31st issue of the MagPi Magazine where I shared a step-by-step guide to shooting and processing 90fps slow motion video with your Raspberry Pi.
As I like to store all my info and knowledge on this blog, I thought I’d write something similar here which will link nicely with my previous four camera module articles.
So, let’s go all movie-style ‘over the top explosion jumping through the air’ and get in to some Raspberry Pi slow motion!
What you’ll need
Optionally you could grab one of my handy ProtoCam boards to make your camera project really clean and tidy, with prototyping options as well!
Connect and set up your camera module
Install a video converter
The Pi records video into a raw h264 file which won’t work on most of the devices you’re likely to play them on. However, we can get the Pi to convert them to a playable format (MP4) straight after we’ve recorded them, in the script I’ve shared later on in this post.
To do this we install a package called gpac. In terminal, run the following commands one after the other:
sudo apt-get update sudo apt-get install gpac
Testing the camera module
Now that gpac is installed, let’s make sure everything’s working as it should by testing the camera with a couple of terminal commands.
With a screen connected, open a terminal window and type the following command:
raspistill -o test.jpg
The camera’s image should appear on screen for a short time and the image saved to your home folder. If it doesn’t work, check you typed the command correctly or turn off your Pi and re-connect the camera belt before trying again.
Create a Python script
We’ll be using Python to create our slow motion video script.
This code takes a 30 second video at 90fps, then processes the raw file for you. Cool huh?
import os import time print 'Starting programme' time.sleep(2) ##### Record the slow motion video ##### # '-w' sets the width # '-h' sets the height # '-fps' sets the frames per second (90 maximum - for slow motion) # 't' sets the time in milliseconds (30000 = 30 seconds) # '-o' sets the output filename print 'Recording started (30 seconds)' os.system("raspivid -w 640 -h 480 -fps 90 -t 30000 -o slowmotion.h264") print 'Recording complete. Please wa