Skip to content

Instantly share code, notes, and snippets.

@jpetazzo
Created September 14, 2020 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpetazzo/33c623e8d0b694985ddf30688ca3c573 to your computer and use it in GitHub Desktop.
Save jpetazzo/33c623e8d0b694985ddf30688ca3c573 to your computer and use it in GitHub Desktop.
Force focus on webcams (because autofocus is 💩 sometimes)
#!/bin/sh
setcam() {
FOCUS=$1
echo "Configuring camera $NAME on /dev/$DEV."
echo "Setting fixed focus to $FOCUS."
v4l2-ctl --device /dev/$DEV -c focus_auto=0
v4l2-ctl --device /dev/$DEV -c focus_absolute=$FOCUS
echo "Setting power line frequency to 50Hz."
v4l2-ctl --device /dev/$DEV -c power_line_frequency=1
}
cd /sys/class/video4linux
for DEV in *; do
# Only work with device index=0
# (the other indexes are typically metadata devices,
# we don't care about them)
grep -q ^0$ $DEV/index || continue
NAME=$(cat $DEV/name)
case $NAME in
"HD Pro Webcam C920")
setcam 30
;;
"Logitech StreamCam")
setcam 20
;;
"Razer Kiyo")
setcam 180
;;
*)
echo "Skipping unknown camera $NAME on /dev/$DEV."
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment