multiple /dev/video for one physical device

Asked by kris

Since upgrading from ubuntu 16.04 to 18.04 (kernel 4.15 generic) to 18.04 (kernel 5) v4l2 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.

`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
```
I see someone has a similar question on stack exchange:
https://unix.stackexchange.com/questions/512759/multiple-dev-video-for-one-physical-device

I'm using Ubuntu 18.04 with kernel `5.0.0-27-generic`

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", ATTR{index}=="0", ATTRS{idProduct}=="708c", SYMLINK+="v4l/hd_cam"
```

Any input would be greatly appreciated

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
kris
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

Does the system have a make and model?
Does the webcam have a make and model?

Revision history for this message
kris (leonhardeuler2718) said :
#2

@actionparnsip:

Thanks for the response.

I have several different cameras plugged in (all exhibiting the same behavior).

One we can focus on is a Logitech C920 as this is a fairly common camera.

As for my setup, I'm using an Asus ROG GL503V.

But again, I have seen this behavior on multiple different machines. The stack exchange post I shared in my original message indicates they're using an HP.

I found another post on Ask Ubuntu, similar problem on a Dell.

https://askubuntu.com/questions/1123601/four-dev-video-entries-but-just-one-camera

Unfortunately the answer accepted by the person who posted this question, doesn't address why v4l is reporting multiple /dev/video devices per physical device.

I hope this helps. Please let me know if I can provide additional information.

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

What is the real problem?
- the fact that two device entries (e.g. /dev/video0 and /dev/video1) are created, or
- the fact that you do not know which one to use für your applications?

Does one of the commands listed on the askubuntu page(e.g. "v4l2-ctl --device=/dev/video* --all", "cat /sys/class/video4linux/video*/...") help idetifying the right one?

Revision history for this message
kris (leonhardeuler2718) said :
#4

Thanks for the response m-hampl

The real problem is I'm unable to reliably open video streams from cameras I've connected to via udev aliases in 18.04, a method which worked in 16.04.

I am assuming (which could be wrong), that this is due to the multiple indexes per physical device.

From testing multiple times, I know the first index can stream video, the second index cannot.

This behavior is consistent across multiple cameras, multiple reboots, and multiple unplug/plug in of the physical device.

I have tried to write a custom udev rule which aliases the 1st index of the device. However this has not been successful in resolving the problem. Again, that udev rule is:

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

I have investigated the various device entries (e.g. /dev/video0, /dev/video1) like you mentioned, and it seems to confirm what I have experienced in testing with OpenCV, vlc, etc. That the first index is capable of video streaming, but the second is not.

Here are the results from running `v4l2-ctl --device=/dev/video* --all`. Specifically this is from 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
```

As you can see, the second index has considerably less information than the first. Noticeably missing from the Device Caps section is Video Capture.

I hope that helps. Please let me know if I can provide any more clarification, or more details.

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

According to https://www.mythtv.org/wiki/Device_Filenames_and_udev you can use wild cards in udev rules. This should allow selecting the first one. Have you tried something like

KERNEL=="video[02468]", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="0458", ATTRS{idProduct}=="708c", SYMLINK+="v4l/hd_cam"

Revision history for this message
kris (leonhardeuler2718) said :
#6

@m-hampl.

Thank you very much for the input. I've gone ahead and implemented your suggestion. This looks like it has worked for me. I will mark this problem solved.