Udev Webcam

Friday, April 1, 2022 · 1 minute · 180 words

You can change the device link so your webcam will be always accessible at the same location /dev/video99. You can also persist some settings via the v4l-ctl command.

We will need the v4l2-ctl utility from the “v4l-utils” package :

sudo apt install v4l-utils

First, let’s get the vendor and product id from the lsusb command :

lsusb | grep -i Webcam

# Bus 001 Device 014: ID 046d:082d Logitech, Inc. HD Pro Webcam C920

Information are located after the ID keyword as “vendor:product”. In this case, the idVendor=046d and the idProduct=082d.

Then edit an udev rules file as root (sudo) : /etc/udev/rules.d/99-webcam.rules

# -- always links to /dev/video99 

SUBSYSTEM=="video4linux", KERNELS=="1-8", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="082d", SYMLINK+="video99"

# -- set power line to 50HZ

SUBSYSTEM=="video4linux", KERNELS=="1-8", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="082d", RUN+="/usr/bin/v4l2-ctl -d $devnode -c power_line_frequency=1"

We need to target the “video4linux” subsystem because the “usb” is to high in the hierarchie.

Note: you can not change the webcam device name, that is why we set a new link.

You can finally restart udev without rebooting your linux :

sudo udevadm control --reload-rules && sudo udevadm trigger
linux howto