Difference between revisions of "Webcam setup"

From ArchWiki
Jump to navigation Jump to search
(Add sections on v4l2-ctl command line and using v4l2-ctl with udev to persist config changes)
 
(68 intermediate revisions by 20 users not shown)
Line 1: Line 1:
[[Category:Imaging]]
+
[[Category:Digital imaging]]
 
[[es:Webcam setup]]
 
[[es:Webcam setup]]
 
[[ja:ウェブカメラ設定]]
 
[[ja:ウェブカメラ設定]]
 
[[ru:Webcam setup]]
 
[[ru:Webcam setup]]
[[zh-cn:Webcam setup]]
+
[[zh-hans:Webcam setup]]
{{Accuracy|Several drivers in this article are available as built-in kernel modules, and shouldn't require special packages.}}
 
 
 
 
This is a guide to setting up your webcam in Arch Linux.
 
This is a guide to setting up your webcam in Arch Linux.
  
== Linux webcam support ==
+
Most probably your webcam will work out of the box. Permissions to access video devices (e.g. {{ic|/dev/video0}}) are handled by [[udev]], there is no configuration necessary.
 
 
Most probably your webcam will work out of the box. In that case you may skip to section [[#Webcam configuration]] if you want to configure color, brightness and other parameters. Otherwise follow the steps below.
 
 
 
== Identify your webcam ==
 
 
 
Identify the name of your webcam (using, for example, {{Ic|lsusb}}) and find a proper driver.  Below is a list of webcams, and what drivers they work with. If you get your webcam to work, add the name of the webcam and the driver you used to the list!
 
 
 
=== pwc ===
 
 
 
* Creative Labs Webcam Pro Ex
 
* Logitech QuickCam Notebook Pro (only the "Pro" models)
 
* Logitech Quickcam Pro 4000
 
* Philips ToUCams (not confirmed at the moment, but it is using the pwc driver if I remember correctly)
 
* Philips SPC900NC
 
 
 
=== qc-usb ===
 
 
 
* Dexxa Webcam
 
* Labtec Webcam (old model)
 
* LegoCam
 
* Logitech Quickcam Express (old model)
 
* Logitech QuickCam Notebook (not the "Pro" models)
 
* Logitech Quickcam Web
 
 
 
=== qc-usb-messenger ===
 
 
 
* Logitech Quickcam Messenger
 
* Logitech Quickcam Communicate (for Communicate MP/S5500 or "for Business" see the linux-uvc section below)
 
  
It is now in the community repo.
+
== Loading ==
  
{{Note|
+
Most recent webcams are UVC (''USB Video Class'') compliant and are supported by the generic ''uvcvideo'' kernel driver module. To check that your webcam is recognized, run ''dmesg'' just after you plug the webcam in. You should see something like this:
* If qc-usb-messenger does not work use the gspca module, by installing the gspcav1 package.
+
{{hc|$ dmesg {{!}} tail|
* Now this driver is a module included in kernel 2.6.27.
 
}}
 
 
 
=== zr364xx ===
 
 
 
 
 
This driver can be used for many webcams like:
 
* Aiptek PocketDV 3300
 
* Creative PC-CAM 880
 
* Konica Revio 2
 
* Genius Digital Camera
 
* Maxell Maxcam PRO DV3
 
You can find the full list of supported devices [http://royale.zerezo.com/zr364xx/ here].
 
 
 
=== sn9c102 ===
 
 
 
* Trust Spacecam series
 
* Maxell Smartcam (for notebooks): 352x288 max. resolution @ 3fps
 
 
 
=== gspca ===
 
 
 
An extensive list of supported webcams is available [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/video4linux/gspca.txt;hb=HEAD].
 
 
 
{{Note|This driver does not have V4L1 support.}}
 
 
 
=== stv680 ===
 
 
 
Many cheap no-name cameras that came out Asia in the last couple of years use the stv680 chipset. Most of these cameras were novelty items (i.e. Pencam, SpyC@m and LegoCam).
 
* Aiptek PenCam series
 
* Digitaldream series
 
* Dolphin Peripherals series
 
* Lego LegoCam
 
* Trust SpyC@m series
 
* Welback Coolcam
 
 
 
A more-complete list of webcams that use the stv680 chipset is available [http://webcam-osx.sourceforge.net/cameras/index.php?orderBy=controller here].
 
 
 
=== linux-uvc ===
 
 
 
* Genius iLook 1321
 
* Logitech  Webcam C210
 
* Logitech  Webcam C250
 
* Logitech  Webcam C270
 
* Logitech  Webcam C600
 
* Logitech HD Webcam C525
 
* Logitech HD Pro Webcam C920
 
* Logitech Quickcam Pro 5000
 
* Logitech Quickcam Pro 9000
 
* Logitech Quickcam Orbit AF
 
* Logitech Quickcam Orbit MP
 
* Logitech Quickcam S5500
 
* Microdia Pavilion Webcam (on MSI PR200)
 
* Logitech Quickcam Communicate MP/S5500 or "for Business"
 
* Chicony Electronics CNF7051
 
 
 
You can find a full list of supported UVC devices [http://www.ideasonboard.org/uvc/ here].
 
 
 
As of kernel 2.6.26 linux-uvc is part of the kernel. Just load the uvcvideo module.
 
 
 
{{Note|
 
* This driver does not have V4L1 support.
 
* With WebCam SCB-0385N (usb ID 2232:1005), WebCam SC-0311139N (usb ID 2232:1020) and WebCam SC-03FFL11939N (usb ID 2232:1028), you might need to add some configuration to the module if the usage of the camera makes the system freeze :
 
{{hc|1=/etc/modprobe.d/uvcvideo.conf|2=options uvcvideo nodrop=1}} }}
 
 
 
=== ov51x-jpeg ===
 
 
 
* Sony EyeToy
 
* Chicony DC-2120
 
* Chicony DC-2120 pro
 
* Trust Spacecam 320
 
* Hercules Webcam Deluxe
 
* Hercules Webcam Classic
 
* Creative Live! Cam Notebook Pro VF0400
 
* Creative Live! Cam Vista IM
 
* Creative Live! Cam Vista IM VF0420
 
* Creative Vista Webcam VF0330
 
* ASUS webcam Model?
 
* Philips PCVC820K/00
 
* NGS showtime plus
 
* HP VGA Webcam with Integrated Microphone
 
 
 
For me to get my "Creative Live! Cam Vista IM" working with Skype, I had to add this line to {{ic|/etc/modprobe.d/modprobe.conf}}:
 
options ov51x-jpeg forceblock=1
 
 
 
=== r5u870 (Ricoh) ===
 
 
 
* HP Pavilion Webcam
 
* HP Webcam 1000
 
* Sony VAIO VGP-VCCx
 
 
 
The Ricoh webcam is built into most new Sony laptops.
 
 
 
Install {{AUR|r5u87x-hg}}{{Broken package link|{{aur-mirror|r5u87x-hg}}}} (provides firmware too) and run the {{ic|r5u87x-loader}} command.
 
 
 
=== stk11xx (Syntek) ===
 
 
 
* Integrated camera in lot of Asus laptops
 
* Asus A8J, F3S, F5R, F5GL, F9E, VX2S, V1S, A6T
 
 
 
Just install {{AUR|stk11xx-svn}}. It contains the right kernel module.
 
 
 
== Make sure the module is loaded for your webcam ==
 
 
 
Add your webcam's [[Kernel modules|kernel module]] in {{ic|/etc/modules-load.d/webcam.conf}} so it will be loaded into the kernel during init stage bootstrapping.
 
 
 
If your webcam is USB, the kernel ''should'' automatically load the proper driver.  If this is the case, check dmesg after you plug your webcam in. You should see something like this:
 
 
 
{{hc|<nowiki>$ dmesg|tail</nowiki>|<nowiki>
 
 
sn9c102: V4L2 driver for SN9C10x PC Camera Controllers v1:1.24a
 
sn9c102: V4L2 driver for SN9C10x PC Camera Controllers v1:1.24a
 
usb 1-1: SN9C10[12] PC Camera Controller detected (vid/pid 0x0C45/0x600D)
 
usb 1-1: SN9C10[12] PC Camera Controller detected (vid/pid 0x0C45/0x600D)
Line 156: Line 18:
 
usb 1-1: V4L2 device registered as /dev/video0
 
usb 1-1: V4L2 device registered as /dev/video0
 
usb 1-1: Optional device control through 'sysfs' interface ready
 
usb 1-1: Optional device control through 'sysfs' interface ready
usbcore: registered new driver sn9c102
+
usbcore: registered new driver sn9c102}}
</nowiki>}}
+
Some pre-UVC webcams are also supported via the ''gspca'' kernel driver module. See the [https://www.linuxtv.org/wiki/index.php/Gspca_devices gspca devices] for a non-exhaustive list of supported devices under this framework.
  
== Permissions ==
+
Otherwise, if your webcam is not supported by the kernel's drivers, an external driver is necessary. The first step is to identify the name of the webcam, using for example {{Ic|lsusb}}. Then you can check [https://www.linuxtv.org/wiki/index.php/Webcam_devices webcam devices] for information and resources about webcams. Once you find a driver compatible with the webcam, you have to add the corresponding [[kernel module]] in {{ic|/etc/modules-load.d/webcam.conf}} so it will be loaded into the kernel during init stage bootstrapping.
  
Permissions to access video devices (e.g. {{ic|/dev/video0}}) are handled by [[udev]], there is no configuration necessary.
+
{{Note|The Linux kernel to userspace API used to control webcams is named ''Video4Linux2'', '''v4l2''' for short. All applications which support v4l2 will work with the kernel's drivers.}}
  
== Webcam configuration ==
+
== Configuration ==
  
If you want to configure brightness, color and other webcam parameters (e.g. in the case when out-of-the-box colors are too bluish/reddish/greenish) you may use [http://guvcview.sourceforge.net/ GTK+ UVC Viewer] (guvcview), available in the [[Official repositories]] as package  {{Pkg|guvcview}}. Just install it and launch, and it will present you a list of configurable settings. Changing these settings will affect all applications (e.g. Skype).
+
If you want to configure brightness, color and other webcam parameters (e.g. in the case when out-of-the-box colors are too bluish/reddish/greenish) you may use ''Qt V4L2 Test Bench''. To run it, [[install]] {{Pkg|v4l-utils}} and launch {{ic|qv4l2}}, and it will present you a list of configurable settings. Changing these settings will affect all applications.
  
=== Webcam resolution ===
+
=== Command Line ===
  
[[#Identify your webcam]], for example:
+
{{Pkg|v4l-utils}} also installs an equivalent command line tool, {{ic|v4l2-ctl}}. To list all video devices:
{{hc|$ lsusb|
 
Bus 001 Device 002: ID 5986:0241 Acer, Inc BisonCam, NB Pro
 
...
 
}}
 
  
Then use the {{ic|Bus}} and {{ic|Device}} numbers to get more information on that device:
+
$ v4l2-ctl --list-devices
  
{{hc|<nowiki>$ lsusb -s 001:002 -v | egrep "Width|Height"</nowiki>|
+
To list the configurable settings of a video device:
wWidth    640
 
wHeight  480
 
wWidth    1280
 
wHeight  1024
 
...
 
}}
 
  
Which should print the height, width pairs the camera is capable of - in this case, 1280x1024 plus some smaller ones.[http://askubuntu.com/questions/214977/how-can-i-find-out-the-supported-webcam-resolutions/214990#214990]
+
$ v4l2-ctl -d /dev/video0 --list-ctrls
  
== Get software to use your webcam ==
+
=== Persisting configuration changes ===
  
Version 2.6.27 of the Linux kernel supports [http://mxhaard.free.fr/spca5xx.html many new webcam drivers].  Legacy Video4Linux API has been dropped, and these drivers now only support Video4Linux version 2. Pixel format decoding has been pushed to user space, since Video4Linux version 2 does not support kernel space decoding.  The libv4l library provides userland applications with pixel decoding services and will be used by most programs.  Other compatibility layers are also available.
+
Configuration made via V4L2 does not persist after the webcam is disconnected and reconnected. It's possible to use {{ic|v4l2-ctl}} with [[Udev]] rules in order to set some configuration each time a particular camera is connected.
  
'''If your device is created but your image looks strange (mine was nearly completely green), you probably need this.'''
+
For example, to set a default zoom setting on a particular Logitech webcam each time it is connected, add a [[Udev#udev_rule_example|udev rule]] like this:
  
If the application has V4L2 support but no pixelformat support (eg: cheese) then use the following command:
+
{{hc|/etc/udev/rules.d/99-logitech-default-zoom.rules|2=
LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so cheese
+
SUBSYSTEM=="video4linux", KERNEL=="video[0-9]*", ATTRS{product}=="HD Pro Webcam C920", ATTRS{serial}=="BBBBFFFF", RUN="/usr/bin/v4l2-ctl -d $devnode --set-ctrl=zoom_absolute=170"
 
 
If the application only supports the older version of V4L (Skype is the most popular of this kind of software) then use this command:
 
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
 
 
 
{{Tip|1=You also might want to put a line like the following into {{ic|/etc/profile}} or [[xprofile]] so you do not have to type that long command all the time:
 
{{bc|1=export LD_PRELOAD=/usr/'$LIB'/libv4l/v4l2convert.so}}
 
or
 
{{bc|1=export LD_PRELOAD=/usr/'$LIB'/libv4l/v4l1compat.so}}
 
 
}}
 
}}
  
For 32-bit applications (e.g. Skype) within Arch64, install the {{Pkg|lib32-v4l-utils}} package.
+
To find udev attributes like the product name and serial, see [[Udev#List the attributes of a device]]. It also possible to [[Udev#Setting static device names|set a static name for a video device]]).
  
If the webcam works fine on guvcview, but it does not work in Skype, you may also need to set
+
== Applications ==
export XLIB_SKIP_ARGB_VISUALS=1
 
before starting it.
 
  
=== Cheese ===
+
See also [[List of applications/Multimedia#Webcam]].
  
{{Pkg|cheese}} is the GNOME photo/video taking client. It is similar to Photo Booth in macOS. It is in the official repositories.
+
=== xawtv ===
  
{{Accuracy|{{Pkg|cheese}} depends on {{Pkg|clutter-gst2}}. The following is either outdated or indicates a packaging problem. {{Pkg|clutter-gst}} may still be required by other software.}}
+
This is a basic ''Video4Linux2'' device viewer, and although it is intended for use with TV tuner cards, it works well with webcams. It will display what your webcam sees in a window.
  
In case of the following error:
+
[[Install]] {{Pkg|xawtv}} and run it with:
 
+
$ xawtv -c /dev/video0
Error during camera setup: One or more needed GStreamer elements are missing: cluttervideosink.
 
 
 
First close cheese, then run the following commands:
 
 
 
# pacman -R clutter-gst
 
$ rm -r ~/.cache/gstreamer-1.0/
 
 
 
Then reopen cheese.
 
 
 
=== QtCAM ===
 
 
 
QtCAM is an Open Source Linux Webcam Software that enables users to capture/view videos/images from any USB camera or any V4L2 compatible device with attractive features such as Color space switching, Displaying Frame rates, over 10 image control settings and extension settings for select cameras.
 
 
 
=== fswebcam ===
 
 
 
fswebcam is a tiny and flexible webcam app which can be called from the command line. Install it from the [[official repositories]] as the package {{Pkg|fswebcam}}.
 
 
 
=== GTK+ UVC Viewer (guvcview) ===
 
 
 
In addition to being a convenient way to configure your webcam, [http://guvcview.sourceforge.net/ guvcview] also allows capturing (with sound!) and viewing video from devices supported by the Linux UVC driver. Available in the [[official repositories]] as package  {{Pkg|guvcview}}.  Just install it and launch, and it will present you a list of configurable settings. Changing these settings will affect all applications (e.g. Skype).
 
 
 
=== Kopete ===
 
 
 
Kopete is the [[KDE]] instant messaging (IM) client. As of KDE 3.5, it has support for MSN and Yahoo! webcams, but not every cam works yet. It is included in the kdenetwork package.
 
  
=== Kamoso ===
+
In case of error see [[#xawtv with nvidia card]].
 
 
Application to take pictures and videos out of your webcam for KDE.
 
 
 
* KDE4: {{Pkg|kamoso}}
 
* KDE Plasma 5: {{AUR|kamoso-git}}
 
 
 
=== xawtv ===
 
 
 
This is a basic v4l device viewer, and although it is intended for use with TV tuner cards, it works well with webcams. It will display what your webcam sees in a window. Install it ({{Pkg|xawtv}}) and run it with:
 
$ xawtv -c /dev/video0
 
If you are using an nVidia graphic card, and you get an error like
 
X Error of failed request:  XF86DGANoDirectVideoMode
 
  Major opcode of failed request:  139 (XFree86-DGA)
 
  Minor opcode of failed request:  1 (XF86DGAGetVideoLL)
 
  Serial number of failed request:  69
 
  Current serial number in output stream:  69
 
you should instead run it as:
 
$ xawtv -nodga
 
  
 
=== VLC ===
 
=== VLC ===
  
[[VLC]] can also be used to view and record your webcam. In VLC's file menu, open the 'Capture Device...' dialog and enter the video and audio device files. Or from the command line, do:
+
[[VLC]] can also be used to view and record your webcam. In VLC's "Media" menu, open the 'Capture Device...' dialog and enter the video and audio device files. Or from the command line, do:
  $ vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2"
+
  $ vlc v4l2:// :input-slave=alsa:// :v4l-vdev="/dev/video0"
This will make VLC mirror your webcam. To take stills, simply choose 'Snapshot' in the 'Video' menu. To record the stream, you add a {{ic|--sout}} argument, e.g.
+
This will make VLC mirror your webcam.
  $ vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" \
+
* To take stills, simply choose ''Snapshot'' in the ''Video'' menu.  
  --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}}"
+
* To record the stream, add a {{ic|--sout}} argument to the command line, e.g.
 +
  $ vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" --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}}"
  
(Obviously a bit overkill with regard to the bit rates but it is fine for testing purposes.) Notice that this will not produce a mirror on the display - in order to see what you are recording, you would need to add the display as a destination to the argument:
+
(Obviously a bit overkill with regard to the bit rates but it is fine for testing purposes). Note that by default this will not display the video, in order to see what you are recording, you need to add the display as a destination to the argument (note that it will slow down the operation):
  ... :duplicate{dst=display,dst=std{access= ....
+
  ... :duplicate{'''dst=display''',dst=std{access= ....
(Though this can tax older hardware somewhat...)
 
  
 
=== MPlayer ===
 
=== MPlayer ===
Line 280: Line 80:
 
To use [[MPlayer]] to take snapshots from your webcam run this command from the terminal:
 
To use [[MPlayer]] to take snapshots from your webcam run this command from the terminal:
 
  $ mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 15 -vf screenshot
 
  $ mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 15 -vf screenshot
From here you have to press {{ic|s}} to take the snapshot. The snapshot will be saved in your current folder as '''shotXXXX.png'''.
+
From here you have to press {{ic|s}} to take the snapshot. The snapshot will be saved in the current folder as {{ic|shotXXXX.png}}.
If you want to record continuous video:
+
If you want to record video continuous:
 
  $ mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o ''filename''.avi
 
  $ mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o ''filename''.avi
 
Press {{ic|Ctrl+c}} to end the recording.
 
Press {{ic|Ctrl+c}} to end the recording.
Line 287: Line 87:
 
=== mpv ===
 
=== mpv ===
  
To use [[mpv]] to take snapshots from your webcam run this command from the terminal:
+
To use [[mpv]] to take snapshots from your webcam, run this command from the terminal:
  $ mpv tv:// -tv driver=v4l2:device=/dev/video0
+
  $ mpv av://v4l2:/dev/video0
From here you have to press {{ic|s}} to take the snapshot. The snapshot will be saved in your current folder as '''mpv-shotNNNN.jpg'''.
 
  
=== FFmpeg ===
+
From here you have to press {{ic|s}} to take the snapshot. The snapshot will be saved in your current folder as {{ic|mpv-shot''NNNN''.jpg}}.
  
See [[FFmpeg#Recording webcam]].
+
To use MJPEG as the pixelformat instead of the default, which in most cases is YUYV, you can run the following instead:
 +
$ mpv --demuxer-lavf-format video4linux2 --demuxer-lavf-o-set input_format=mjpeg av://v4l2:/dev/video0
  
=== ekiga ===
+
In some cases this can lead to drastic improvements in quality and performance (5FPS -> 30FPS for example).
  
This is very similar to Microsoft NetMeeting. 
+
=== FFmpeg ===
Install the {{pkg|ekiga}} package from the official repositories.
 
The configuration druid will set everything up for you.
 
  
=== Sonic-snap ===
+
See [[FFmpeg#Recording webcam]].
  
{{AUR|sonic-snap}}{{Broken package link|{{aur-mirror|sonic-snap}}}} [http://www.stolk.org/sonic-snap/] is a viewer/grabber for sn9c102-based webcams '''only'''.
+
== Troubleshooting ==
  
=== Skype ===  
+
=== V4L1 support ===
  
The newest version of [[Skype]] has video support. Check Video Devices in the options for a test image which you can double-click to make full screen. Install the {{AUR|skype}} package.
+
Version 2.6.27 of the Linux kernel dropped support for the legacy Video4Linux (1) API. Pixel format decoding has been pushed to user space, since Video4Linux version 2 does not support kernel space decoding. The libv4l library provides userland applications with pixel decoding services and will be used by most programs. Other compatibility layers are also available.
If you get a green or disorted picture with skype read the section [[#Get software to use your webcam]] above.
 
  
If you're running x86-64 you might actually need to install {{Pkg|lib32-v4l-utils}} and then run skype with
+
'''If your device is created but your image looks strange (e.g. nearly completely green), you probably need this.'''
LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype
 
You can either set an alias for skype, or rename the original skype binary in {{ic|/usr/bin}} and create a text file containing the above option, or you can simply adjust the Command line in the options for the Skype icon in your favourite desktop environment.
 
  
=== Motion ===
+
If the application has V4L2 support but no pixelformat support then use the following command:
 +
LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so application
  
:''Motion is a program that monitors the video signal from cameras. It is able to detect if a significant part of the picture has changed; in other words, it can detect motion.''
+
If the application only supports the older version of V4L, use this command:
 +
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so application
  
{{Pkg|motion}} can only handle v4l2 devices so if you need to use a camera that only has v4l1 drivers you need to preload v4l1compat.so as previously mentioned. Otherwise you will get loads of errors about motion not able to find a suitable palette.
+
{{Tip|1=You also might want to put a line like the following into {{ic|/etc/profile}} or [[xprofile]] so you do not have to type that long command all the time:
 +
{{ic|1=export LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so}} or {{ic|1=export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so}}}}
  
{{Tip|If you need to load webcams in order (i.e. get the /dev/video0..n device order) or set ownership or permissions, take a look at writing rules for [[Udev#Writing udev rules|writing udev rules]].}}
+
For 32-bit [[multilib]] applications, install the {{Pkg|lib32-v4l-utils}} package and replace {{ic|/usr/lib/libv4l/}} by {{ic|/usr/lib32/libv4l/}} in the above commands.
  
=== MJPG-streamer ===
+
=== xawtv with nvidia card ===
 +
If you are using an nvidia graphic card, and get an error like
 +
X Error of failed request:  XF86DGANoDirectVideoMode
 +
  Major opcode of failed request:  139 (XFree86-DGA)
 +
  Minor opcode of failed request:  1 (XF86DGAGetVideoLL)
 +
  Serial number of failed request:  69
 +
  Current serial number in output stream:  69
 +
you should instead run it as {{ic|$ xawtv -nodga}}
  
{{AUR|mjpg-streamer}} takes JPGs from Linux-UVC compatible webcams, filesystem or other input plugins and streams them as M-JPEG via HTTP to webbrowsers, VLC and other software.
+
=== Microsoft Lifecam Studio/Cinema ===
 
 
== Troubleshooting ==
 
 
 
=== Microsoft Lifecam Studio/Cinema===
 
  
 
Under certain configurations, the Microsoft lifecam studio/cinema may request too much usb bandwidth and fail [http://www.ideasonboard.org/uvc/#footnote-13 see Uvcvideo FAQ]. In this case, change the buffering by loading the {{ic|uvcvideo}} driver with {{ic|1=quirks=0x80}}. Add it to {{ic|/etc/modprobe.d/uvcvideo.conf}} :
 
Under certain configurations, the Microsoft lifecam studio/cinema may request too much usb bandwidth and fail [http://www.ideasonboard.org/uvc/#footnote-13 see Uvcvideo FAQ]. In this case, change the buffering by loading the {{ic|uvcvideo}} driver with {{ic|1=quirks=0x80}}. Add it to {{ic|/etc/modprobe.d/uvcvideo.conf}} :
Line 338: Line 139:
  
 
{{Note|If delays are visible in the logs, or the camera works periodically, this workaround should apply generally. Bigger values such as {{ic|1=quirks=0x100}} are possible.}}
 
{{Note|If delays are visible in the logs, or the camera works periodically, this workaround should apply generally. Bigger values such as {{ic|1=quirks=0x100}} are possible.}}
 +
 +
=== Skype ===
 +
 +
When testing the webcam, note the following:
 +
* The echobot does not support videochat. Don't use it for testing your webcam.
 +
* Skype might recognize different video/camera devices (/dev/video*). These will be listed as something like "integrated camera..." in a dropdown menu in the camera settings. Try each camera and wait a few seconds, because it takes time to switch to a different camera.
 +
 +
=== Check bandwidth used by USB webcams ===
 +
 +
When running multiple webcams on a single USB bus, they may saturate the bandwidth of the USB bus and not work properly. You can diagnose this with the ''usbtop'' tool from the {{AUR|usbtop}} package.

Latest revision as of 23:39, 11 June 2019

This is a guide to setting up your webcam in Arch Linux.

Most probably your webcam will work out of the box. Permissions to access video devices (e.g. /dev/video0) are handled by udev, there is no configuration necessary.

Loading

Most recent webcams are UVC (USB Video Class) compliant and are supported by the generic uvcvideo kernel driver module. To check that your webcam is recognized, run dmesg just after you plug the webcam in. You should see something like this:

$ dmesg | tail
sn9c102: V4L2 driver for SN9C10x PC Camera Controllers v1:1.24a
usb 1-1: SN9C10[12] PC Camera Controller detected (vid/pid 0x0C45/0x600D)
usb 1-1: PAS106B image sensor detected
usb 1-1: Initialization succeeded
usb 1-1: V4L2 device registered as /dev/video0
usb 1-1: Optional device control through 'sysfs' interface ready
usbcore: registered new driver sn9c102

Some pre-UVC webcams are also supported via the gspca kernel driver module. See the gspca devices for a non-exhaustive list of supported devices under this framework.

Otherwise, if your webcam is not supported by the kernel's drivers, an external driver is necessary. The first step is to identify the name of the webcam, using for example lsusb. Then you can check webcam devices for information and resources about webcams. Once you find a driver compatible with the webcam, you have to add the corresponding kernel module in /etc/modules-load.d/webcam.conf so it will be loaded into the kernel during init stage bootstrapping.

Note: The Linux kernel to userspace API used to control webcams is named Video4Linux2, v4l2 for short. All applications which support v4l2 will work with the kernel's drivers.

Configuration

If you want to configure brightness, color and other webcam parameters (e.g. in the case when out-of-the-box colors are too bluish/reddish/greenish) you may use Qt V4L2 Test Bench. To run it, install v4l-utils and launch qv4l2, and it will present you a list of configurable settings. Changing these settings will affect all applications.

Command Line

v4l-utils also installs an equivalent command line tool, v4l2-ctl. To list all video devices:

$ v4l2-ctl --list-devices

To list the configurable settings of a video device:

$ v4l2-ctl -d /dev/video0 --list-ctrls

Persisting configuration changes

Configuration made via V4L2 does not persist after the webcam is disconnected and reconnected. It's possible to use v4l2-ctl with Udev rules in order to set some configuration each time a particular camera is connected.

For example, to set a default zoom setting on a particular Logitech webcam each time it is connected, add a udev rule like this:

/etc/udev/rules.d/99-logitech-default-zoom.rules
SUBSYSTEM=="video4linux", KERNEL=="video[0-9]*", ATTRS{product}=="HD Pro Webcam C920", ATTRS{serial}=="BBBBFFFF", RUN="/usr/bin/v4l2-ctl -d $devnode --set-ctrl=zoom_absolute=170"

To find udev attributes like the product name and serial, see Udev#List the attributes of a device. It also possible to set a static name for a video device).

Applications

See also List of applications/Multimedia#Webcam.

xawtv

This is a basic Video4Linux2 device viewer, and although it is intended for use with TV tuner cards, it works well with webcams. It will display what your webcam sees in a window.

Install xawtv and run it with:

$ xawtv -c /dev/video0

In case of error see #xawtv with nvidia card.

VLC

VLC can also be used to view and record your webcam. In VLC's "Media" menu, open the 'Capture Device...' dialog and enter the video and audio device files. Or from the command line, do:

$ vlc v4l2:// :input-slave=alsa:// :v4l-vdev="/dev/video0"

This will make VLC mirror your webcam.

  • To take stills, simply choose Snapshot in the Video menu.
  • To record the stream, add a --sout argument to the command line, e.g.
$ vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" --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}}"

(Obviously a bit overkill with regard to the bit rates but it is fine for testing purposes). Note that by default this will not display the video, in order to see what you are recording, you need to add the display as a destination to the argument (note that it will slow down the operation):

... :duplicate{dst=display,dst=std{access= ....

MPlayer

To use MPlayer to take snapshots from your webcam run this command from the terminal:

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

From here you have to press s to take the snapshot. The snapshot will be saved in the current folder as shotXXXX.png. If you want to record video continuous:

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

Press Ctrl+c to end the recording.

mpv

To use mpv to take snapshots from your webcam, run this command from the terminal:

$ mpv av://v4l2:/dev/video0

From here you have to press s to take the snapshot. The snapshot will be saved in your current folder as mpv-shotNNNN.jpg.

To use MJPEG as the pixelformat instead of the default, which in most cases is YUYV, you can run the following instead:

$ mpv --demuxer-lavf-format video4linux2 --demuxer-lavf-o-set input_format=mjpeg av://v4l2:/dev/video0

In some cases this can lead to drastic improvements in quality and performance (5FPS -> 30FPS for example).

FFmpeg

See FFmpeg#Recording webcam.

Troubleshooting

V4L1 support

Version 2.6.27 of the Linux kernel dropped support for the legacy Video4Linux (1) API. Pixel format decoding has been pushed to user space, since Video4Linux version 2 does not support kernel space decoding. The libv4l library provides userland applications with pixel decoding services and will be used by most programs. Other compatibility layers are also available.

If your device is created but your image looks strange (e.g. nearly completely green), you probably need this.

If the application has V4L2 support but no pixelformat support then use the following command:

LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so application

If the application only supports the older version of V4L, use this command:

LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so application
Tip: You also might want to put a line like the following into /etc/profile or xprofile so you do not have to type that long command all the time: export LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so or export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so

For 32-bit multilib applications, install the lib32-v4l-utils package and replace /usr/lib/libv4l/ by /usr/lib32/libv4l/ in the above commands.

xawtv with nvidia card

If you are using an nvidia graphic card, and get an error like

X Error of failed request:  XF86DGANoDirectVideoMode
 Major opcode of failed request:  139 (XFree86-DGA)
 Minor opcode of failed request:  1 (XF86DGAGetVideoLL)
 Serial number of failed request:  69
 Current serial number in output stream:  69

you should instead run it as $ xawtv -nodga

Microsoft Lifecam Studio/Cinema

Under certain configurations, the Microsoft lifecam studio/cinema may request too much usb bandwidth and fail see Uvcvideo FAQ. In this case, change the buffering by loading the uvcvideo driver with quirks=0x80. Add it to /etc/modprobe.d/uvcvideo.conf :

/etc/modprobe.d/uvcvideo.conf
## fix bandwidth issue for lifecam studio/cinema
options uvcvideo quirks=0x80
Note: If delays are visible in the logs, or the camera works periodically, this workaround should apply generally. Bigger values such as quirks=0x100 are possible.

Skype

When testing the webcam, note the following:

  • The echobot does not support videochat. Don't use it for testing your webcam.
  • Skype might recognize different video/camera devices (/dev/video*). These will be listed as something like "integrated camera..." in a dropdown menu in the camera settings. Try each camera and wait a few seconds, because it takes time to switch to a different camera.

Check bandwidth used by USB webcams

When running multiple webcams on a single USB bus, they may saturate the bandwidth of the USB bus and not work properly. You can diagnose this with the usbtop tool from the usbtopAUR package.