DIY : CCTV Server with Ubuntu Server 12.04 + Motion + USB Webcam(s)

Building CCTV Server with Ubuntu Server 12.04 + Motion + USB Webcam(s)

What you need:

  1. PC with Ubuntu Server Installed
  2. PCI USB Card(s), as 1 USB Controller only capable of handling 2 USB Webcams
  3. Webcam(s). Make sure they work in linux. I have bought cheap webcams from Ebay, which are detected automatically by Ubuntu
  4. Optional : IR Illuminator
  5. WIP :  Utilizing USB RJ45 Extender

Steps:

1. Preparing Server & installing Motion

Update your server repo to the latest :

 sudo apt-get update

Install motion :

sudo apt-get install motion

2. Tweaking uvcvideo driver

sudo rmmod uvcvideo
sudo modprobe uvcvideo quirks=128

This will be reset every reboot. If this works, create the following file:

sudo pico /etc/modprobe.d/uvcvideo.conf

containing the line:

options uvcvideo quirks=128

3. Configuring Motion for multiple threads, storage location, etc

The configuration file is located at : /etc/motion/motion.conf

Suggestion : comment out the device in motion conf and configure each camera with their separate thread conf file

Make sure to add line of each thread file in the last line of the motion.conf

thread /etc/motion/camera1.conf

thread /etc/motion/camera2.conf

…..

thread /etc/motion/camera6.conf

Example content of camera1.conf ( pay attention to bold line):

root@cctv01:~# cat /etc/motion/camera1.conf
# /usr/local/etc/thread1.conf
#
# This config file was generated by motion 3.2.12

 

###########################################################
# Capture device options
############################################################

# Videodevice to be used for capturing (default /dev/video0)
# for FreeBSD default is /dev/bktr0
videodevice /dev/video2

# The video input to be used (default: 8)
# Should normally be set to 1 for video/TV cards, and 8 for USB cameras
input 8

# Draw a user defined text on the images using same options as C function strftime(3)
# Default: Not defined = no text
# Text is placed in lower left corner
text_left CAMERA 1
############################################################
# Target Directories and filenames For Images And Films
# For the options snapshot_, jpeg_, mpeg_ and timelapse_filename
# you can use conversion specifiers
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second,
# %v = event, %q = frame number, %t = thread (camera) number,
# %D = changed pixels, %N = noise level,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event
# Quotation marks round string are allowed.
############################################################

# Target base directory for pictures and films
# Recommended to use absolute patch. (Default: current working directory)
#target_dir /usr/local/apache2/htdocs/cam1
############################################################
# Live Webcam Server
############################################################

# The mini-http server listens to this port for requests (default: 0 = disabled)
webcam_port 8081

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# The filename of the picture is appended as an argument for the command.
#on_picture_save /usr/local/motion-extras/camparse1.pl

# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# Filename of movie is appended as an argument for the command.
#on_movie_end /usr/local/motion-extras/mpegparse1.pl

Test & run motion :

sudo /etc/init.d/motion start

check syslog, make sure no error. You should see something like this:

Jul 20 10:43:52 cctv01 motion: [5] Using palette YUYV (352×288) bytesperlines 704 sizeimage 202752 colorspace 00000000
Jul 20 10:43:52 cctv01 motion: [5] found control 0x00980900, “Brightness”, range 0,255
Jul 20 10:43:52 cctv01 motion: [5] #011″Brightness”, default 140, current 102
Jul 20 10:43:52 cctv01 motion: [5] found control 0x00980901, “Contrast”, range 0,127
Jul 20 10:43:52 cctv01 motion: [5] #011″Contrast”, default 36, current 36
Jul 20 10:43:52 cctv01 motion: [5] found control 0x00980902, “Saturation”, range 0,127
Jul 20 10:43:52 cctv01 motion: [5] #011″Saturation”, default 80, current 80
Jul 20 10:43:52 cctv01 motion: [5] found control 0x00980903, “Hue”, range -15,15
Jul 20 10:43:52 cctv01 motion: [5] #011″Hue”, default -3, current -3
Jul 20 10:43:52 cctv01 motion: [5] found control 0x00980910, “Gamma”, range 1,3
Jul 20 10:43:52 cctv01 motion: [5] #011″Gamma”, default 2, current 2
Jul 20 10:43:52 cctv01 motion: [5] mmap information:
Jul 20 10:43:52 cctv01 motion: [5] frames=4
Jul 20 10:43:52 cctv01 motion: [5] 0 length=202752
Jul 20 10:43:52 cctv01 motion: [5] 1 length=202752
Jul 20 10:43:52 cctv01 motion: [5] 2 length=202752
Jul 20 10:43:52 cctv01 motion: [5] 3 length=202752
Jul 20 10:43:52 cctv01 motion: [5] Resizing pre_capture buffer to 1 items
Jul 20 10:43:53 cctv01 motion: [2] Started stream webcam server in port 8082
Jul 20 10:43:53 cctv01 motion: [2] Resizing pre_capture buffer to 2 items
Jul 20 10:43:53 cctv01 motion: [6] Started stream webcam server in port 8086
Jul 20 10:43:53 cctv01 motion: [6] Resizing pre_capture buffer to 2 items
Jul 20 10:43:53 cctv01 motion: [1] Started stream webcam server in port 8081
Jul 20 10:43:53 cctv01 motion: [1] Resizing pre_capture buffer to 2 items
Jul 20 10:43:53 cctv01 motion: [5] Started stream webcam server in port 8085
Jul 20 10:43:53 cctv01 motion: [5] Resizing pre_capture buffer to 2 items
Jul 20 10:43:53 cctv01 motion: [4] Started stream webcam server in port 8084
Jul 20 10:43:53 cctv01 motion: [4] Resizing pre_capture buffer to 2 items
Jul 20 10:43:53 cctv01 motion: [3] Started stream webcam server in port 8083
Jul 20 10:43:53 cctv01 motion: [3] Resizing pre_capture buffer to 2 items

4. IR Filter Mod &  utilizing IR Illuminator

http://www.instructables.com/id/Hacked-WebCam-for-IR-Photography-and-Night-Vision/

5. Mod for outdoor usage:

http://www.instructables.com/id/Convert-a-Webcam-to-work-outdors-in-bright-light/

6. BROKEN WIP : Utilizing USB RJ45 Extender

useful links :

http://renoirsrants.blogspot.com/2011/07/multiple-webcams-on-zoneminder.html

http://adhi.widjajanto.net/blog/archives/2011/12/my_home_server.html (in bahasa Indonesia)

http://www.instructables.com/id/Hacked-WebCam-for-IR-Photography-and-Night-Vision/

http://www.instructables.com/id/Convert-a-Webcam-to-work-outdors-in-bright-light/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: