13 Dec 2014

Stand alone video surveillance system with Raspberry Pi

Submitted by Max

This tutorial describes how to build a stand alone video surveillance system based on Raspberry Pi.

We will use a Raspberry Pi Camera that continuously record the video on a usb flash drive. This creates video files of 15 minutes continuously. Periodically, the oldest files are deleted to free space.

To watch the recording just extract the pen drive and connect it to the computer.

You need:

a Raspberry Pi B or B+, with the latest version of Raspbian, or our MIcroSD Card 8GB Class 10 Raspbian preinstalled.

a Raspberry Pi Camera Board or a Raspberry Pi NoIR Camera Board - Infrared-sensitive Camera

a Raspberry Pi Camera enclosure

a pen drive with sufficient space, with the settings in this tutorial one hour of recording takes up about 1 GB.


Connect the Camera module as shown in the video below




Enabling the camera, from terminal type

sudo raspi-config

Select Enable camera and hit Enter, then go to Finish and you'll be prompted to reboot.

Raspberry Pi enable camera


Plug in the pen drive, then type

sudo fdisk -l

this reveals that our drive is located at /dev/sda1

Raspberry Pi check fdisk

Mount the pen drive with

sudo mount /dev/sda1 /mnt

To mount the pen drive on boot edit the /etc/fstab file

sudo nano /etc/fstab

and add the following line

/dev/sda1       /mnt            vfat    defaults          0       0

Raspberry Pi fstab file

Change the permission to /mnt with the command

sudo chmod -R 0775 /mnt

Create a folder to store the video files

sudo mkdir /mnt/video


There are many software to use the camera, we will use raspivid that is already included in raspbian and enables video capture with ease.

Create a new file, record.sh,  that will execute raspivid every 15 minutes

sudo nano /home/pi/record.sh

with this content

now=$(date +%d%m%Y-%H%M%S).h264
raspivid -o /mnt/video/$now -t 890000 -w 800 -h 600

When it runs, it starts recording on an output file with the current date, for 890 seconds (a little less than 15 minutes to avoid overlap), with dimensions 800x600

To start recording every 15 minutes use crontab, then type

crontab -e

and add this lines at the end

*/15 * * * * sudo sh /home/pi/record.sh  >> /home/pi/video.log 2>&1
* */1 * * * sudo find /mnt/video/* -mmin +360 -exec rm -f {} \; >> /home/pi/video.log 2>&1

The first line executes the record.sh file every 15 minutes, the second line delete files older than 360 minutes (6 hours).

Save and reboot, your mini dvr is ready.

Raspberry Pi mini dvr

This is made with Raspberry Pi NoIR Camera Board - Infrared-sensitive Camera

If Raspberry is connected to the network you can access the video files, even remotely, eg with winscp, otherwise you need to remove the pen drive for watching videos.

Obviously if your Raspberry is not connected to the network you will need an rtc module.

Follow us on social to stay informed.