Assign webcam to a specific /dev/video#

Assign webcam to a specific /dev/video#
Ask Question
Asked 3 years, 10 months ago
Active 3 years, 10 months ago
Viewed 11k times

I have three webcams on my Ubuntu server 14.04. The output of lsusb:

Bus 006 Device 002: ID 0bda:8153 Realtek Semiconductor Corp.
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 003: ID 2537:1066
Bus 004 Device 002: ID 05e3:0616 Genesys Logic, Inc.
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 005: ID 1871:0101 Aveo Technology Corp. UVC camera (Bresser microscope)
Bus 003 Device 004: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 003 Device 003: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 003 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 005: ID 046d:0807 Logitech, Inc. Webcam B500
Bus 001 Device 004: ID 1871:0101 Aveo Technology Corp. UVC camera (Bresser microscope)
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I want to assign a specific /dev/video# to each one. I have read that I have to create a udev rule in /etc/udev/rules.d/, but most of what I’ve read seems outdated and I don’t want to cause problems to my server. I was thinking of creating a 25-name-video-devices.rules containing the following:

SUBSYSTEM==“video4linux”, BUS==“usb”, SYSFS{idVendor}“1871”, SYSFS{idProduct}“0101”, NAME=“video10”
SUBSYSTEM==“video4linux”, BUS==“usb”, SYSFS{idVendor}“1871”, SYSFS{idProduct}“0101”, NAME=“video11”
SUBSYSTEM==“video4linux”, BUS==“usb”, SYSFS{idVendor}“046d”, SYSFS{idProduct}“0807”, NAME=“video12”

The additional problem I have is that 2 of the 3 webcams seem identical (although they are not, they are bought from ebay and they are used to monitor a different area). So what would be the rules for my case? Thanks
webcam udev
shareimprove this question
asked Dec 31 '15 at 9:57
bomberb17
6511 gold badge11 silver badge88 bronze badges
add a comment
1 Answer

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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值