mercredi 25 janvier 2023

Disable webcam autofocus on Linux when plugin it in

/etc/udev/rules.d/99-logitech-webcam-c525.rules

# Disable auto focus for a Logitech C525 Webcam
#
# The focus keeps being off, so I have to set up to infinite. This requires to
# first disable the automatic focus, wait a bit and then set it to infinite.
#
# Attempt to disable and set the focus at the same time will fail with:
#
#   "invalid or incomplete multibyte or wide character"
#
# Which is the bug somewhere in the stack. A sleep works around it.
#
#
# For the udev conditional, you can get all variables using:
#
#   udevadm info -a -p $(udevadm info -q path -n /dev/video2)
#
# I have picked the device name rather than the identifier. Else for a Logitech
# HD Webcam C525 the rule would be:
#
#   ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0826",
#
ACTION=="add", \
  SUBSYSTEM=="video4linux", \
  ATTRS{name}=="HD Webcam C525", \
  ENV{ID_V4L_CAPABILITIES}==":capture:" \
  RUN+="/usr/bin/v4l2-ctl -d $env{DEVNAME} -c focus_automatic_continuous=0", \
  RUN+="/bin/sh -c '/bin/sleep 1 && /usr/bin/v4l2-ctl -d $env{DEVNAME} -c focus_absolute=0'"

Aucun commentaire: