Some tweaks were necessary before this started to work:
- update livestreamer
- install bc
- install imagemagick
I also tried to get rid of some error messages popping up when temporary files weren't there (yet), and this is the result:
#!/bin/bash
# http://stackoverflow.com/questions/18279540/bash-shutdown-hook-or-kill-all-background-processes-when-main-process-is-kille
threshold="0.1"
fps="1/5"
outfolder=/tmp/hdev-availability
trap "jobs -p | xargs --no-run-if-empty kill; rm -r $outfolder" EXIT
mkdir -p $outfolder
livestreamer --player "ffmpeg -i" --player-args "{filename} -vf fps=$fps $outfolder/out%04d.png" https://www.ustream.tv/channel/17074538 worst &
while true; do
# find newest file and compare
FILE=$(ls -t $outfolder/out*.png 2>/dev/null | head -n 1)
if [ -f $FILE ]; then
{ output=$(compare -metric MSE -fuzz 20% $FILE references/novideo.png $outfolder/tmp.jpg 2>&1 1>&3-) ;} 3>&1
value=$(echo $output | cut -d "(" -f2 | cut -d ")" -f1)
echo $value'>'$threshold | bc -l
fi
# remove old files
# http://stackoverflow.com/questions/25785/delete-all-but-the-most-recent-x-files-in-bash
(ls -t $outfolder/out*.png 2>/dev/null | head -n 2;ls $outfolder/out*.png 2>/dev/null ) | sort | uniq -u | xargs --no-run-if-empty rm
# check if livestreamer is still running and restart if required
# ...
sleep 5
done
It's happily printing a chain of 1's and 0's, according to live video availability. Now I just need to- make it more reliable
- create a stream multiplexer that shows something else when live HDEV images are not available
- make the information available publicly
- reduce cpu load - ffmpeg uses a lot of resources and I'm not sure if that's necessary. Sometimes the cpu is fully loaded.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.