Be prepared to do a bit of work to get this set-up working as not all web cams are built equal. I am using a Logitech USB web cam (I can't remember the exact make and it is not on the device itself but see below). At the end of this article you should have a working web cam that can be used to monitor your house like a security camera or remotely monitor something. In my case I am going to set it up to watch my fish tank so that I can watch it from my office.
Finding Out What is Connected
As I can't remember exactly what make and model my web cam is it is probably best to find out before continuing. Even if you think you know the exact make and model of you web cam it can't hurt to know what the computer thinks it is. To find this out simply enter 'lsusb' (as root) and you will be give a list of the currently connected USB devices. For example:
Bus 002 Device 005: ID 046d:0840 Logitech, Inc. QuickCam Express Bus 002 Device 003: ID 0452:0051 Mitsubishi Electronics America, Inc. Integrated Hub Bus 002 Device 002: ID 0452:0050 Mitsubishi Electronics America, Inc. Diamond Pro 900u CRT Monitor Bus 002 Device 001: ID 0000:0000 Bus 001 Device 002: ID 046d:c501 Logitech, Inc. Cordless Mouse Receiver Bus 001 Device 001: ID 0000:0000
So it's a QuickCam Express. Not a terribly good web cam but good enough for what I want. The hex after the ID (eg 046d:0840 in my case) specifies the exact make and model of device. The first four digits are a manufacturer code the second four are a device code. If you have a device that doesn't have a name you can look it up here.
Installing the Required Drivers
This was quite probably the most difficult thing that I have ever done to a Linux box. The drivers have to be compiled on the machine you want to use the web cam on which is a pain. Fortunately there is a script that does most of the work for you. Unfortunately, the script isn't quite clever enough yet and needs you to hold it's hand in a couple of places.
First off, install the source for the QuickCam module. You need to install the package qc-usb-source. It is advisable at this point to install xawtv as well as it is used by the compile script to check whether your web cam is working but it is not a dependency (I presume because it isn't necessary). Once it is installed find a friendly command prompt and type (Note: you might need to be root initially to unzip and untar the package but the script complains if you are root when you run it. The solution I used was to chown the qc-usb-source directory as my normal user and run the script as me from in it):
cd /usr/src/ gunzip qc-usb-modules.tar.gz tar -xf qc-usb-modules.tar cd modules/qc-usb-source/
At this point you should have the unpacked the sources for the module. To compile the module you should now only need to enter the command:
I hit a tiny snag at this point. While checking for required software the compile script gave me the following warning:
gcc version: gcc version 3.3.5 (Debian 1:3.3.5-8) gcc version: gcc version 3.3.5 (Debian 1:3.3.5-8) Make version: GNU Make 3.80 Linker version: GNU ld version 2.15 Kernel compiler: gcc version 3.3.5 (Debian 1:3.3.5-6) [!] Kernel compiler and gcc seem to be different versions. Instead, they should be the same. If you have many compilers installed, you can specify the correct one with command (in bash) export CC=kgcc before trying to install the driver. Replace kgcc with the command required for compiling kernels (kgcc is often used in Red Hat systems). WARNING: If you press Enter, I'll try to continue anyway, but this probably will fail. You SHOULD press Ctrl+C now.
As you can see there is a tiny variation in the version number for the gcc installed and the gcc used to compile the kernel. I performed an update to make sure I had the latest versions of everything but there was still a mis-match. I decided to give it a go and see what happened lets hope that they didn't break backwards compatibility when they upgraded gcc <crosses-fingers>. If you don't have the videodev module loaded the script will attempt to load it for you and you should then see the module in the list. The script then builds the module and will finally test it. There is a chance that at this point your computer hang badly. Jot down the SysRq key combinations and make sure you have saved everything you might want to keep. In reality the chance of total failure is not that great but you never know.
... time passes - I worry about my system...
It worked. Well it didn't crash my computer at least :o). The next step is to configure the camera to use /dev/video0 as it's device but unfortunately this has failed for some reason. The script seems to be reporting that the /dev/video0 directory doesn't exist:
Testing if /dev/video0 is correct. crw-rw---- 1 root video 81, 0 2005-02-25 10:42 /dev/video0 ls: : No such file or directory /dev/video0 is a symbolic link to . ./quickcam.sh: line 699: [: too many arguments ls: : No such file or directory ls: : No such file or directory [!] major number is . Usually it should be 81, so there are problems ahead. WARNING: If you press Enter, I'll try to continue anyway, but this probably will fail. You SHOULD press Ctrl+C now. Press Ctrl+C to quit, Enter to continue ---> [!] Bad minor number in , should be 0. To correct this problem, remove the bad file and recreate it with mknod-command (read man mknod). Example: rm -f /dev/video0 mknod /dev/video0 c 81 0 chmod a+rw /dev/video0 WARNING: If you press Enter, I'll try to continue anyway, but this probably will fail. You SHOULD press Ctrl+C now.
However a quick look in /dev shows that video0 does exist and that it has a major number of 81 and a minor number of 0.
crw-rw---- 1 root video 81, 0 2005-02-25 10:42 video0
Since it seems to be there and have the correct major and minor number I am going to continue and see what happens. After all, what's the worst that can happen? I think this problem is caused by the fact that the device is only read/write for root and video and I am trying to install the drivers using my account. If this doesn't work I will try installing them as video or changing the permissions on device node. Despite all the warnings of doom and gloom and the "you SHOULD press Ctrl-C now" I have a actually now got a working web cam (as tested with xawtv). I have to say as well, the quality of the picture and refresh rate is far better than that produced under Windows with the Logitech drivers. The picture I get under Windows was always a little fuzzy, speckled and with poor colour. The Linux picture is sharp, clear with none of the speckle. As this was sold as a cheep web cam I am wondering if it was intentionally crippled by the drivers under Windows (the image really is that much better).
The configuration program for the camera is qcset (provided by the qc-usb-utils package) but I doubt you will ever want to use it. There is one little bit of configuration that the script won't do for you. It reports that it is too dumb to automatically load the module at boot time. To load the module manually simply enter:
as root or you can have it load every time you boot by entering quickcam in the /etc/modules file. Note: you may also need to add videodev to the modules list as well.
Other Things to Install
Now that you have your web cam installed (there is no point in reading on if it doesn't work) you can install some of the utilities for it. I suggest you install qc-usb-utils and gqcam.
If you want to routinely capture images from your web cam one application you can use is webcamd. Webcamd is not the greatest bit of software around (see below). It insists on creating a file called index.html in what ever directory you tell it you want to store your web cam pictures in. It would have been nice if you could just dump the image somewhere rather than having dump the page as well. To get round this I just created a sub-directory on the web server specifically for the web cam images. You could even block the loading of index.html in this directory if you are so inclined. There is a fairly sizeable bug in webcamd (it might not be a bug but there is so little documentation I couldn't figure out how to correct this behaviour). Webcamd can add the time to the bottom of your image. It does this by creating two files. The first is called pre-webcam.jpg (which is the captured image) the second webcam.jpg (which is the date and time). The latter is the one that gets displayed and copied to the web server. For some unknown reason my installation of webcamd doesn't seem to composite the two images so I always just ended up with a black image with the time. The way round this is to just provide a completely empty <pricture> section in the configuration file. You will probably also get the error message:
ioctl: VIDIOC_QUERYCAP(driver="";card="";bus_info="";version=0.0.0; capabilities=0x0 ): Unknown error 515
This is a much better image grabber. It has useful help and does pretty much what it says on the tin. There was only one slight problem with it that I noticed. When running in deamon mode you have to use the -C flag to hold the device open or you get the error message:
kernel: quickcam: frame lost
hundreds if not thousands of times in /var/log/syslog. The only down side of using the -C flag is that other applications can't then access the web cam and you have a constant load on the CPU. I don't particular care that other software can't access the device and the CPU load is tiny. I suspect that the driver doesn't like having the device repeatedly opened and closed. You might also want to look at using the -z flag to allow the camera to do automatic brightness control although it didn't work for me. To stop vgrabbj in deamon mode just kill it.
I noticed that as evening drew near the brightness of the image produced by vgrabbj was far to low. Setting a higher value using qcset didn't seem to make any difference. The solution to this seems to be to turn on the automatic brightness control with the -b flag however that causes the message:
vgrabbj: Brightness not optimal
to be output every time a frame is captured. That's not so bad but it does fill the syslog with rubbish over time. I have tried using the -F 4 flag as well but that doesn't seem to fix the problem. The result is that the image is a little to bright (but better).
Next I tried turning adaption off using:
But the error message was still displayed and the image became grainy (interestingly just like it is under Windows). I haven't found a way to fix the brightness completely to my satisfaction but I have found the following command to vgrabbj gives about the best result. All I can suggest it you tweak the driver parameters with qcset.
vgrabbj -l 10 -C -f /your/pic.jpg -d /dev/video0 -F 4
When you run xawtv you have to run it with the -noxv flag since quickcams can't do video overlay. The result of not using that flag is a blue screen.