Assign webcam to a specific /dev/video#

Solution without Udev Rules

There is a chance that video4linux has already provided you with stable device names. You may want to check the directories /dev/v4l/by-id/ and /dev/v4l/by-path/ for this. Connect your devices to different USB ports and compare the created device names to make sure that they are really stable.

Solution with Udev Rules

Otherwise it depends on whether your two seemingly identical devices do at least have a different serial number which is accessible by udev. You can find this out by using the correct “Bus” and “Device” number from your lsusb output in the following command:

udevadm info --attribute-walk /dev/bus/usb/003/005

If there is some kind of output like the following in the first block of key/value pairs and the serial is different between the two devices, then you may use that in your udev rules:

ATTR{serial}=="68974689267119892"

Your udev rules could then look like this:

SUBSYSTEM=="usb", ATTR{serial}=="68974689267119892", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video10"
SUBSYSTEM=="usb", ATTR{serial}=="12345698798725654", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video11"
SUBSYSTEM=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="0807", NAME="video12"

If there is no serial (or similar unique) number, then I only see the following possibility: you would have to make sure that your devices always remain connected at the same USB ports. In that case you could use rules like these:

SUBSYSTEM=="usb", KERNEL=="2-3", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video10"
SUBSYSTEM=="usb", KERNEL=="2-4", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", NAME="video11"
SUBSYSTEM=="usb", KERNEL=="2-2", ATTR{idVendor}=="046d", ATTR{idProduct}=="0807", NAME="video12"

You would have to find out which KERNEL IDs to use by again running the udevadm command mentioned above and looking for the KERNEL key/value pair.

Minor Notes

It may be nicer/better to only create new symlinks instead of new device names, and maybe even grouping them under a common directory:

SUBSYSTEM=="usb", KERNEL=="2-3", ATTR{idVendor}=="1871", ATTR{idProduct}=="0101", SYMLINK+="foo/video10"

The previous rule, for example, would create a device symlink at /dev/foo/video10.

I would probably also simply name the rules file name-video-devices.rules, i.e., leaving the leading number out. It probably doesn’t matter when the rules are executed, so no need to use a (rather high) priority of 25.