Take Continuously Screenshots in a Certain Interval
Some time ago I took a lecture that was streamed on the Internet, but you would only get the slides, when you came to class in person. I didn’t get the logic in that and to save the time commuting to university I wrote a shell script that takes a screenshot every x seconds to capture the slides. It uses import from the imagemagick packet.
#!/bin/bashno=$1# number of screenshots as argumentsec=1 # interval of screenshots in seconds, also floats possiblesleep 5 # optionals= 0
for i in $(seq $no); dosleep $secs=$(($i*$sec))echo"$s seconds of $(($no*$sec))" import -window root image_$(seq -f %0011f $i$i | cut -d ',' -f 1).png
done
But now I had lots of screenshots and I only needed the distinct ones. compare compares two images and if their difference is under a certain threshold they are considered equal and only one of them is kept.
So the final script looks like this. It also crops the screenshot, which you might omit.
#!/bin/bashno=$1# number of screenshots as argumentfuzz=20 # which pixels are considered equal, in %threshold=10 # threshold, under which images are considered equalsec=1 # interval of screenshots, also floats possiblewidth=1024 # width of slideheigth=768 # height of slideoffset=335 # offset from the leftsleep 5
s=0
date
for i in $(seq $no); dosleep $secs=$(($i*$sec))echo"$s seconds of $(($no*$sec))" import -crop ${width}x${height}+${offset} -window root image_$(seq -f %0011f $i$i | cut -d ',' -f 1).png
donedate
i=1
while[$i -le $no]doj=$((i+1))while[$j -le $no]doi_=$(seq -f %0011f $i$i | cut -d ',' -f 1)j_=$(seq -f %0011f $j$j | cut -d ',' -f 1)if[ -f image_${i_}.png ]&&[ -f image_${j_}.png ]thendiff=$(compare -fuzz ${fuzz}% -metric ae image_${i_}.png image_${j_}.png diff.png 2>&1)echo"difference between $i_ and $j_: $diff"if[$diff -lt $threshold]thenrm image_${j_}.png
elsei=$((j-1))breakfi fij=$((j+1))donei=$((i+1))donerm diff.png
i=0
for file in *.png
domv $file$(seq -f %0011f $i$i | cut -d ',' -f 1).png
i=$(($i+1))done