Sunday 20 December 2009

Ubuntu webcam & server


I Had a couple of webcams sitting around which Windoze hates - typical 80mb or larger install iles, temperamental operation and the usual "one minute it works, next it's no longer supported" stuff.


Linux uses V4L (Video for Linux) so if your camera is support and I'm amazed how many are) it's often just a case of plugging in and off you go.

A simple test program first is Cheese (sudo apt-get install heese), this grabs whatever camera you have plugged in and shows live images from it, you can edit them etc.

Another indication the camera is working is either check the lsusb command or look for a video device in /dev/videox

lsusb on mine shows.
Bus 005 Device 002: ID 05a9:0511 OmniVision Technologies, Inc. OV511 Webcam

listing the contents of /dev/video I get.
ls /dev/video*
/dev/video0

So I know by these two commands my webcam is detected anyway, its an Omnivision OV511.
Another package worth using to check is Xawtv - this shows which driver it's using, screen size etc I ran that and it shows the Omnivision driver is actually the ov519 driver.

So I now need to capture my webcam and upload it to the web....

There are several utilities including camorama (this works best with V4L2 webcams) and although had this working in mere moments I decided to use "webcam"

sudo apt-get install webcam

This installs webcam which is run from the command line (just type webcam).
First though you just need to make some pretty simple changes to it's config file (which is held in your home directory but hidden ie. has a full stop in front of the name)

sudo gedit ./webcamrc

The file has two parts, one for the Grab itself i.e size, frequency etc and another for the FTP bit.

[grab]
device = /dev/video0
text = "webcam %Y-%m-%d %H:%M:%S"
# infofile = filename
fg_red = 255
fg_green = 255
fg_blue = 255
width = 640
height = 480
delay = 60
wait = 5
input = ov519
# norm = pal
rotate = 0
top = 0
left = 0
bottom = -1
right = -1
quality = 75
trigger = 0
once = 0

[ftp]
host = upload.website.com
user = myusername
pass = mypassword
dir = Cam
file = Webcam.jpeg
tmp = uploading.jpeg
passive = 1
debug = 0
auto = 0
local = 0
ssh = 0

Now I have my webcam config file (I commented out the PAL format as I was not sure what format this camera did but it seems to work fine with that commented out).

I made a simple web page but this will dump the file into my webpage home directory in the /Cam folder and call the image Webcam.jpg

To run webcam you just open a console and type "webcam"
It shows output as it uploads to the ftp site so you can leave it like that if you want and if connection gets lost you would see connection errors.
I wanted to run it without the console being open, there are plenty of people giving help and the command is ...

webcam > /dev/null 2>&1 &


If you run this it will return the process number for webcam i.e

kevin@server:~$ webcam > /dev/null 2>&1 &
[1] 17709

run the PS command to confirm it's running

kevin@server:~$ ps
PID TTY TIME CMD
8360 pts/2 00:00:00 bash
17709 pts/2 00:00:00 webcam
17755 pts/2 00:00:00 ov511-decomp
17856 pts/2 00:00:00 ps


That's it really, it uploads every 60 seconds ( I put delay=60, the wait=5 gives the camera
5 seconds to form an image once the command is issued)
I've also used a simple Java script from http://www.ajaxcam.com/ which makes the main webpage refresh every 60 seconds as well.

if you go to the cam webpage then there is no need to click refresh, it keeps up with the image.

The Ubuntu man (manual) page for webcam is.
http://manpages.ubuntu.com/manpages/lucid/en/man1/webcam.1.html

Although it does not contain a lot I found this site to help a lot.
http://blog.mymediasystem.net/uncategorized/setting-up-webcam-on-linux/



No comments:

Post a Comment