I have two identical USB HDMI capture devices and want to be able to distinguish between them.
Following the stackexchange answer here I created the following rules file which is based on their USB addresses:
# cat /etc/udev/rules.d/20-roger-video.rules
SUBSYSTEM=="video4linux", KERNELS=="1-1.3", ATTRS{idProduct}=="2109", ATTRS{idVendor}=="534d" SYMLINK+="roger/vid0"
SUBSYSTEM=="video4linux", KERNELS=="1-2.2.3", ATTRS{idProduct}=="2109", ATTRS{idVendor}=="534d" SYMLINK+="roger/vid1"
Then we see (for example):
# ls -l /dev/roger/
total 0
lrwxrwxrwx 1 root root 9 Sep 28 19:49 vid0 -> ../video2
lrwxrwxrwx 1 root root 9 Sep 28 19:49 vid1 -> ../video4
Here, vid0
and vid1
are tied to the USB addresses, but video2
and video4
are changeable, and cannot be guaranteed to always refer
to the same device.
However - this is not sufficient as plugging the capture device
creates two device files under /dev
, for example /dev/video0
and
/dev/video1
the first time. We only want the first of these, so we
need to add ATTR{index}=="0"
to the rules. Reference
here.
Final working version:
# cat /etc/udev/rules.d/20-roger-video.rules
SUBSYSTEM=="video4linux", KERNELS=="1-1.3", ATTRS{idProduct}=="2109", ATTRS{idVendor}=="534d" ATTR{index}=="0" SYMLINK+="roger/vid0"
SUBSYSTEM=="video4linux", KERNELS=="1-2.2.3", ATTRS{idProduct}=="2109", ATTRS{idVendor}=="534d" ATTR{index}=="0" SYMLINK+="roger/vid1"
Getting the components of the rules
As mentioned in the article referenced above we can use a command like
udevadm info -a -p $(udevadm info -q path -n /dev/video2)
Then, to get the components for the device that is currently /dev/video2
:
# udevadm info -a -p $(udevadm info -q path -n /dev/video2) | grep KERNELS | awk 'NR==2'
KERNELS=="1-1.3"
# udevadm info -a -p $(udevadm info -q path -n /dev/video2) | grep idProduct | awk 'NR==1'
ATTRS{idProduct}=="2109"
# udevadm info -a -p $(udevadm info -q path -n /dev/video2) | grep idVendor | awk 'NR==1'
ATTRS{idVendor}=="534d"
# udevadm info -a -p $(udevadm info -q path -n /dev/video2) | grep index
ATTR{index}=="0"
Displaying the captured video
I had problems with such programs as webcamoid, kamoso, that did not seem to want to accept multiple config files, or correctly take device names on the command line.
Mplayer seems fine with command lines such as:
mplayer tv:// -tv driver=v4l2:device=/dev/roger/vid0:width=1920:height=1080
mplayer tv:// -tv driver=v4l2:device=/dev/roger/vid1:width=1920:height=1080