The Raspberry Pi Camera Module: Part 5 – Slow Motion Video

The Raspberry Pi Camera Module Part 5 Slow Motion VideoShooting slow motion video with the Raspberry Pi Camera Module is dead easy

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

In order to be the next Speilberg with your £25 computer, you’ll just need the standard Raspberry Pi camera module. You’ll also need a Raspberry Pi with Raspbian set up as well, of course.

Raspberry Pi and camera module

A Raspberry Pi and a camera module is all you 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!

ProtoCam boards

My ProtoCam boards, both funded via Kickstarter

Connect and set up your camera module

I covered how to set up your camera module in the first two camera module blog posts I wrote. If you haven’t got yours attached and set up yet, take a look at Part 1 and Part 2 now.

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
install gpac

gpac will convert your raw video file into a playable format, and installing it is easy.

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.

Open your favourite text editor (I use Notepad++) and copy the code below being careful not to misspell anything along the way. Alternatively, grab a copy of the code from my PasteBin here.

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'

##### 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