#!/bin/bash x=320 # y=240 # n=1000 # ( 0 x*y) - N max=40 # "" ( 0 255) sleep=60 #, maxbright=100 # minbright=20 # while [ 1 ]; do # ffmpeg -f video4linux2 -s ${x}x${y} -i /dev/video0 -f image2 /tmp/snapshot.jpg 2>/dev/null # convert /tmp/snapshot.jpg -colorspace gray /tmp/snapshot.jpg # sum=0 count=0 let "s = x*y" # color=(`convert /tmp/snapshot.jpg[${x}x${y}+0+0] -depth 8 txt: | tail -n +2 | sed -n 's/^.*\(#[^ ]*\).*$/\1/p' | cut -c2-3`); # , R RGB, . for i in `seq 0 $n $s`; # N- do # 16- color1=`echo ${color[i]} | cut -c1-1` color2=`echo ${color[i]} | cut -c2-2` case "$color1" in "A" ) color1=10;; "B" ) color1=11;; "C" ) color1=12;; "D" ) color1=13;; "E" ) color1=14;; "F" ) color1=15;; esac case "$color2" in "A" ) color2=10;; "B" ) color2=11;; "C" ) color2=12;; "D" ) color2=13;; "E" ) color2=14;; "F" ) color2=15;; esac let "rgbcolor = color1*16+color2" let "sum = sum+rgbcolor" # "". let "count = count+1" # done let "avcolor = sum/count" # #echo ": $avcolor" # ( max) let "bright=avcolor*100/$max" # # if [ $bright -gt $maxbright ]; then bright=$maxbright fi if [ $bright -lt $minbright ]; then bright=$minbright fi xbacklight -set $bright # echo " : $bright" sleep $sleep # done
avcolor=`convert snapshot.jpg -colorspace GRAY -resize 1x1 txt: | sed 's/[^(]*(\s*\([0-9]*\),.*/\1/p;d'`
echo -n $bright > /proc/acpi/video/VGA/LCD/brightness;
Source: https://habr.com/ru/post/136388/
All Articles