
Snap from Office Security Cam
So, now that I’m in Morgantown – my home is too small to comfortably work on side gigs and personal projects – especially now that my family is getting bigger with the baby! I’ve been using the office space I leased out more and more. While exploring video conferencing with Matt last week, I had the thought “wouldn’t it be cool to have a security camera in the office?”. So I did just that, and it’s actually quite easy for Ubuntu linux users.
What you need:
- Ubuntu Linux ( I was using 8.04.1 at the time of installation )
- one or more USB web cameras
What you can do:
- Motion detection – record video/and or frames if there is motion.
- Snapshot intervals – take time interval snapshots regardless of motion detection.
- Live video IP stream in mjpeg format.
- Specify recorded video to be saved in your choice mpeg, avi, flv, swf format.
- When motion exists, have frames and videos draw a box around the specific motion for more obvious recognition of subtle movements ( this actually shows the shadow of the janitor near the door around 6 a.m. every morning – I wouldn’t have noticed otherwise! )
- Easily send all data to a backup server in a variety of ways – I keep it simple by saving data to my Dropbox directory, a wonderful cross-platform data syncronization and sharing utility.
Steps:
1. Plugin your webcam.
For me, the Logitech QuickCam® Pro 9000 worked right out of the box, and was only 105$.
2. Install Motion – software motion detector, and turn it on.
sudo apt-get install motion sudo motion
3. Configure Motion
Everything really works out of the box with this – but isn’t quite organized to my liking, and probably not yours either. Global configuration is located inside /etc/motion.conf ( You’ll notice there are multiple threadN.conf files in this directory – which can be used for custom configured individual cameras if you are setting up more than one ).
Note: Be sure to restart the Motion server everytime you make a configuration change.
sudo /etc/init.d/motion restart
Take a look at the files, they are well documented. Below are a few helpful configurations to get your data organized quicker:
#/etc/motion/motion.conf # Locate and draw a box around the moving object. locate on # Draws the timestamp using same options as C function strftime(3) text_right %Y-%m-%dn%T-%q # Text is placed in lower left corner text_left SECURITY CAMERA %t - Office
Organize the filesytem to save data by date, instead of all in one directory.
# File path for snapshots (jpeg or ppm) relative to target_dir snapshot_filename %Y%m%d/camera-%t/snapshots/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-snapshot # File path for motion triggered images (jpeg or ppm) relative to target_dir jpeg_filename %Y%m%d/camera-%t/motions/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-%q-motion # File path for motion triggered ffmpeg films (mpeg) relative to target_dir movie_filename %Y%m%d/camera-%t/movies/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-movie # File path for timelapse mpegs relative to target_dir timelapse_filename %Y%m%d/camera-%t/timelapses/hour-%H/camera-%t-%Y%m%d-timelapse
4. (Optional) Setup a backup solution
a. Easy solution, get and install Dropbox — instructions on the Dropbox site. Then update your motion.conf to save to your Dropbox directory:
#/etc/motion/motion.conf ... target_dir /path/to/dropbox/security_camera ...
b. A more granular solution is to take advantage of hooks configurable in motion.conf. Using these, you can create bash scripts to do anything your heart desires ( like trigger a silent alarm on motion detection outside business hours ). Available hooks: on_event_start, on_event_end, on_picture_save, on_motion_detected, on_movie_start, on_movie_end.
If you have wput installed, you can easily upload files to a remote backup server with these hooks:
#motion.conf ... on_picture_save wput ftp://user@pass@server %f ...
However, this solution is somewhat less secure, as it uses FTP. In a future post I will detail how to secure this up using encrypted transfer and phrase free keys. ( Stay tuned! )
5. Live feed
This comes working out of the box with Motion. Check out your live stream in your web browser by navigating to: http://localhost:8081
That’s it! Webcam security made easy

Digg
Disqus
Facebook
Flickr
LinkedIn
MySpace
oDesk Profile
Twitter
YouTube!
September 4th, 2009 at 6:24 pm
how to play mp3 on motion
February 6th, 2010 at 8:32 am
How can I stop motion without shutting down my computer? It keeps running even after I exit the terminal.
February 6th, 2010 at 8:39 pm
I haven't used Motion in several months now, but I would imagine you can stop the daemon via: /etc/init.d/motion stop
April 23rd, 2010 at 10:36 pm
@mickos
did you try on_motion?
April 27th, 2010 at 2:55 am
[...] on Ubuntu?Red Hat Profits SoarSony Makes A Linux ComebackUbuntu Switches Back To GoogleObviously Motion as webcam security would be vastly more attractive with a GUI. Either GTK or QT. But even without a clean UI to work [...]
June 27th, 2010 at 5:32 pm
How can I enable the text_left command?
I erase the ” ; '' the were before text_left, but it still not appear on the jpeg file
July 29th, 2010 at 11:28 pm
Thanks, very helpful tutorial.
The motion daemon dies quite silently if it can't write to its output directory. Daemon runs as user “motion”. Took a few minutes to figure that out.
August 22nd, 2010 at 10:44 pm
program that supports sending captured images to an address email?
September 4th, 2010 at 5:50 pm
i use mutt like this in my motion.conf
on_picture_save mutt -s “Test mail” -a %f email@gmail.com
September 7th, 2010 at 8:34 am
Hi, How do i setup multible cams? I have one camera working just as i like. But have another cam plugged into /dev/video1, at the moment motion is only picking up /dev/video0 unless i change the video capture to either or. I can get either working one at a time. But not both at once. I also have no thred#.conf files?
Regards
September 23rd, 2010 at 8:54 am
how to auto run motion, example script . . . . . please
October 11th, 2010 at 7:16 am
read the tutorial above? can simultaneously record sound?
bask80@gmail.com
October 27th, 2010 at 8:03 pm
did u test with multiple cams? i just tried with two different cams and it does not work. the second cam never seems to work (the second video device – /dev/videoX). both cams work alone, but not together.
November 2nd, 2010 at 10:25 pm
@Raman You need to terminate the process. In Terminal, enter ps -A and you will see motion listed with a process ID. Then type sudo kill -s SIGTERM ##### where #### = the process ID of motion.
November 23rd, 2010 at 11:26 am
Hi, I have easycap (/dev/easycap0 ) with channel, each one for each camera.
how I can configure Motion ?
best regards
Javier
December 11th, 2010 at 12:56 pm
Anyone manage to get this work with Ubuntu 10.10 and a Logitech Quickcam Pro 4000? The green led indicator on the webcam comes on when Motion is started, but no images get saved. Also, trying to stop the motion process always results in the terminal just hanging. I'm trying the daemon now with the same result : (
December 11th, 2010 at 8:27 pm
I wound up getting it to work (it works great, too!) – my problem was I had an old Hauppage WinTV PCI card in my PC and wasn't working for any app. Even though the Logitech webcam was /etc/video1 and I changed the motion.conf file to reflect that, on a hunch I just pulled the WinTV card out of my PC, rebooted, and tried Motion and it works flawlessly now.
February 16th, 2011 at 1:02 am
you have to use threads. Read a bit in the documentation about it. you'll need three files.
April 3rd, 2011 at 6:22 pm
I just set this up. There's so many options! Thanks for the intro. Now I can find out what the sneaky neighbour is up to.
April 21st, 2011 at 1:11 pm
the sample script is the init.d script. After configuring (updating the motion.conf file according to the suggestions above) you can run sudo /etc/rc.d/motion restart or /etc/init.d/motion restart to (re) start motion. Look for a motion process with ps aux | grep motion
April 22nd, 2011 at 3:48 am
Btw. works fine on arch with kernel 2.6.38-ARCH x86_64
May 12th, 2011 at 12:22 pm
I think this site copied your post: http://xtremediary.blogspot.co…
June 18th, 2011 at 2:18 am
thank you Chris! very useful and succinct explanation… just the right amt of info to get one started..
June 20th, 2011 at 11:36 am
[...] Here is a good tutorial show you how to Setup a webcam security system with Ubuntu and Motion: [...]
June 26th, 2011 at 10:54 am
It works quite nicely but i can't seem to get the live feed over the internet. On the local network it works fine, but outside that it never connects. I've set my router to forward port 8081 to my laptop (just testing with the on-board webcam at the moment), but nothing. Must be a setting somewhere i've missed.
June 28th, 2011 at 5:20 am
Hi Guys
iam running ubuntu 10.04 i have ordered a “wireless network dvr 4 channel” setup on ebay as you know it only has windows drivers.
I do not find any linux drivers for this setup.
It is a usb aplication that then connects either wireless or via cable to the not sure if i can call it router.
how do i get pc to recognise this “router”?
July 17th, 2011 at 6:57 am
how do i quit in the terminal? i am trying everything and it won't stop
July 17th, 2011 at 10:57 am
how do i quit in the terminal? i am trying everything and it won't stop
September 16th, 2011 at 1:11 pm
I i’ve managed to set it up, it works great, but now i want to stream audio to.
Any ideas?
October 17th, 2011 at 11:24 am
yeah, started motion and saves lots of pics–Control C
^C[1] File of type 1 saved to: ./01-20111017081937-07.jpg
[1] Thread exiting
[1] Calling vid_close() from motion_cleanup
[1] Closing video device /dev/video0
[0] Motion terminating
October 21st, 2011 at 1:47 am
@Raman: You can stop “Motion” by pressing CTRL+C.
October 25th, 2011 at 6:56 am
@Raman: You can press Ctrl + C to stop motion
November 16th, 2011 at 8:50 pm
can someone submit an example of a motion.conf and thread1.conf
thread2.conf for multiple camera operation.
i have been trying for 3 months to get more than one camera working.
thanks greatly
November 22nd, 2011 at 3:14 am
Many thanks, this was really useful.
One quick note:
on_picture_save wput ftp://user@pass@server %f
should be:
on_picture_save wput ftp://user:pass@server %f
Some people have already mentioned, but to re-iterate motion just fails silently if you don’t have permission to write to the directory. The daemon runs as user motion so you will need to set permissions on your system correctly.
January 12th, 2012 at 5:43 am
Hello,
Can somebody please tell me where is the file in which I can setup motion start at startup of a system?
I know that there is one file where you can write option
start on boot=yes
But I forget where is it
The script was starting but failed after few hours (normaly three or four ) Did anyone maybe have the same problem?
Perhaps there is other option to start motion on boot up? Many thanks for help!!
February 22nd, 2012 at 7:27 am
Interesting piece of work! I’ve got it running in Ubuntu 10.10LTS so far without a hitch and it’s seeing two cameras from two video cards. Motion detection appears a bit strange though as though it only works on the one camera and not the other. But this is further investigation.