Skip to content

Instantly share code, notes, and snippets.

@d3cline
Created September 28, 2017 20:44
Show Gist options
  • Save d3cline/ade1cc46b358c253fe1d42458c07ff19 to your computer and use it in GitHub Desktop.
Save d3cline/ade1cc46b358c253fe1d42458c07ff19 to your computer and use it in GitHub Desktop.
Pi Webcam Youtube streamer with text from ioTank. (yet another weather station)
*/1 * * * * $HOME/weather.sh
* * * * * $HOME/watch.sh > $HOME/cron/watchdog.log 2>&1
#! /bin/bash
VBR="3000k"
FPS="30"
QUAL="ultrafast"
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
mkdir -p "$HOME/tmp"
PIDFILE="$HOME/tmp/myprogram.pid"
SOURCE="/dev/video0"
KEY="123456789"
if [ -e "${PIDFILE}" ] && (ps -u $(whoami) -opid= |
grep -P "^\s*$(cat ${PIDFILE})$" &> /dev/null); then
echo "Already running."
exit 99
fi
ffmpeg \
-i "$SOURCE" \
-f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -pix_fmt yuv420p -profile:v baseline \
-vcodec libx264 -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \
-vf drawtext="fontfile=$HOME/Gameplay.ttf: \
textfile=$HOME/foo.txt: reload=1: fontcolor=white: fontsize=24: box=1: [email protected]: \
boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2" \
-f flv "$YOUTUBE_URL/$KEY" > $HOME/tmp/myprogram.log &
echo $! > "${PIDFILE}"
chmod 644 "${PIDFILE}"
#! /bin/bash
# this script generates the text and is ran in cron every minute.
# The IP here is the IP of ioTank https://github.com/objectsyndicate/ioTank
echo -n "T:" > foo.txt
curl -s 'http://192.168.1.32/json' | jq -r '.t1' | tr -d '\n' >> foo.txt
echo -n "" >> foo.txt
echo -n " H:" >> foo.txt
curl -s 'http://192.168.1.32/json' | jq -r '.h' | tr -d '\n' >> foo.txt
echo -n "" >> foo.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment