#!/bin/bash # Configure a Logitech webcam (and possibly others) from the commandline. # USAGE: logitech <-d DEVICE> [-e EXPOSURE] [-g GAIN] [-t TEMPERATURE] [-f FOCUS] # DEVICE should be a device number as used by `v4l2-ctl`. This is usually 0 if # there's only one webcam connected. # NOTE: when one of the parameters is set, auto-setting it by the webcam is # disabled. # # Getting device info: # v4l2-ctl -d --all device= exposure= gain= temperature= focus= while getopts 'd:e:g:t:f:' flag; do case "${flag}" in d) device=$OPTARG ;; e) exposure=$OPTARG ;; g) gain=$OPTARG ;; t) temperature=$OPTARG ;; f) focus=$OPTARG ;; *) error "Unexpected option ${flag}" ;; esac done if [ -z "$device" ]; then echo "Provide device with -d flag" exit 1 fi if [ -n "$exposure" ]; then v4l2-ctl -d "$device" --set-ctrl auto_exposure=1 v4l2-ctl -d "$device" --set-ctrl exposure_time_absolute="$exposure" fi if [ -n "$gain" ]; then v4l2-ctl -d "$device" --set-ctrl gain="$gain" fi if [ -n "$temperature" ]; then v4l2-ctl -d "$device" --set-ctrl white_balance_automatic=0 v4l2-ctl -d "$device" --set-ctrl white_balance_temperature="$temperature" fi if [ -n "$focus" ]; then v4l2-ctl -d "$device" --set-ctrl focus_automatic_absolute=0 v4l2-ctl -d "$device" --set-ctrl focus_absolute="$focus" fi