Udev Webcam

Friday, April 1, 2022 · 1 minute · 184 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 :

1sudo apt install v4l-utils

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

1lsusb | grep -i Webcam
2
3# 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

1# -- always links to /dev/video99 
2
3SUBSYSTEM=="video4linux", KERNELS=="1-8", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="082d", SYMLINK+="video99"
4
5# -- set power line to 50HZ
6
7SUBSYSTEM=="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 :

1sudo udevadm control --reload-rules && sudo udevadm trigger
Linux Howto