February 12, 2022
Manually control a webcam using the command line on Linux
Any webcam compatible with the USB Video Class (UVC) standard should expose an API usable via v4l2-ctl
.
Use the following command to check which devices are connected to your computer at the moment.
v4l2-ctl --list-devices
To check the available controllers for your device, run:
v4l2-ctl --list-ctrls-menus
For me, this feature is specially useful for managing focus, brightness and sharpness. The following commands work well with Logitech C922 at least.
# Manual focus
v4l2-ctl -d /dev/video0 --set-ctrl=focus_auto=0 # default=1
v4l2-ctl -d /dev/video0 --set-ctrl=focus_absolute=0
# Manual light exposure controls
v4l2-ctl -d /dev/video0 --set-ctrl=exposure_auto=1 # default=3 (Aperture Priority Mode)
v4l2-ctl -d /dev/video0 --set-ctrl=exposure_absolute=166 # min=12 max=664 default=166
# Brightness and other useful controls
v4l2-ctl -d /dev/video0 --set-ctrl=sharpness=170 # default=128
v4l2-ctl -d /dev/video0 --set-ctrl=brightness=150 # default=128
v4l2-ctl -d /dev/video0 --set-ctrl=backlight_compensation=1 # default=0