Monday 19 December 2011

Linux Motion with multiple usb webcams and ip cameras

Intended for the users of the fantastic Linux 'Motion' app with a mixture of cheap usb web cameras and IP cameras.

I asume you are up and running with one webcam but are having trouble with multiple cameras, especially the mix of webcam and IP cams.

It's all about the config files and will only cover important steps on how i managed to get all 3 cameras working.
My system saves files in a different folder for each camera and each camera can be viewed in a browser.
The motion.conf holds all the global settings for all cameras but each camera needs it's own .conf with it's individual settings.

With 3 cameras i needed the main motion.conf file and 3 thread.conf files.
So thats 4 files, motion.conf and thread1.conf thread2.conf and thread3.conf.
It all runs on my new £60 beagleboard which has the power to do all this and send me a text too.

First the location of the files, i run Ubuntu 10.04 and found the best place to put all 4 .conf files was in
/etc/motion
The files will now be found automatically by Motion without having to specifiy it when firing it up from the command line.
Make sure the files are readable by you otherwise they will be totally ignored, mine were owned by root at first so i did this.
sudo chown -R ndmaque:ndmaque /etc/motion
sudo chmod g+r /etc/motion


I commented these out in motion.conf but not totally sure if it helped, they will mostly be set in each conf file.
It's prolly ok to leave as it was but this works for me and that's how it's gonna stay for now.

;netcam_url value
;target_dir value
;webcam_port 8081
;videodevice /dev/video0

some stuff i set to make like easier
The text wasn't clear from my £5 webcams unless i did this
text_double on
I dont need any output text now it's working so start it silently, but it's best to save the PID somewhere so my script can kill it.
daemon on
process_id_file /home/ndmaque/motion/motion.pid

If you have 3 cameras we need to enable 3 thread config files at the very bottom of motion.conf.

 thread /etc/motion/thread1.conf
 thread /etc/motion/thread2.conf
 thread /etc/motion/thread3.conf
; thread /usr/local/etc/thread4.conf


The thread.conf files need very little.

thread1.conf
videodevice /dev/video0
text_left USBWebcam-1
target_dir /home/ndmaque/motion/images/webcam1
webcam_port 8081

thread2.conf
videodevice /dev/video1
text_left USBWebcam-2
target_dir /home/ndmaque/motion/images/webcam2
webcam_port 8082

thread3.conf
netcam_userpass admin:mypassword
text_left Foscam IP
netcam_url http://192.168.0.60/videostream.cgi
target_dir /home/ndmaque/motion/images/foscam
webcam_port 8083
*my cheap Foscam (like all IP Cam's) needs a user/pass to be accessed.


We're ready to rock so from the command line...
motion

The reponse confirms it found and loaded all the conf files...
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Processing config file /etc/motion/thread1.conf
[0] Processing config file /etc/motion/thread2.conf
[0] Processing config file /etc/motion/thread3.conf
[0] Motion 3.2.11 Started
[0] Motion going to daemon mode

Time to fire up the browser and have a peep
http://localhost:8081/
http://localhost:8082/
http://localhost:8083/

Yay, files are pouring into the three folders.
All i need now is a little port forwarding and i'm good to go from my Android.

Bizarely i do not intend to use the zone/motion detection alerts because even high quality cams trigger when shadows/daylight changes etc.
So i set this in the global motion.conf to make sure they never trigger
threshold 1000000

I have my Arduinos with motion, smoke, fire and other sensors which can make a better decision if i am being burgled again.
The Arduino's will trigger the BeagleBoard to send a text and run the youtube api and push the files into my account.

A really top notch home alarm system for a £60 PTZ foscam, 2 x £5 webcams, a £12 Arduino Uno and a £60 BeagleBone.
It would have cost much more but thanks to Linux, Motion, Drupal, Youtube and all the other other Open Source solutions it is very cheap.

I really hope this helps someone.
(*|*)