OS: Ubuntu 20.04 (Focal Fossa)
I recently bought a Logitech c930e camera for use in online proctored exams where the invigilator may ask for a government-issued ID to be shown. The camera has an autofocus functionality which can initially focus on close objects (if one is placed in front of the camera as it is started), but once it shifts its focus to distant objects, it cannot re-detect and refocus on close objects subsequently placed in front of the camera. This causes the text on government-issued IDs placed in front of the camera to become illegible.
After some initial research, it turns out I can install v4l-utils
and obtain a list of parameters I can tune on the camera as follows (assuming the associated device node is /dev/video1
):
$ v4l2-ctl -d /dev/video1 --list-ctrls
Filtering the output to only include focus-related options gives:
$ v4l2-ctl -d /dev/video1 --list-ctrls | grep focus
focus_absolute 0x009a090a (int) : min=0 max=255 step=5 default=0 value=0 flags=inactive
focus_auto 0x009a090c (bool) : default=1 value=1
So focus_auto
is set to 1
and focus_absolute
to 0
by default, which can also be seen by running the following commands:
$ v4l2-ctl -d /dev/video1 --get-ctrl focus_auto
focus_auto: 1
$ v4l2-ctl -d /dev/video1 --get-ctrl focus_absolute
focus_absolute: 0
After some manual experimentation, it seems that focus_auto: 0
and focus_absolute: 75
gives a good balance of making close-up text clear enough while not blurring distant objects too much:
$ v4l2-ctl -d /dev/video1 --set-ctrl focus_auto=0
$ v4l2-ctl -d /dev/video1 --set-ctrl focus_absolute=75
So I write a udev rules file /etc/udev/rules.d/90-logitech-c930e.rules
for applying these settings:
KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0843", RUN+="/usr/bin/v4l2-ctl -d $devnode --set-ctrl focus_auto=0", RUN+="/usr/bin/v4l2-ctl -d $devnode --set-ctrl focus_absolute=75"
This file can also be found on GitHub
The idVendor: 046d
and idProduct: 0843
I obtained with lsusb
:
$ lsusb | grep Logitech
Bus 001 Device 002: ID 046d:0843 Logitech, Inc. Webcam C930e
Then I restart systemd-udevd.service
:
$ sudo systemctl restart systemd-udevd.service
Unplug the camera, and plug it back in. For the first few seconds, focus_auto
is set to 0
and focus_absolute
to 75
as expected:
$ v4l2-ctl -d /dev/video1 --get-ctrl focus_auto
focus_auto: 0
$ v4l2-ctl -d /dev/video1 --get-ctrl focus_absolute
focus_absolute: 75
But after a few dozen seconds at most, the settings are reverted to their defaults:
$ v4l2-ctl -d /dev/video1 --get-ctrl focus_auto
focus_auto: 1
$ v4l2-ctl -d /dev/video1 --get-ctrl focus_absolute
focus_absolute: 0
Why might that be? Is it possible to disable this behavior? If so, how?