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.



    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest

    22 Discussions

    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?

    4 replies

    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!

    1 reply

    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.

    Can we use a USB Camera instead of the Raspberry Pi camera enclosure. And do we need the camera board or is there something else less expensive to substitute because I like your idea and i'm using it.

    I get the DIY and all... unfortunately with increasingly better systems available at increasingly affordable prices this starts to make less and less sense. Unless it's done as a learning project. Then again would be a learning limited to this experience since won't help put together something that could them become a commercial product (or at least I don't see how it could yet). Thanks for sharing! :)


    2 years ago

    can you make a Raspberry camera to take video from one or several GoPro Cameras from its Micro HDMI port pass it through the Raspberry, compress it to MPEG-4 format, and store it into a SSD or HD drive? If you can I would like to purchase several...

    Instead of motion you can also use, it's also open-source and a lot more user friendly to install and configure. You can find more information on the website.

    Hi, in order to help some people that like me have an error in the configuration is: "sudo fdisk -l" (with "-L" not "-1") the guide`s creator don't explain it well. I wasted many time try it with "-1"

    Hi, i tried this using an usb webcam, but nothing happens, can you help?

    hi, i can´t understand please explain the process because i can´t made the pen drive instalation, i can`t undestand the process

    You can use, it's open-source and user friendly to install and configure. You can find more information on their website.

    I really like this cam set up. I still can't get my network setting quite right but the video is popping right up on screen for me. The little camera module is pretty good quality. thanks for putting this here to help us newbies!