Add shell code

This commit is contained in:
2021-08-22 23:18:49 +02:00
commit 21be937126
2 changed files with 21 additions and 0 deletions

3
Readme.md Normal file
View File

@@ -0,0 +1,3 @@
# brightness
Set the screen brightness using your camera.

18
brightness.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/env bash
# camera device
FFMPEG_DEVICE='/dev/video0'
# min brightness
MIN=50
# get max brightness
MAX=$(cat /sys/class/backlight/intel_backlight/max_brightness)
# sys path for backligt control
SET='/sys/class/backlight/intel_backlight/brightness'
# get grayscale and calculate brightness value for the screen
GET_GRAYSCALE=$(ffmpeg -i $FFMPEG_DEVICE -vf scale=1:1 -pix_fmt gray -f rawvideo -frames:v 1 -v quiet pipe:1)
AMBIENT=$(echo -n $GET_GRAYSCALE | od -t u | sed "s/000000[01]\s*//" | sed q)
BRIGHTNESS=$(( $AMBIENT * $MAX / 255 ))
# set brightness and limit boundaries
echo $(( $BRIGHTNESS > $MIN ? $BRIGHTNESS : $MIN )) | sudo tee $SET