Monday, November 24, 2008

Named UVC Web Cams

Let's say, hypothetically, that you have some UVC web cams. Like, 10 or 20. Normally, if you plug one in, it gets assigned the next free camera index: the first is created as /dev/video0, the second as /dev/video1, and so on. But if you want to always know exactly which video device is associated with each camera, this won't work very well.

By default, there is no equivalent to the /dev/disk/by-* directories. However, after some fumbling, I found this udev magic:
KERNEL=="video*", ATTRS{serial}=="835DE5C1", SYMLINK+="cam01"
Sticking one or more of these lines into /etc/udev/rules.d/10-webcam.rules means that when I plug in a camera with the specified serial number, /dev/cam01 will be created as a link to the appropriate /dev/video file. If that camera gets assigned to /dev/video1, then /dev/cam01 will be a link to /dev/video1.

How to figure out the serial number? You should be able to spot it in the dmesg file after you plug the camera in:
root@thorn 2> dmesg | grep -i serial
[ 3.618073] usb 1-1.1: SerialNumber: 23427691
Or you can probe a specific video device with:
root@thorn 5> udevinfo -a -p /sys/class/video4linux/video0 | grep -i serial
ATTRS{serial}=="23427691"

Blog Archive