Using UDEV rules to set a static location for /dev/vid* devices

Ubuntu will often assign a USB device to a new address after each re-plug of the device or reboot of the host.

The problem:

When USB devices are reconnected or the system restarted, video devices are assigned to a /dev/vid* device path.

This path can vary, therefore creating issues when wanting to use static paths in applications that might utilise this stream

The solution:

To configure UDEV rules that create static /dev/cams/cam* objects

  1. Create a new rule in /etc/udev/rules.d/ (name the rule file what you want)
    sudo nano /etc/udev/rules.d/99-cam.rules
  2. Write the file in the form:
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", ATTR{index}=="0", MODE="0664", GROUP="video", SYMLINK+="cams/camZ"

Make sure to fill in vendor ID< product ID and path (XXX,YYY,Z)

SUBSYSTEM=="video4linux", ATTRS{idVendor}=="1908", ATTRS{idProduct}=="2311", ATTR{index}=="0", MODE="0664", GROUP="video", SYMLINK+="cams/cam1"
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="045e", ATTRS{idProduct}=="0761", ATTR{index}=="0", MODE="0664", GROUP="video", SYMLINK+="cams/cam2"
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="1dfc", ATTRS{idProduct}=="8513", ATTR{index}=="0", MODE="0664", GROUP="video", SYMLINK+="cams/cam3"

As can be seen in my code above, I have 3 mappings that look for the particular hardware and map to cams/camZ

This creates nice static paths I can use when my devices are unplugged or the system restarted.