Linux – How to map /sys/bus/usb/devices to /dev/video*

deviceslinuxsysfsusbvideo

I am using a library (librealsense) that only outputs the bus and port number as such (9.1). It uses libusb internally. The issue is from this identifier in libusb I want to know what physical device it belongs to in /dev/video0. For instance, 9.1 -> /dev/video0 and 7.2 -> /dev/video2 when two cameras are plugged in in ports 9.1 and 7.2.

Is this possible? How do I acquire what devices paths belong to a bus and port? Any partial answer would be helpful.

Best Answer

Answering so I can close this question full credit to @ridgy and @dirkt for their help. With the command:

udevadm info -n video0 -q path

Or similarly with ls -l /sys/class/video4linux/, a path of the form /devices/pci0000:00/0000:00:10.0/usb7/7-2/7-2:1.0/video4linux/video0 can be found. That in combination with the listing of the video devices using either ls /dev/video* or v4l2-ctl --list-devices allows a map between the usb port and video device to be created.

Related Question