multiple /dev/video devices for 1 camera causing issue with udev rules

Since upgrading from ubuntu 16.04 (kernel 4.15.0-60-generic) to 18.04 (kernel 5.0.0-27-generic) v4l now returns multiple /dev/video devices per physical device. This causes issues when trying to map video devices to aliases using udev rules. One of the /dev/video devices can stream video, the other cannot. The udev alias I've created does not seem to consistently choose the correct /dev/video index (the one with streaming capabilities).

I know this post is very similar to this:

Four /dev/video entries but just one camera

However, the accepted answer (bug with skype) does not adequately address the udev issue I'm experiencing.

I see someone has a similar question on stack exchange:

https://unix.stackexchange.com/questions/512759/multiple-dev-video-for-one-physical-device

However, no answer has been accepted.

Additional Information:

Computer make/model: Asus ROG GL503V

Webcam make/model: Genius WideCam F100, Logitech C920, and more.

v4l2-ctl --list-devices

returns:

USB2.0 PC CAMERA: USB2.0 PC CAM (usb-0000:00:14.0-11):
 /dev/video4
 /dev/video5

USB_Camera: USB_Camera (usb-0000:00:14.0-3):
 /dev/video0
 /dev/video1

HD Pro Webcam C920 (usb-0000:00:14.0-4.1):
 /dev/video6
 /dev/video7

USB2.0 HD UVC WebCam: USB2.0 HD (usb-0000:00:14.0-7):
 /dev/video2
 /dev/video3

Here's a detailed look at the Genius WideCam F100:

user@AsusROG:~$ sudo v4l2-ctl --list-devices
USB_Camera: USB_Camera (usb-0000:00:14.0-3):
    /dev/video0
    /dev/video1

USB2.0 HD UVC WebCam: USB2.0 HD (usb-0000:00:14.0-7):
    /dev/video2
    /dev/video3

user@AsusROG:~$ sudo v4l2-ctl --device=/dev/video0 --all
Driver Info (not using libv4l2):
    Driver name   : uvcvideo
    Card type     : USB_Camera: USB_Camera
    Bus info      : usb-0000:00:14.0-3
    Driver version: 5.0.21
    Capabilities  : 0x84A00001
        Video Capture
        Metadata Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps   : 0x04200001
        Video Capture
        Streaming
        Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height      : 640/480
    Pixel Format      : 'YUYV'
    Field             : None
    Bytes per Line    : 1280
    Size Image        : 614400
    Colorspace        : sRGB
    Transfer Function : Default (maps to sRGB)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization      : Default (maps to Limited Range)
    Flags             : 
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 640, Height 480
    Default     : Left 0, Top 0, Width 640, Height 480
    Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 640, Height 480
Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480
Streaming Parameters Video Capture:
    Capabilities     : timeperframe
    Frames per second: 30.000 (30/1)
    Read buffers     : 0
                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=95 step=1 default=32 value=32
                     saturation 0x00980902 (int)    : min=0 max=100 step=1 default=55 value=55
                            hue 0x00980903 (int)    : min=-2000 max=2000 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=100 max=300 step=1 default=165 value=165
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=10 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=1 max=7 step=1 default=2 value=2
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
              exposure_absolute 0x009a0902 (int)    : min=50 max=10000 step=1 default=166 value=166 flags=inactive
user@AsusROG:~$ sudo v4l2-ctl --device=/dev/video1 --all
Driver Info (not using libv4l2):
    Driver name   : uvcvideo
    Card type     : USB_Camera: USB_Camera
    Bus info      : usb-0000:00:14.0-3
    Driver version: 5.0.21
    Capabilities  : 0x84A00001
        Video Capture
        Metadata Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps   : 0x04A00000
        Metadata Capture
        Streaming
        Extended Pix Format
Priority: 2

Here's the versions of various v4l packages I have installed:

ii libv4l-0:amd64 1.14.2-1 amd64 Collection of video4linux support libraries
ii libv4l-dev:amd64 1.14.2-1 amd64 Collection of video4linux support libraries (development files)
ii libv4l2rds0:amd64 1.14.2-1 amd64 Video4Linux Radio Data System (RDS) decoding library
ii libv4lconvert0:amd64 1.14.2-1 amd64 Video4linux frame format conversion library
ii v4l-utils 1.14.2-1 amd64 Collection of command line video4linux utilities

here's an excerpt from lsusb:

Bus 001 Device 017: ID 0458:708c KYE Systems Corp. (Mouse Systems) Genius WideCam F100

and the associated udev rule:

KERNEL=="video?", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="0458", ATTRS{index}=="0", ATTRS{idProduct}=="708c", SYMLINK+="v4l/hd_cam"

Any input would be greatly appreciated


Solution 1:

As noticed in this related question, the value of ATTR{index} differs when the device is the real cam or only metadata. One should use the rule ATTR{index}=="0" to get the real device.