Stand Alone Video Surveillance System With Raspberry Pi





Introduction: Stand Alone Video Surveillance System With Raspberry Pi

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.

Step 1: Installation

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

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

Step 2: Raspivid

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,, that will execute raspivid every 15 minutes

sudo nano /home/pi/

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/  >> /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 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.



    • Paper Contest 2018

      Paper Contest 2018
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.




    Working this from a scratch setup on Raspberry Pi was pretty simple. When i tried to play the files, had no luck as nothing installed would play them. Had to convert to MKV in ffmpeg to see.

    Is there a way I can set a different handler like MKV or MP4 to take out the extra steps of conversion?

    Also, is there a way I can view a live stream while it's recording?

    do you remember the coding you did? i could really use it?

    I don't. What I do remember is, converting it with handbrake was the ticket. I ran into other issues with the .mp4 being recognized and think I even tried injecting the yuv_402 option but still failed. Handbrake will be your best bet. Google and you should get the proper link.

    The format -pix_fmt yuv420p was done when I screen recorded into MKV. I have that code if you need. Sorry for the misinformation above. It's been a while since I've done that.

    I pulled my old bash files that I had kept and I found one here:

    ffmpeg -i /home/john/Parenthood\ These\ Are\ The\ Times\ We\ Live\ In.mkv -acodec libfdk_aac -b:a 128k -vcodec libx264 -preset slow -crf 22 -threads 0 /home/john/Parenthood\ These\ Are\ The\ Times\ We\ Live\ In.mp4

    You can try that. I don't remember if that was one that worked but it was in there and do remember looking at the video and accepting it because there was a whole string of others that I had converted in the bash file with same coding but different titles.

    On another note, I found too, that the speed of my computer was my biggest hindrance. Once I moved up to an i5 processor, things improved greatly.

    Good Luck

    I take it that upon the reboot this is suppose to automaticly run? or is there a line to start the recording? Very new to Pi and Linux so any help would be appreciated!

    has anybody gotten feedback about this project?

    i have tried this a few times now and it keeps crashing on reboot.....i can't see where im going wrong

    Will the raspberry pi automatically go to video capture mode once booted using this setup?

    I am brand new to these DIY projects, but I am in need of creating a system for video transmission. What is the cheapest, and most effective way? I would like to transmit is to an off site location, and have a low voltage system.