Close

It's running on the RPi now

A project log for ISS HDEV image availability

The "High Definition Earth Viewing" experiment onboard the ISS runs a few cameras, but not always. Let's find out when video is available!

ChristophChristoph 09/22/2016 at 18:340 Comments

Some tweaks were necessary before this started to work:

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

Discussions