Webcam: Difference between revisions

From Leo's Notes
This page was last edited on 5 March 2017, at 23:49.
m Text replacement - "</code>" to "}}"
No edit summary
Line 5: Line 5:
The default permissions set to {{code|/dev/video0}} is set by udev. If you need to change the device permissions (say making it world read/writable), you will need to create a udev rule by creating a new file in {{code|/etc/udev/rules.d/}} with the following contents:
The default permissions set to {{code|/dev/video0}} is set by udev. If you need to change the device permissions (say making it world read/writable), you will need to create a udev rule by creating a new file in {{code|/etc/udev/rules.d/}} with the following contents:


<syntaxhighlight lang="text">
{{highlight|lang=text|code=
SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="045e", SYSFS{idProduct}=="0761", NAME="video0", MODE="0666"
SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="045e", SYSFS{idProduct}=="0761", NAME="video0", MODE="0666"
</syntaxhighlight>
}}


The Vendor ID and product ID must match the values from {{code|lsusb}}. For the example above (a Microsoft LifeCam VX-2000):
The Vendor ID and product ID must match the values from {{code|lsusb}}. For the example above (a Microsoft LifeCam VX-2000):
# lsusb
{{highlight|lang=terminal|code=
Bus 001 Device 005: ID 045e:0761 Microsoft Corp.
# lsusb
Bus 001 Device 005: ID 045e:0761 Microsoft Corp.
}}




=== Capturing Utilities/Daemons ===
To capture images, use any one of the following utilities:
To capture images, use any one of the following utilities:
* fswebcam
* [[motion]]
* [[fswebcam]]
* uvccapture
* uvccapture


You may configure the webcam settings using {{code|v4l-utils}}. See http://www.techytalk.info/webcam-settings-control-ubuntu-fedora-linux-operating-system-cli/
My Raspberry Pis use [[motion]] to automatically capture snapshots periodically to a NFS share.


=== fswebcam ===
=== Configuration ===
fswebcam -r 640x480 --jpeg 85 -D 1 web-cam-shot.jpg
You may configure the webcam settings using {{code|v4l-utils}}.


==== Dumping fswebcam images via HTTP ====
See Also:
You can make a quick an dirty wrapper around the command above so that it can be viewed via the web.
* http://www.techytalk.info/webcam-settings-control-ubuntu-fedora-linux-operating-system-cli/
 
<syntaxhighlight lang="php">
<?php
 
system("fswebcam -r 640x480 --jpeg 85 -D 1 /tmp/out.jpg > /dev/null");
header("Content-Type: image/jpeg");
echo file_get_contents("/tmp/out.jpg");
</syntaxhighlight>
 
 
=== uvccapture ===
Another utility to capture webcam images is {{code|uvccapture}}.




[[Category:Linux]]
[[Category:Linux]]
{{Navbox Linux}}
{{Navbox Linux}}

Revision as of 23:49, 5 March 2017

Linux

To get a webcam working for Linux, ensure that it's supported. Newer webcams tend to have support though cheaper non-HD webcams from China might not. You should see a /dev/video0 device when the webcam is plugged into the computer. If not, check dmesg and see if the USB device is being detected. lsusb should also list it.

The default permissions set to /dev/video0 is set by udev. If you need to change the device permissions (say making it world read/writable), you will need to create a udev rule by creating a new file in /etc/udev/rules.d/ with the following contents:

SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="045e", SYSFS{idProduct}=="0761", NAME="video0", MODE="0666"

The Vendor ID and product ID must match the values from lsusb. For the example above (a Microsoft LifeCam VX-2000):

# lsusb
Bus 001 Device 005: ID 045e:0761 Microsoft Corp.


Capturing Utilities/Daemons

To capture images, use any one of the following utilities:

My Raspberry Pis use motion to automatically capture snapshots periodically to a NFS share.

Configuration

You may configure the webcam settings using v4l-utils.

See Also: