Ställa in kameran
Postat: 03 dec 2021, 05:37
Det senaste har jag deltagit i ett antal intervjuer och andra möten via Teams och då upptäckt att det finns rätt dåliga möjligheter att ställa in kameran i Ubuntu.
Så därför har jag hackat ihop ett litet script som förenklar det, lite iaf:Själva scriptet kallar jag för "cam" och för att snabbt kunna ändra flera inställningar, har jag ett script jag kallar för "camset":Vilka inställningar man själv vill ha, är givetvis subjektivt och man kan också ha flera versioner av "camset", med olika namn....
Hoppas någon kan ha nytta av det...
Så därför har jag hackat ihop ett litet script som förenklar det, lite iaf:
Kod: Markera allt
#! /bin/bash
#
#####################################################################
#
function usage {
cat << EOD
usage: cam { all | help | list | reset | set | show }
all
print all info (approximately "info"+"list")
help | -h | --help
show this
info
show info about the camera
list | show
lists the settings for available cameras
reset
reset the camera to its default settings
set [param=value]
set any of the parameters shown by "list" or "show" to a value,
as long as it is between MIN and MAX.
EOD
exit
}
#
#####################################################################
#
TEMP=`getopt -oh --long help -n $(basename $0) -- "$@"`
if [[ $? -ne 0 ]]; then
usage
fi
eval set -- "$TEMP"
HELP=false
CMDNAME=$(basename $0)
while true; do
case $1 in
-h|--help)
usage
exit
;;
--)
shift
break
;;
*)
echo "-Got a star... [$1]"
exit
;;
esac
done
FUNCTION=$1
PARAMVAL=$2
#
#####################################################################
#
if [[ -z $(which which v4l2-ctl) ]]; then
echo
read -p "v4l2-ctl is not installed, do you want to install it? [y/N]: " IN
if [[ $IN == "y" || $IN == "Y" ]]; then
apt-get -y --allow-downgrades --allow-remove-essential --allow-change-held-packages --allow-unauthenticated install v4l-utils
else
echo
exit
fi
fi
#
WRITTEN=false
VIDEOS=$(v4l2-ctl --list-devices 2> /dev/null | grep /dev/video)
if [[ $? != 0 ]]; then
echo
echo "-Can not find any camera device..."
echo
exit
fi
for VIDEO in $VIDEOS; do
OUT=$(v4l2-ctl -d $VIDEO --list-ctrls)
if [[ ! -z $OUT ]]; then
WRITTEN=true
echo
echo $VIDEO
if [[ $FUNCTION == "help" ]]; then
usage
elif [[ $FUNCTION == "all" ]]; then
v4l2-ctl -d $VIDEO --all
elif [[ $FUNCTION == "info" ]]; then
v4l2-ctl -d $VIDEO --info
elif [[ $FUNCTION == "list" || $FUNCTION == "show" ]]; then
v4l2-ctl -d $VIDEO --list-ctrls-menus
elif [[ $FUNCTION == "set" ]]; then
if [[ ! -z $PARAMVAL ]]; then
PARAM=$(echo $PARAMVAL | awk -F = '{ print $1 }')
VALUE=$(echo $PARAMVAL | awk -F = '{ print $2 }')
if [[ -z $VALUE ]]; then
echo "-$PARAM has no value..."
echo
exit
fi
LINE=$(v4l2-ctl -d $VIDEO --list-ctrls-menus | grep "$PARAM ")
NAME=$(echo $LINE | awk '{ print $1 }' | xargs)
REST=$(echo $LINE | awk '{ $1=""; print $0 }' | xargs)
IFS=" "
for PARAM in $REST; do
if [[ ! -z $(echo $PARAM | grep "default=") ]]; then
DEFAULT=$(echo $PARAM | awk -F = '{ print $2 }')
elif [[ ! -z $(echo $PARAM | grep "min=") ]]; then
MIN=$(echo $PARAM | awk -F = '{ print $2 }')
elif [[ ! -z $(echo $PARAM | grep "max=") ]]; then
MAX=$(echo $PARAM | awk -F = '{ print $2 }')
fi
done
if [[ $VALUE -gt $MAX ]]; then
echo "-Value $VALUE is greater than MAX..."
elif [[ $VALUE -lt $MIN ]]; then
echo "-Value $VALUE is less than MIN..."
else
echo "v4l2-ctl --device $VIDEO --set-ctrl $PARAMVAL"
v4l2-ctl --device $VIDEO --set-ctrl $PARAMVAL
fi
else
echo "-Can not set $VIDEO to nothing..."
fi
elif [[ $FUNCTION == "reset" ]]; then
LINES=$(v4l2-ctl -d $VIDEO --list-ctrls | awk '{ $2=""; $3=""; $4=""; print $0 }')
IFS='
'
for LINE in $LINES; do
NAME=$(echo $LINE | awk '{ print $1 }' | xargs)
REST=$(echo $LINE | awk '{ $1=""; print $0 }' | xargs)
IFS=" "
for PARAM in $REST; do
if [[ ! -z $(echo $PARAM | grep "value=") ]]; then
VALUE=$(echo $PARAM | awk -F = '{ print $2 }')
elif [[ ! -z $(echo $PARAM | grep "default=") ]]; then
DEFAULT=$(echo $PARAM | awk -F = '{ print $2 }')
elif [[ ! -z $(echo $PARAM | grep "min=") ]]; then
MIN=$(echo $PARAM | awk -F = '{ print $2 }')
elif [[ ! -z $(echo $PARAM | grep "max=") ]]; then
MAX=$(echo $PARAM | awk -F = '{ print $2 }')
fi
done
PARAMVAL="$NAME=$DEFAULT"
if [[ $VALUE != $DEFAULT ]]; then
echo "v4l2-ctl --device $VIDEO --set-ctrl $PARAMVAL"
v4l2-ctl --device $VIDEO --set-ctrl $PARAMVAL
fi
IFS='
'
done
fi
fi
done
if [[ $WRITTEN == true ]]; then
echo
fi
Kod: Markera allt
#! /bin/bash
#
cam set brightness=110
cam set contrast=30
cam set saturation=20
cam set hue=200
cam set gamma=200
cam set backlight_compensation=50
Hoppas någon kan ha nytta av det...
