Author Topic: DIY video surveillance recording system  (Read 1616 times)

jakematic

  • Guest
DIY video surveillance recording system
« on: May 12, 2010, 06:48:44 PM »
This DIY project of mine is a bit on the geek side, but fairly easy to do now that the bugs are out and the code is written.

Over the years I've looked high and low for a video surveillance system for my home. Many that fit the bill were in the $1,000+ category for starters.

One fateful day at Best Buy I ran across a display of Panasonic cameras. Wired for about $179, wireless for $279. Not being a fan of WhyFi, or spending an extra $200, two of the wired model BL-C11A's were purchased.




Cool. Setup one of them wired to a switch that was already in place, and the other one wired to an Apple AirPort Express that was laying around disused.

Pretty cool with the remote pan/tilt and audio but this webpage they put up on my home network was lacking a lot.




Now to scour the web for recording software. $400? You've got to be kidding me. Hrmmm, there is already a Linux 'server' with Apache running on my network.

OK, now this was getting exciting. Turns out the motion and piezoelectric sensors buffer frames to be viewed later. Voila! There is a way to save the data too.

After fiddling with the settings a little, now the cameras ftp those pictures to my web server.

Now what? A bunch of pictures. Aha - lets use the Unix utility convert to turn them into an animated GIF file and use the camera setting to trigger Apache to run a script.




The script simply looks for jpg files in a landing space, converts them, and moves them off to an archive.
Code: [Select]

#!/bin/bash
#---------------------------------------------------------------
# Loop.cgi
#   Script to capture surveillance camer input and convert
#   it to animated GIF, cleanup transferred frames.
#   $1 is the camera number
#---------------------------------------------------------------
Eye=$1
Dir="/storage/storage/Fedora/Eye${Eye}"
Out="/storage/storage/Fedora/Eyes"
Now=$(/bin/date +%Y_%m_%d_%H%M%S)
Num=$(ps -ef | grep "var/www/cgi-bin/Loop.cgi ${Eye}" | grep -v grep | wc -l)
if [ ${Num} -gt 2 ]
then
/bin/sleep 1
else
        # Sleep if another Loop is running for this camera so we don't step on each other
/bin/sleep 60
if [ ! -z "$(ls ${Dir}/*.jpg 2>/dev/null)" ]
then
/usr/bin/convert -delay 50 -loop 0 ${Dir}/*.jpg ${Out}/Eye${Eye}_${Now}_Loop.gif
/bin/mv ${Dir}/*.jpg ${Dir}/archive/
fi
fi

So now I can watch loops of the captures that are triggered by motion or body heat in front of the camera. Also wrote a cron job to delete files older than a month.

Taking this to the next logical step, I wrote a script that generates an html file on the server with other useful data such as weather forecast, my weather stations data, camera displays, and other goodies. This runs in a browser on my laptop and gives me a live streaming view of the cameras in my office or anywhere else.

The html for the live cameras is super simple
Code: [Select]
<img src="http://192.168.0.210/nphMotionJpeg?Resolution=320x240&Quality=Standard"  align="left">
With very low wattage lights on a timer they even work well at night. Noise in the living room after bedtime? Just pull up a browser and the apropos home defense item ;D




I started this setup about 2 years ago and fine tuned it ever since. The next step is setting up an away mode. When I'm out of the house working or on vacation, the system could easily email a copy of the loop to my cell and text me when it is triggered.

Hopefully someone else here may be able to make use of a setup like this. I'm into it for under $400 and a little coding, and am sure many of you could do the same. Feel free to use the code samples provided.

 The camera's are still around on Amazon for about $150 and there are newer versions available for about the same price.

It may not be the best or cheapest way to do this, but it was a fun project and works well. The number of cameras can be easily expanded and outdoor models are available.

The first thing I do after getting home from a business trip, after opening a beer, is to review the video to see what's been going on while I was away.

If you have any questions, or ideas let me know.



Offline Docwatmo

  • May Ignite Spontaneously
  • Administrator
  • Survival Veteran
  • *******
  • Posts: 6601
  • Karma: 152
  • The Prepper Rising from the Ashes
Re: DIY video surveillance recording system
« Reply #1 on: May 12, 2010, 07:29:21 PM »
Well Done.  I working on a linux server project to build my own little multi camera DVR for home.  This gives me some ideas.  Particularly the compilation of stills to video.  Much more efficient and less space/resource intensive than true video (not to mention cheaper than all that software out there for the job).   

Thanks and great job.

Doc

Docwatmo

 
Father of 3 wonderfull little men, and lucky husband to an amazing woman. 
"Courage is being scared to death - but saddling up anyway." John Wayne
"Don't prepare for everything, prepare for anything." Doc 
"Gods Speed, Jenkins, Gods Speed" - Nafterize

Mark II, Mod 3, gas operated, self lubricating Inflatable Goat type 1
Ever watchful for the deadly Blue Winged Pecker Snapple
http://averageguyreviews.wordpress.com

Offline fritz_monroe

  • The Defenestrator
  • Global Moderator
  • Survival Veteran
  • ******
  • Posts: 6959
  • Karma: 116
    • The Homestead Fritz
Re: DIY video surveillance recording system
« Reply #2 on: May 12, 2010, 08:43:18 PM »
Very cool.  Thanks for posting this.  It really appeals to the geek in me.
F_M
Check out my blogs at The Homestead Fritz and Camping With Fritz

jakematic

  • Guest
Re: DIY video surveillance recording system
« Reply #3 on: May 12, 2010, 09:52:16 PM »
Thanks Doc and fritz.

If you setup your own let me know how it works and feel free to bounce ideas around.

One thing that should have been mentioned is turning off the activity light on the cameras. It's good for testing initially, but the last thing I want to do is alert an intruder they are on video.

-Jake

jakematic

  • Guest
Re: DIY video surveillance recording system
« Reply #4 on: May 13, 2010, 03:03:55 PM »
Update:

After some testing of emailing the video to myself I decided to change the format to MPEG-4.

Testing on the same input, the GIF file was 3.3M and the MP4 was 87K.

Current Loop.cgi code follows. It required symlinks for the input to ffmpeg to be in numerical order. Didn't feel like fighting it.

Code: [Select]
#!/bin/bash
Eye=$1
Dir="/storage/storage/Fedora/Eye${Eye}"
Out="/storage/storage/Fedora/Eyes"
Now=$(/bin/date +%Y_%m_%d_%H%M%S)
Num=$(ps -ef | grep "var/www/cgi-bin/Loop.cgi ${Eye}" | grep -v grep | wc -l)
if [ ${Num} -gt 2 ]
then
/bin/sleep 1
else
/bin/sleep 60
if [ ! -z "$(ls ${Dir}/*.jpg 2>/dev/null)" ]
then
# /usr/bin/convert -delay 50 -loop 0 ${Dir}/*.jpg ${Out}/Eye${Eye}_${Now}_Loop.gif

x=1
for i in ${Dir}/*jpg
do
counter=$(printf %04d $x)
/bin/ln "$i" ${Dir}/img"${counter}".jpg
x=$(($x+1))
done
/usr/bin/ffmpeg -r 5 -b 1800 -i ${Dir}/img%04d.jpg ${Out}/Eye${Eye}_${Now}_Loop.mp4
/bin/rm -f ${Dir}/img*.jpg

/bin/mv ${Dir}/*.jpg ${Dir}/archive/
fi
fi

Without spending a LOT of time on sendmail I was able to use the following command to email the file to myself.
Code: [Select]
echo "$(/bin/date)" | /bin/mail -s "Video loop triggered" -a /storage/storage/Fedora/Eyes/Eye2_2010_05_13_154921_Loop.mp4 -r from@myemail.xyz to@myemail.xyz

Offline Olympic Wanderer

  • Senior Survivalist
  • ****
  • Posts: 208
  • Karma: 14
  • Not all who wander are lost. We just wish we were.
    • Olympic Wanderer
Re: DIY video surveillance recording system
« Reply #5 on: May 15, 2010, 06:45:33 PM »
NERD!!!

No, really. That's pretty sweet. Keep up the good work :D