Webcams in Linux, Part 1

Tuesday Feb 26th 2008 by Carla Schroder
Share:

Webcams are everywhere these days and decent standalone USB Webcams cost less than $40. In this two-part series we'll set up a Webcam on Linux, and then use it to perform a number of amazing and fun tasks.

Webcams are everywhere these days: they're standard on a lot of laptops, LCD monitors are starting to incorporate them, and decent standalone USB webcams can be had for less than $40. In this two-part series we'll set up a Webcam on Linux, and then use it to perform a number of amazing and fun tasks.

You won't get television-quality video with an inexpensive Webcam; you'll get small fuzzy herky-jerky. But it's acceptable herky-jerky. A low-end Webcam typically supports 15 frames per second at 320 x 240 pixels. For comparison, movies run at 24 fps. Spending a bit more money will get you some silky smooth video. One example is the Logitech QuickCam Pro 9000. For $99.99 you get a built-in microphone, autofocus, good-quality optics, 30 frames per second, and high-quality video capture size up to 960 x 720 pixels.

It takes more than a good Webcam to get good performance. You should have a modern PC, dual-core if possible, because all that video processing takes some horsepower. A typical minimum bandwidth requirement for smooth video is 256 kbps both ways.

Linux support for Webcams is pretty good, thanks to a number of hardy Linux developers. As usual, the vendors themselves have no interest in supporting anything but MS Windows. Michel Xhaard, with little help, figured out how to support over 250 different Webcams from a common base driver. This base driver, GSPCA/SPCA5xx, is now included in Debian and its offspring. The good folks at Linux UVC driver and tools support a different set of Webcams, and the nice people at Philips USB Webcam Driver for Linux keep it maintained, even though it supports mostly older devices.

The bad news is "pretty good" means you may still have to compile and manually install drivers, and perform other manual tweakages. Just like the good old days.

Continue to Page 2

If you're still shopping, first find out what works best on your own particular Linux distribution. Mandriva is probably the Webcam-friendliest Linux. Logitech Webcams are the most popular, but not all of them have native Linux drivers.

If you're using an inherited Webcam, you may get lucky and it will work as soon as you connect it. Here is the short way:

  1. Install Camorama
  2. Install both v4l and v4l2 (Video for Linux)
  3. Connect Webcam
  4. Start Camorama
  5. Wave to yourself
If Camorama doesn't work, try the Testbed account in Kopete. Figure 1 shows me and my best friend in Kopete.

Figure 1 shows a problem with integrated Webcams: you have to adjust your whole screen to frame your image. I was sitting tall, too.

Camorama does not support v4l2, which is unfortunate because v4l2 has a lot of improvements and bugfixes over version 1. The Ubuntu forums are full of users asking what the "could not connect to video device (dev/video0)" error message means when they try to use Camorama. One reason is they're using a driver that requires v4l2, or they don't have v4l installed.

On a modern Linux distribution, udev and HAL should detect the Webcam, create /dev/video0 with the correct permissions, owner root and group video, and load the correct kernel module. If you are not in the "video" group, add yourself, then logout and log back in. Run the id command with no options to make sure. Run lsmod to verify that the correct kernel module loaded.

Continue to Page 3

My own Webcam is built into a Viewsonic VX2255 LCD monitor. This monitor also has a built-in microphone. The Webcam requires a USB cable, so I connected it and ran these commands to see if Kubuntu Gutsy recognized it:
$ lsusb
Bus 005 Device 002: ID 04f2:b021 Chicony Electronics Co., Ltd
$ dmesg
[20093.973828] usb 5-8: new high speed USB device using ehci_hcd and address 2
[20094.211937] usb 5-8: configuration #1 chosen from 1 choice
[20094.318310] Linux video capture interface: v2.00
[20094.341023] uvcvideo: Found UVC 1.00 device ViewSonic 1.3M, USB2.0 Webcam (04f2:b021)
[20094.344865] usbcore: registered new interface driver uvcvideo
[20094.345151] USB Video Class driver (v0.1.0)
That reveals that this Webcam is supported by the uvcvideo kernel module, and if I need to do a Web search for more information I have the Super Secret Webcam Name and Number. Take that, Viewsonic! Remember that dmesg updates as you plugin or remove peripherals, so its most recent output always shows the latest activity. If dmesg doesn't see a device, then the kernel does not see it, and you're probably out of luck.

Come back next week and we'll get cracking on some fun stuff, such as spying on people and displaying ourselves on the Internet. Please visit Resources for all manner of helpful links.

Resources

Carla Schroder is the author of the Linux Cookbook and the newly-released Linux Networking Cookbook, and is a regular contributor to LinuxPlanet.

This article was first published on LinuxPlanet.com.

Do you have a comment or question about this article or other small business topics in general? Speak out in the SmallBusinessComputing.com Forums. Join the discussion today!

Return to Page 1

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved