Page 1 of 1

Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 10:05 am
by machinebacon
The following instructions turn your computer with webcam to a poor man's surveillance system. If you are planning to go on holidays, if you don't trust the neighbors or family members, or if you want to know who cums on your toothbrush while you are at work -- these are all use-cases for you!

CASE 1: Holidays! I am not at home but I want to know who steals my underwear :(

You will be able to log in to dropbox and see the images there.

1) You need a computer -- I use a RasPi -- and a webcam that is actually detected by the device. Usually, most of them will work well.
2) Install 'cron' 'fswebcam' and 'curl' from the repos:

Code: Select all

sudo apt-get install cron fswebcam curl
3) Get yourself a Dropbox account on which the images will be uploaded: http://www.dropbox.com
4) Fetch the dropbox_uploader.sh script, make it executable (chmod a+x dropbox_uploader.sh), and if wished, move it to /usr/local/bin/dropbox_uploader.sh

Code: Select all

curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
5) Run dropbox_uploader.sh and follow the instructions. It's easy.
6) Create a directory named ~/webcam

Code: Select all

mkdir ~/webcam
7) Create /usr/local/bin/snap with following content and make it executable (chmod a+x /usr/local/bin/snap)

Code: Select all

#!/bin/bash
IMGPATH=~/webcam/
IMGNAME="$(date +\%Y\%m\%d\%H\%M).jpg"
FULLPATH=$IMGPATH$IMGNAME
fswebcam $FULLPATH
/usr/local/bin/dropbox_uploader.sh upload $FULLPATH $IMGNAME
8) Add a new crontab entry:

Code: Select all

crontab -e
at the bottom, add

Code: Select all

* * * * * /usr/local/bin/snap
for a snapshot every minute. If you want a snapshot every 5 minutes, use

Code: Select all

*/5 * * * * /usr/local/bin/snap
You don't need to worry about filling up your hard disc with stills: dropbox_uploader.sh moves the files to the server so your drive stays clean. Of course you should clean up the images folder in dropbox every now and then (for me, one image a minute produced around 6Mb of data per hour, YMMV -- you can resize fswebcam's output and also reduce the size by compressing jpg to 70% or so -- have a try first!)

CASE 2: I just want to spy on my loved ones :P

1) You need a computer -- I use a RasPi -- and a webcam that is actually detected by the device. Usually, most of them will work well.
2) Install 'cron' and 'fswebcam' from the repos:

Code: Select all

sudo apt-get install cron fswebcam
3) Create a directory named ~/webcam

Code: Select all

mkdir ~/webcam
4) Create /usr/local/bin/snap with following content and make it executable (chmod a+x /usr/local/bin/snap)

Code: Select all

#!/bin/bash
IMGPATH=~/webcam/
IMGNAME="$(date +\%Y\%m\%d\%H\%M).jpg"
FULLPATH=$IMGPATH$IMGNAME
fswebcam $FULLPATH
5) Add a new crontab entry:

Code: Select all

crontab -e
at the bottom, add

Code: Select all

* * * * * /usr/local/bin/snap
for a snapshot every minute. If you want a snapshot every 5 minutes, use

Code: Select all

*/5 * * * * /usr/local/bin/snap

Re: Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 12:07 pm
by simgin
Nice writeup Julius, someone is stealing your underwear? What fucking looser does that :S

Re: Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 12:58 pm
by dkeg
Interesting. No use case for it atm, but very cool nonetheless. Thanks for the write up.

Re: Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 2:38 pm
by machinebacon
simgin wrote:Nice writeup Julius, someone is stealing your underwear? What fucking looser does that :S
I wonder, too -- I don't even *wear* underwear!

Re: Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 3:58 pm
by pidsley
Cool! I used something similar to make a time-lapse video with my cheap webcam and rpi (taking a snap every 5 seconds, and then making a video with mencoder) -- fswebcam has a handy "loop" option.

fswebcam.sh:

Code: Select all

#!/bin/sh

fswebcam --loop 5 test.jpg -r 768x576 --exec ./update.sh
update.sh:

Code: Select all

#!/bin/sh

cp test.jpg "test-$(date +%s).jpg"
Running fswebcam.sh takes a snap every 5 seconds and uses update.sh to copy each snap to a time-coded file.

Then use mencoder to build a video:

Code: Select all

#!/bin/sh

mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=4/3:vbitrate=8000000 \
  -vf scale=768:576 -o timelapse.avi -mf type=jpeg:fps=24 mf://@list.txt
I started with the instructions here and made some minor modifications to the scripts.

I believe you can also make the video with ffmpeg, but I did not try that. Search the web for "time-lapse video linux".

Re: Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 4:18 pm
by machinebacon
^ Ah, that's nice, too! Thanks :)

Re: Home CCTV (Cheapo Edition)

Posted: Sun Sep 27, 2015 5:48 pm
by ivanovnegro
That is really cool.

Re: Home CCTV (Cheapo Edition)

Posted: Mon Sep 28, 2015 7:15 am
by GekkoP
Nice, I just need a webcam, but this could be useful to monitor who the hell uses my media server when I'm not at home. Thanks.

Re: Home CCTV (Cheapo Edition)

Posted: Mon Sep 28, 2015 3:49 pm
by machinebacon
Some older 'digital camera' models work fine as webcams, and if you replace fswebcam with arecord you can monitor the noise in your apartment :D

Re: Home CCTV (Cheapo Edition)

Posted: Thu Oct 01, 2015 2:02 pm
by ChefIronBelly
I need to dig out my old webcam and give this a go. thanks for sharing.

Re: Home CCTV (Cheapo Edition)

Posted: Sat Oct 10, 2015 1:23 am
by nova
This may resolve a soiled bed linen mystery. Thanks.

Re: Home CCTV (Cheapo Edition)

Posted: Sat Oct 10, 2015 9:24 am
by rhowaldt
hahaha wtf? i hope youre talking animals :D

Re: Home CCTV (Cheapo Edition)

Posted: Fri Apr 21, 2017 11:40 am
by skakos
Hi, I read twice but still unable to understand the bed linen or bedding mystery! btw new from Australia!

Re: Home CCTV (Cheapo Edition)

Posted: Fri Apr 21, 2017 6:29 pm
by ivanovnegro
Then what about an introduction in the appropriate forum thread? ;) Then we can properly welcome you.

Re: Home CCTV (Cheapo Edition)

Posted: Sun Apr 23, 2017 10:52 pm
by wuxmedia
^^ I presume Nova has had a soiled bed and would use the CCTV to find out how did it..?