Webcam
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. // What kinds then? |
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 frameworks. Enable support in your kernel:
| Linux Kernel Configuration: Enabling video for linux |
Device Drivers --->
Multimedia support --->
<*> Video For Linux
|
[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:
And list the connected devices using lsusb.
Bus 001 Device 002: ID 046d:08da Logitech, Inc. QuickCam Messanger
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.
[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_VIDEO_CLASS |
Device Drivers --->
Multimedia support --->
[*] Video capture adapters --->
[*] V4L USB devices --->
<*> USB Video Class (UVC)
|
| Linux Kernel Configuration: USB_GSPCA |
Device Drivers --->
Multimedia support --->
[*] 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
|
[edit] Specific Drivers
Some webcams, especially older ones, will need specific drivers. Some are in-kernel, others are available as external packages.
| Manufacturer | Model | Driver Location | Driver Name |
|---|---|---|---|
| Konika | OV511 | in-kernel | TODO |
| Konika | SE401 | in-kernel | TODO |
| Konika | SN9C10x | in-kernel | TODO |
| Konika | STV680 | in-kernel | TODO |
| Konika | W996[87]CF | in-kernel | TODO |
| Philips | ToUcam | portage | media-video/usb-pwc-re and media-video/usb-pwcx |
| Philps | others TODO | in-kernel | TODO |
| Logitech | New models (2010+) | portage | media-video/linux-uvc |
| Logitech | Older models (2009-) | portage | media-video/qc-usb, media-video/qc-usb-messenger, media-video/gspcav1, media-video/spca5xx |
| Logitech | QuickCam 4000 Pro, QuickCam Notebook Pro | in-kernel | TODO (Philips Webcam Driver) |
[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:
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:
[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
MSI StarCam 370i (WebCam) is an example of one of these cameras
This general process could probably be applied to any webcam.
Use lsusb (sys-apps/usbutils) to find the manufacturer and device codes.
pearcely:~ # lsusb Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 007 Device 002: ID 0c45:60c0 Microdia PC Camera with Mic (SN9C105) Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 003: ID 413c:2010 Dell Computer Corp. Bus 006 Device 002: ID 413c:1003 Dell Computer Corp. Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 004: ID 413c:3010 Dell Computer Corp. Optical Wheel Mouse pearcely:~ #Searched for using
grep -i 60c0 /usr/src/linux/Documentation/video4linux/*
which points to sn9c102.txt
Followed instructions on configuring that module. You may also like to enable the v4l compatability layer in the kernel.
Add sn9c102 to /etc/modules.autoload.d/kernel-2.6
Make sure both 'v4l' and 'v4l2' in USE setting in /etc/make.conf
Doemerge --newuse --verbose --with-bdeps y --update --deep world
Reboot, just to be sure you have not borked something (for example, emerge nvidia-drivers or virtualbox-modules)
Tested usingmplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0Alternatively, you could try
env LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0if the first doesn't work.
[edit] Getting it working with ZoneMinder
Re-emerged ZoneMinder, just in case (temporarily changing my /etc/make.conf MAKEOPTS to '-j1' because zoneminder does not build well with parallel builds, apparently)
CPPFLAGS="-D__STDC_CONSTANT_MACROS" emerge -av www-misc/zoneminderI had to put
LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so; export LD_PRELOADin my apache2 /etc/conf.d/apache2
I had tried simply putting it in the zoneminder service startup script, to no avail.
Restarted apache and browsed to the zoneminder page.
Now, you should be able to see the webcam stream! (configured as 320x240 PAL RGB24)
[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
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:
And insert the module for your camera.
You can also add it to /etc/modules.autoload.d/linux-2.6 (if using <baselayout-2)
... <module_name> ...
or /etc/conf.d/modules (if using >=baselayout-2)
...
modules="${modules} <module_name>"
...[edit] Libraries
Sometimes additional libraries may be needed for the camera to work correctly.
- 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.
- app-emulation/emul-linux-x86-medialibs contains 32bit version of the above libraries. These are required on 64bit systems running 32bit binaries like Skype
[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:
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, a v4l2 driven webcam with a resolution of 640x480 and 15 frames per second:
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] Skype
If Skype doesn't display your webcam but another programs do like Cheese or MPlayer, it's because Skype doesn't load v4l. So you'll have to do it manually each time you load Skype:
(if you have v4l version1)
(if you have v4l version2)
To integrate the command in the launcher of gnome-panel, the "env" will have to be added before ld_preload, so we'll have:
or
[edit] Other packages
- media-video/camorama - Simple and effective.
- media-video/spcaview - Viewer for use with the spca5xx or gspcav1 driver.
- media-video/xawtv - One of the oldest video viewers for linux. Relatively old graphical interface. Gets the job done.
- media-video/came - Rewrite of xawtv with added features.
- media-video/cheese - Gnome webcam application
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:
Recording with sound, one channel 64kbit mp3:
unmute ALSA capture
List all soundcards and digital audio devices
**** 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"
[edit] Other packages
- media-video/w3cam - Obsolete, no longer in Portage. Was able to capture single frames and create image files. Could be used 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.
Specific setup for cameras based on PAC207* chipset:
.... [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:
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:
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:
If that works, you will probably want to go back and read section Webcam#Libraries /pre>}}
[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:
- media-video/qc-usb
- media-video/qc-usb-messenger
- media-video/gspcav1
- media-video/spca5xx
- media-video/linux-uvc - for new logitech webcams
These packages are removed from portage, drivers are available in-kernel since Oct 8, 2009.
[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: {{Root|