Webcam

From Gentoo Linux Wiki

(Redirected from HOWTO Install a webcam)
Jump to: navigation, search

Webcams are live video capturing devices. They are usually connected using USB. If it is an ethernet or wifi webcam, you won't need any drivers, but just a browser.

Fix me: Add information for non-USB webcams.

Contents

[edit] Kernel configuration

[edit] USB support

Before continuing, make sure you've got USB up and running.

[edit] Webcam support

Video devices are connected using the Video4Linux and Video4Linux2 frameworks. Enable support in your kernel:

Linux Kernel Configuration: v4l and v4l2 support
Device Drivers  --->
  Multimedia devices  --->
    <*> Video For Linux
    [ ]   Enable Video For Linux API 1 (DEPRECATED)
    [*]   Enable Video For Linux API 1 compatible Layer

[edit] Webcam driver

Now we'll need to identify your webcam's chipset and configure in-kernel support, or find an external module. Install sys-apps/usbutils:

emerge -av usbutils

And list the connected devices using lsusb.

# lsusb
Bus 001 Device 002: ID 046d:08da Logitech, Inc. QuickCam Messanger
The above output line will be just one of many, and is an example webcam. You may have a completely different line. If your webcam doesn't show up, run
update-usbids
Also make sure you have booted with a kernel which supports your USB chipset. If you have, check dmesg's output while plugging in a webcam and see if anything happens.

Now that you (hopefully) know your webcam's chipset, open up your kernel configuration and see if there's in-kernel support for it. If there is, you can just go ahead and enable it, recompile and install your kernel.

Note: Some drivers support more than one chipset, so it may not be clear from the config's title whether or not yours is supported. Read the options' help to be sure.

[edit] Generic

Most webcams on the market today are supported by the two generic drivers below. Also, if you can't identify the make or model or your webcam, the following kernel drivers may help you out after all:

Linux Kernel Configuration: USB_GSPCA
Device Drivers  --->
  Multimedia devices  --->
    [*] Video capture adapters  --->
      [*]   V4L USB devices  --->
        <*>   USB GSPCA driver


Or, for the Linux kernel >=2.6.29:

Linux Kernel Configuration: USB_GSPCA
Device Drivers  --->
  Multimedia devices  --->
    [*] Video capture adapters  --->
      [*]   V4L USB devices  --->
        <*>   GSPCA based webcams --->
          [Select your device from the list]


If your web camera is aggregated with microphone, you will need the USB sound device:

Linux Kernel Configuration: SND_USB_AUDIO
Device Drivers  --->
  <*> Sound card support  --->
    <M>   Advanced Linux Sound Architecture  --->
       [*]   USB sound devices  ---> 
        <M>   USB Audio/MIDI driver


(install media-video/gspcav1 for <2.6.27 kernels): supports many webcams based on various chipsets. List of supported devices at http://mxhaard.free.fr/spca5xx.html

Linux Kernel Configuration: USB_VIDEO_CLASS
Device Drivers  --->
  Multimedia devices  --->
    [*] Video capture adapters  --->
      [*]   V4L USB devices  --->
        <*>   USB Video Class (UVC)


(install media-video/linux-uvc for <2.6.26 kernels): supports many webcams following the UVC specification. List of supported devices at http://linux-uvc.berlios.de

[edit] Konica, OV511, SE401, SN9C10x, STV680, W996[87]CF, some Philips webcams

Drivers for cameras based on these chip-sets can be found in the kernel.

[edit] Philips

Drivers for some Philips ToUcam webcams can be found in media-video/usb-pwc-re and media-video/usb-pwcx.

[edit] Logitech

Some drivers are available in-kernel, but there are also some packages. A few drivers are available. Each supports a different set of webcams. Try them all until you find the one that works best:

Note: Some old Logitech webcams only work with the Philips driver (e.g. Logitech QuickCam 4000 Pro, Logitech QuickCam Notebook Pro).

[edit] Tweaks

If using the qc-cam driver, you can improve the speed of the camera using the qcset utility. You can enable double-buffering using:

# qcset compat=dblbuf

The qcset utility is full of interesting settings. With qcset keepsettings=1, the settings will be stored into the webcam and you will be able to control brightness, contrast, etc. You can check that your settings have been restored correctly by runing:

# qcset -i

[edit] OV51X (Sony EyeToy)

For this webcam chipset, there's media-video/ov51x-jpeg in sunrise. The modules included in this are:

  • ov51x
  • ov519_decomp

[edit] Ricoh R5U870

For this webcam chipset, there's media-video/ov51x-jpeg in sunrise.

[edit] SN9C1XX

There are a couple of sn9c1xx webcams around, like the sweex minicam. There is general support in the kernel for these, but there is a more up-to-date driver called media-video/sn9c1xx in the sunrise overlay.

[edit] Syntek

This webcam can be found in some ASUS laptops. It is not yet available in any tree, so go to the Web site and install it manually.

[edit] Loading a driver

Note: You can skip this section if you built the drivers into the kernel.

You should now have your camera's module installed. To find the module's name of the module use the equery tool from gentoolkit with the name of the driver's package:

$ equery f <package name>

And insert the module for your camera.

# modprobe <module_name>

You can also add it to /etc/modules.autoload.d/linux-2.6 (if using <baselayout-2)

File: /etc/modules.autoload.d/linux-2.6
...
<module_name>
...

or /etc/conf.d/modules (if using >=baselayout-2)

File: /etc/conf.d/modules
...
modules="${modules} <module_name>"
...

[edit] Libraries

Sometimes additional libraries may be needed for the correct work of the camera.

  • media-libs/libv4l fixes the compatibility issue between v4l and v4l2, and also converts from different pixel formats used by cameras to a standard understood by most applications. If the driver recognizes your camera but the picture appears as noise or seriously distorted (while the resolution setting are alright) then you should try to emerge this library and follow the instructions given in ebuild messages.

[edit] Using your webcam

If you are using udev there should now be a device file in /dev/v4l/ called video0 (or video1, video2 or video3, for that matter). If the device is not created, check dmesg for errors and useful messages.

[edit] Testing

Some applications require the v4l and/or v4l2 use-flags to take advantage of your webcam. Some applications can't detect the camera's resolution. You can use the v4l-info tool from the media-tv/xawtv package to find out what resolution your device supports, and also detect if it's working at all:

$ v4l-info

This produces a lot of output. Scroll through the list to find the resolution.

[edit] Viewing

[edit] Mplayer

Versatile media player. Can play from many sources, including video devices. Specify the width and height manually, depending on what your camera supports. For example, for a v4l1 driven webcam with resolution of 352x288:

$ mplayer tv:// -tv driver=v4l:width=352:height=288:device=/dev/video0 $ mplayer tv:// -tv driver=v4l:width=352:height=288:outfmt=rgb24:device=/dev/video0:noaudio -flip

A v4l2 driven webcam with a resolution of 640x480 and 15 frames per second:

$ mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 15

Anononymous note: Remember to have mplayer compiled with dvb and v4l and/or v4l2. This can be done by adding media-video/mplayer dvb v4l v4l2 on /etc/portage/package.use.

[edit] Other packages

You might need to install media-libs/libv4l and run "LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so application" in order to make some programs which only work with v4l1 work on v4l2. Remember also to emerge those applications with the v4l v4l2 flag.

[edit] Recording

[edit] mplayer

Make sure mplayer's encode use-flag is enabled. Example usage for recording continuous video:

$ mencoder tv:// -tv driver=v4l:width=<width>:height=<height>:device=/dev/video0 -nosound -ovc lavc -o <filename>.avi

Recording with sound, one channel 64kbit mp3:

$ mencoder tv:// -tv driver=v4l:width=<width>:height=<height>:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o <filename>.avi


unmute ALSA capture

$ alsamixer
and press F4

List all soundcards and digital audio devices

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Intel [HDA Intel], device 0... 
.... 

card 1: U0x46d0x9c1 [USB Device 0x46d:0x9c1], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

change "adevice=/dev/dsp"

mencoder tv:// ... adevice=hw.1:alsa

[edit] Other packages

  • media-video/w3cam - Able to capture single frames to image files. You could use this to make photos.

[edit] Streaming

You can also publish the video stream via ethernet.

[edit] vlc

Install with the stream, httpd and v4l use-flags. Run the GUI client and open a capture device. Make sure the correct device file is selected, and turn on streaming at the bottom of the dialog. In the stream settings, enable http and select at least a video codec. In the preferences window you may also set a user and password for accessing the stream. The "open capture dialog" and "stream settings" will also show you the options you need to perform all this from the command line.

[edit] camserv

Streaming video server.

Note: If you know the following settings aren't needed, or can minimize this list, please do.

Specific setup for cameras based on PAC207* chipset:

File: Pixart camserv setup
....
[video_v4l_qcam]
path            /usr/lib64/camserv/libvideo_v4l.so.0
device_path     /dev/video0
port            0
color           30000
hue             30000
contrast        30000
brightness      30000
whiteness       30000
autobright      0
...

[video]
video_section           video_v4l_qcam
width                   320
height                  240
maxfps                  0
memhack                 1
...

[edit] Other packages

  • UVC Streamer - Streaming video server for Linux UVC compatible webcams with very low CPU and RAM usage.

[edit] Monitoring

Even though this is not a good idea due to usb bandwidth, this is possible with 1 or 2 cameras, or with multiple usb bus cards.

  • media-video/motion - Motion detector.
  • www-misc/zoneminder - Allows you to capture, analyze, record and monitor any cameras attached to your system through a web interface.
  • media-video/motiontrack - Not strictly a webcam application, but can be used in combination with a frame grabber to compare images and check for motion.

[edit] Troubleshooting

[edit] "Input/output error" or "No space left on device"

This can be due to USB bandwidth being exceeded. Try connecting the device to a different USB port, preferably on another bus (usually not the connector right next to it). Also see this post on the Gentoo forums.

[edit] Black screen

If you only see a black screen using xawtv or gqcam and then the application crashes and the kernel log gives you something like this:

May 18 14:47:37 [kernel] ohci_hcd 0000:00:03.1: leak ed ef3340c0 (#81) state 2
May 18 14:48:00 [kernel] quickcam: Control URB error -2
May 18 14:48:00 [kernel] Unable to handle kernel paging request at virtual address 02000040
...
May 18 14:48:00 [kernel]  <1>Fixing recursive fault but reboot is needed!

Then you have to make sure the webcam is connected to a usb-hub (BUS) that does not have any other devices attached to it. You can investigate that by issuing lsusb as root:

# lsusb
Bus 004 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 002: ID 046d:c50e Logitech, Inc. MX-1000 Cordless Mouse Receiver
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 002: ID 046d:0870 Logitech, Inc. QuickCam Express
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

If lsusb hangs you need to reboot first (look at the line reboot is needed! in the kernel log). Here you see that Bus 002 only has the Logitech webcam connected to it. Before that it was connected to Bus 003 where there is already an optical mouse and that would make it crash, so you may have to reboot the system. More about this issue can be found at Gentoo-forum and qc-usb mailing list.

[edit] Odd colors

Known to occur on logitech quickcam messenger 046d:08da. If using the gspca driver, try adding the parameter force_rgb=1. Either using modprobe manually, or add a file in /etc/modules.d:

File: /etc/modules.d/gspca
options gspca force_rgb=1

Run "update-modules force" before inserting the module.

[edit] Mplayer refuses to work with your webcamera or shows some kind of a green noise

Emerge media-libs/libv4l and try running:

$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so mplayer tv:// -tv driver=v4l:device=/dev/video0

If that works, you will probably want to go back and read section Webcam#Libraries

Personal tools