loading

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

sudo nano /home/pi/record.sh

with this content

#!/bin/sh
  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.

www.emmeshop.eu

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.<br><br>Is there a way I can set a different handler like MKV or MP4 to take out the extra steps of conversion?<br><br>Also, is there a way I can view a live stream while it's recording?
<p>do you remember the coding you did? i could really use it?</p>
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.
<p>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.</p>
I pulled my old bash files that I had kept and I found one here:<br><br>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<br><br>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.<br><br>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.<br><br>Good Luck
<p>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!</p>
<p>has anybody gotten feedback about this project?</p>
<p>i have tried this a few times now and it keeps crashing on reboot.....i can't see where im going wrong</p>
<p>Will the raspberry pi automatically go to video capture mode once booted using this setup?</p>
<p>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. </p>
<p>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.</p>
<p>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! :)</p>
<p>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...</p>
<p>Instead of motion you can also use <a href="https://kerberos.io/" rel="nofollow">Kerberos.io</a>, it's also open-source and a lot more user friendly to install and configure. You can find more information on the website.</p>
<p>Hi, in order to help some people that like me have an error in the configuration is: &quot;sudo fdisk -l&quot; (with &quot;-L&quot; not &quot;-1&quot;) the guide`s creator don't explain it well. I wasted many time try it with &quot;-1&quot;</p>
<p>Hi, i tried this using an usb webcam, but nothing happens, can you help?</p>
<p>hi, i can&acute;t understand please explain the process because i can&acute;t made the pen drive instalation, i can`t undestand the process</p>
<p>You can use Kerberos.io, it's open-source and user friendly to install and configure. You can find more information on their website. </p>
<p>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!</p>
<p>is there a way to add microphone</p>
There is only a 15 minute loop?
<p>Hi, to change the recording time you can edit the file record.sh and crontab. For example, for recordings of 30 minutes, replace 890000 with 1790000 in file record.sh and * / 15 * * * * with * / 30 * * * * in the first row of the crontab</p>

About This Instructable

39,117views

193favorites

License:

More by emmeshop:Roast Coffee With Artisan and Phidgets Raspberry datalogger with Mysql Highcharts  Remote control with Raspberry Pi and Phidget WebService 
Add instructable to: