个人工具

UbuntuHelp:Webcam

来自Ubuntu中文

跳转至: 导航, 搜索


<<Include(Tag/StyleCleanup)>> This page is not really written for people who are new, or relatively new to Ubuntu, and Linux. The author assumes prior knowledge of the subject matter contained herein in order to achieve successful results. This is typical within the Linux community. Good luck! Many webcams will "just work" in Ubuntu. There is a USB standard that defines USB streaming video called UVC. This stands for Universal Video Class, and it does for webcams what UMS does for USB memory sticks and hard drives. This allows one driver to work with many webcams. When looking to purchase a webcam for use with Ubuntu, you should look for a UVC compatible camera. The Linux-UVC project has a good list of UVC compatible webcams as well as The Quickcam Team for Logitech cameras.

Example: A webcam that just "works"

OS: Ubuntu 9.10 Karmic Koala <
> Webcam: Logitech Webcam C200 <
> Laptop: Dell M90 <
> Application: skype-ubuntu-intrepid_2.1.0.47-1_i386.deb from www.skype.com (already installed). Steps:

  1. Plugged in webcam into available USB.
  2. Opened up program to use the webcam i.e Skype
  3. Went to Options -> Video Devices
  • Noticed UVC camera at /dev/video0 was selected
  1. Clicked the test button and saw video
  2. Went to Options -> Sound Devices
  3. Tried to make a Test Call --> No Audio or microphone pick up
  4. Went to System -> Preference -> Sound selected the Input tab
  • Two audio devices were available:

Internal Audio Analog Stereo (selected) and 0802 Analog Mono

  1. Selected 0802 Analog Mono
  2. Made some noise, saw it register on the input level meter.

10. Closed out Sound 11. Re-open Skype Options -> Sound Devices 12. Made a Test Call -> Audio works perfectly 13. Went to Options -> Video Devices 14. Checked to Enable Skype Video, Start Video automatically ..., recieve... video from anybody, and show video... to those I have allowed 15. Made a call to a friend, worked flawlessly :D 16. Tested with Ekiga and Pidgin as well.

Testing your webcam

Ekiga is installed by default in Ubuntu, and can be used to test your webcam. For UVC devices luvcview is a good program you can use to test that the camera is working. If it doesn't work, you may need to update the UVC driver (see Manual install instructions below). Cheese, Camorama, xawtv, VLC, aMSN, and Kopete are in the Ubuntu repositories. They all can be used to test and use your webcam. In some cases you (VLC, mplayer, amongst others) will need to know the video and audio device files for your webcam. Before you plug in your webcam, try the following two command at a console:

ls /dev/video*
ls /dev/audio*

Make a note of the devices appearing. Now plug in your webcam, allow the system a few seconds to register the device, and run the two commands again. The new appearances should belong to your webcam (for instance, /dev/video0 and /dev/audio2).

Before attempting any drivers installation

If your webcam is not one of the latest models and you get at least something as the picture (some garbled or green screen or statics) instead of the expected picture -- you already have the installed drivers. Still you'll have to reconfigure the launching of the application in which the problem is observed. Reason: The developers decided to change the way the drivers and cameras work: old drivers (before Ubuntu 8.10) had the code to decode the data received from the webcam, the new drivers (since 8.10) don't. instead they assume decoding it always done somewhere else. The applications which use the older assumptions have to be provided with the additional (compatibility and decoding) library. An example of the procedure needed to adjust launching one typical application with the described problem follows.

Skype

Go to main menu, System, Preferences, Menus: Applications, Internet, Items: Skype, Properties, and replace the Command with

bash -c 'LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype'
64-bit
bash -c 'LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype'

If the above doesn't work then try running the command from a terminal and look at the output. If it is complaining about "error unexpected width / height in JPEG headerexpected: 320x240, header: 1600x1200" then try the following

bash -c 'LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so skype'
64-bit
bash -c 'LD_PRELOAD=/usr/lib32/libv4l/v4l2convert.so skype'

Driver installation

EasyCam

If needed, try EasyCam, a tool for installing webcam drivers. If you are unable to manage installing your Webcam using EasyCam, you may try installing your camera manually. At the end of this page are some links to help you with this. If you are using Intrepid and have a Logitech QuickCam or something else using the gspca driver, see this answer for video4linux 1 compatibility. Note: requires building and installing software from scratch.

Manual driver installation instructions

Installing spca5xx manually

You can find howto's for manual installation of the spca5xx driver here.

Installing ov51x manually

You can find howto's for manual installation of the ov51x driver here.

Installing ov51x-jpeg manually

This is a hacked driver by http://www.rastageeks.org/ and more info is available at http://www.rastageeks.org/ov51x-jpeg/index.php/Main_Page Suported hardware http://www.rastageeks.org/ov51x-jpeg/index.php/Working_Webcams (July 16 2008) Currently the source package for ov51x-jpeg doesn't compile, but you can use this howto to get it running.

Installing UVC

The UVC module is included in 7.10 and later, and possibly earlier but the included version has problems with some webcams. If you need to install/update it you can find a howto here

Recording video

cheese

You can use cheese to test and record pictures and video from your webcam.

sudo apt-get install cheese

then run cheese . cheese should automatically detect your webcam and display live video stream. You can click either on photo or video and select Take a Photo or Start recording

ffmpeg

To record both video and audio using ffmpeg, first make sure ffmpeg is installed:

sudo apt-get install ffmpeg

then run ffmpeg with arguments such as these:

ffmpeg -f oss -i /dev/dsp -f video4linux2 -s 320x240 -i /dev/video0 out.mpg

MPlayer / MEncoder

MPlayer is capable of displaying a webcam video stream, for example with the command line

mplayer tv:// -tv driver=v4l:width=640:height=480:device=/dev/video0

For Jaunty / Karmic, use this command line.

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

The resolution (width=??? & height=??? ) should be chosen to match the output of your device, and the device file (/dev/video0) to match your webcam's device file, see above. The companion to MPlayer, MEncoder can record from a webcam to video files such as AVI, for example without audio:

mencoder tv:// -tv driver=v4l:width=320:height=240:device=/dev/video0 -ovc lavc -o webcam.avi

for Jaunty/Karmic,

mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0 -ovc lavc -o webcam.avi

and with audio

mencoder tv:// -tv driver=v4l:width=320:height=240:device=/dev/video0:forceaudio:adevice=/dev/dsp1 -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o webcam.avi

for Jaunty/Karmic,

mencoder tv:// -tv driver=v4l:width=320:height=240:device=/dev/video0:forceaudio:adevice=/dev/dsp1 -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o webcam.avi

Type 'man mencoder' for more info on the audio options. In the example, /dev/dsp1 refers to the webcam USB Audio device, while /dev/dsp would refer to the sound card. You may need to install these programs with

sudo apt-get install mplayer mencoder

VLC

In VLC, choose 'Open capture device' from the file menu and enter the video and audio device files (see above) in video device name and audio device name, respectively. If you just want a 'mirror' (to see what the webcam is showing), click 'OK' and you're done. If you wish to record, tick off 'Stream/save' in the 'Advanced options' section. Click the settings button right next to it. Tick 'File' off under 'Outputs' and enter a filename. Encapsulation method can be left at the default (MPEG TS). Under 'Transcoding options', tick 'Audio codec' and 'Video codec'. These can also safely be left the defaults (obviously greater compression results in lower file sizes, so experiment). Click 'OK' in the Settings screen and once again in the main webcam screen (Video4linux). If you want to have more control, you can access several settings, including resolution, by clicking the Advanced options button. If you wish to be able to quickly start a video session with your webcam, the resulting vlc command is printed in the Customize line at the bottom. You simply need to prepend 'vlc', e.g.

vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" :v4l-norm=3 :v4l-frequency=-1 :v4l-caching=300 :v4l-chroma="" :v4l-fps=-1.000000 :v4l-samplerate=44100 :v4l-channel=0 :v4l-tuner=-1 :v4l-audio=-1 :v4l-stereo :v4l-width=640 :v4l-height=480 :v4l-brightness=-1 :v4l-colour=-1 :v4l-hue=-1 :v4l-contrast=-1 :no-v4l-mjpeg :v4l-decimation=1 :v4l-quality=100

The recording instructions will similarly need to be appended. Copy the contents of the 'Stream Output MRL' box under 'Settings' and change ":sout=" to "--sout " and append it to your vlc command:, e.g.

vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" :v4l-norm=3 :v4l-frequency=-1 :v4l-caching=300 :v4l-chroma="" :v4l-fps=-1.000000 :v4l-samplerate=44100 :v4l-channel=0 :v4l-tuner=-1 :v4l-audio=-1 :v4l-stereo :v4l-width=640 :v4l-height=480 :v4l-brightness=-1 :v4l-colour=-1 :v4l-hue=-1 :v4l-contrast=-1 :no-v4l-mjpeg :v4l-decimation=1 :v4l-quality=100 --sout "#transcode{vcodec=mp1v,vb=1024,scale=1,acodec=mpga,ab=192,channels=2}:duplicate{dst=std{access=file,mux=mpeg1,dst=/tmp/test.mpg}}"

For Ubuntu 9.10 (Karmic Koala), use

vlc v4l2:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" :v4l-norm=3 :v4l-frequency=-1 :v4l-caching=300 :v4l-chroma="" :v4l-fps=-1.000000 :v4l-samplerate=44100 :v4l-channel=0 :v4l-tuner=-1 :v4l-audio=-1 :v4l-stereo :v4l-width=640 :v4l-height=480 :v4l-brightness=-1 :v4l-colour=-1 :v4l-hue=-1 :v4l-contrast=-1 :no-v4l-mjpeg :v4l-decimation=1 :v4l-quality=100

as an example, because vlc is not compiled with v4l, but with v4l2 To simple take a few snapshots, open the webcam without recording and choose 'Snapshot' under the 'Video' menu.

Webcam Issues

Intrepid/Updated Hardy issues

With Intrepid and Hardy fully updated, several issues were presented with previously working webcams. The root causes for this issues were several webcam modules merged into the kernel from 2.6.26 and 2.6.27, libv4l modifications, gstreamer modifications and changes in Ubuntu's kernel. Almost all the issues present at this time (14/12/08) are detected with corresponding bug reports, some of them are solved, and some others are in the process of getting them solved. We are working hard to uncover and solve the remaining issues, so please bear with us in the meantime. I'm listing here the issues organized by kernel module. So you've got to check which module your camera uses in order to check for the workaround or corresponding report.

List of Kernel modules with problems

Driver Launchpad Bugs Brief problem description
gspca https://bugs.edge.launchpad.net/bugs/260918 The mother of all webcam related bugs :). Well almost all of the, this one solves a lot of libv4l issues with gspca webcam and some other webcams as well
uvcvideo https://bugs.edge.launchpad.net/bugs/290506 Uvcvideo webcam issue detected mainly with cheese. It's solved right now just waiting the next kernel
pwc https://bugs.edge.launchpad.net/bugs/282473 Due to the mentioned changes this one became a dupe from bug #260918
gspca_zc3xx https://bugs.edge.launchpad.net/bugs/292086 This is caused by the inclusion of gspca modules on the kernel
gspca_zc3xx https://bugs.edge.launchpad.net/bugs/144745 Probably the same bug as the previous one
sn9c10x https://bugs.edge.launchpad.net/bugs/280657 snc9105 and sc9102 issues
sn9c20x https://bugs.edge.launchpad.net/bugs/87054 microdia solution for the sn9c20x webcams
r5u87x https://bugs.edge.launchpad.net/bugs/219252 This would be the package of userland tools needed to load firmware for Ricoh Cameras and would use the uvcvideo driver for the actual work
r5u870 https://bugs.edge.launchpad.net/bugs/120434 This is the way to go if you've got a WDM camera not supported by uvcvideo or if you want to use the old driver. In the near (really near) future this would be deprecated
ov51x_jpeg https://bugs.edge.launchpad.net/bugs/263008 Trying to introduce this module into the kernel
ov51x_jpeg https://bugs.edge.launchpad.net/bugs/262853 As the current source package no longer builds, the latest version is the one for this webcam to work
stk, stkwebcam https://bugs.edge.launchpad.net/bugs/269123 The st11k module present in Hardy is no longer available in Intrepid/Jaunty. The stkwebcam doesn't supports all the previous webcams.
quickcam https://bugs.edge.launchpad.net/bugs/293176 Description

Fixing Webcam issues while using Flash since Intrepid

If your webcam stopped working in flash-powered streaming sites, for instance (like www.ustream.tv), that might be due to two reasons: (1) Bug in recent version of the adobe flash plugin (2) you are using an old webcam which doesn't work well with V4L2 See below for more information on solutions reported to work by some users.

Bug in recent version of Adobe flash player

In Ubuntu Hardy you were used to be asked to grant permission to the website you were visiting to take control on your webcam (through some flash popup with the settings). It seems that recent versions of Adobe flash player (the updated ones for Intrepid and Jaunty since June 2009, at least, and probably before also) have a bug which doesn't ask the user to grant access to a site when visiting it. Like ustream.tv for streaming using your webcam, as example. The workaround is to grant access to that website by default without attempting to ask you each time.

  • You need to go to:

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager06.html

  • Choose the "Website privacy settings"
  • Select the site from the list of visited websites.
  • click on the option "always allow" above the list.

You should see that the icon on the left of that site in the list changes from yellowish to green colour. That's it. Try again visiting that website, ustream.tv in this example, and your webcam should be streaming again as it used to do back with Hardy. Enjoy! :-)

old webcam which doesn't work well with V4L2

There seems to be a known problem in Ubuntu Intrepid and Jaunty (at least), due to switching from the video system V4L to the more recent V4L2. Many applications, like webcams, doesn't seem to work well (or at all) with V4L2. But luckily there is a simple workaround to avoid the problem, through installing and loading some libraries with backward-compatibility with V4L, so that Flash sees again your Webcam, as it used to do until Ubuntu Hardy. In order to do it, we need to shut down any application that might be doing some use of the video: editors, instant messengers or even the internet browser, and in a terminal we'll type:

sudo apt-get install ld.so.preload-manager

y after that, execute:

sudo ld.so.preload-manager /usr/lib/libv4l/v4l1compat.so

Then, you have to switch the video mode to V4L from the multimedia systems selector, through executing:

gstreamer-properties

Go to the Video tab, and change the default value to V4L. That should do the work (it did for me using Jaunty, and for others as reported originally at this source).

Fixing Audio problems with USB webcam

I installed a Logitech webcam Pro 9000 on a new Karmic/9.10 32bit install. Video worked "out of the box" but there was no audio. After hunting around for a while, I remembered how I had a similar problem trying to get digital audio out over hdmi on another 9.10 box. The problem was that the alsa settings (not visible under pulseaudio) had the IEC958 device muted (silly setting if you ask me!). Anyway, I took the following steps to getting my webcam audio to work:

  1. start a terminal window/xterm window
  2. type: sudo alsamixer
  3. using the tab key, make sure to be either in "all" or "capture" mode
  4. using the left/right arrow key, navitage to the correct "slider"

(I'm not sure if the right one was front mic (left/right) or just plain "mic" or Mic Boost but I enabled them all)

  1. if the value at the bottom of the slider says "M" then your device is on "mute" - Hit the "m" key to togger the mute / un-mute
  2. using the up/down arrow, adjust the setting to get as much green as possible w/o getting in the red zone.
  3. repeat for all lables that look like "mic", "front mic" "Mic Boost" etc...
  4. exit alsamixer
  5. test your audio. I installed "cheese" to do a quick audio/video recording test but you can also test with "sound recorder" or the skype test call etc...

That should do it!

Setting brightness, contrast, color etc. on some webcams

When fidling with webcam software one may inadvertently screw up the settings in VIDIOCGPICT. This often results in a very bright / dark picture, or a "greenish" / "blueish" picture. After spending hours on the 'Net trying to solve this, I found a very easy solution: luvcview . Simply install (it's in the repositories) and run. It is a simply webcam app that uses the webcam to make a video, BUT.... it allows you to change the settings in VIDIOCGPICT. Hardly an elegant solution, but it does the job.

Additional software

This software is not supported by Ubuntu, and is not available in the repositories. Camera Monitor shows a tray icon letting you know when your webcam is on.

See also