diff options
-rwxr-xr-x | encode-libvlc.sh | 107 | ||||
-rw-r--r-- | examplesite/configuration.sh | 4 |
2 files changed, 109 insertions, 2 deletions
diff --git a/encode-libvlc.sh b/encode-libvlc.sh new file mode 100755 index 0000000..ee0854e --- /dev/null +++ b/encode-libvlc.sh @@ -0,0 +1,107 @@ +#!/bin/bash +# +# Encode programme using libVLC input from +# dabplus-enc or toolame +# +# monitor processes, and restart if necessary +# Optionally send an email when restart happens + +printerr() { + echo -e "\033[01;31m$1\033[0m" + logger -p local0.error -t "$ID" "$1" +} + +printmsg() { + echo -e "\033[01;32m$1\033[0m" + logger -p local0.notice -t "$ID" "$1" +} + +set -u + +# check number of arguments +if [[ "$#" -lt 3 ]] ; then + echo "Usage $0 url destination [encoder]" + echo "Encoder shall be 'dabplus-enc' or 'toolame'" + exit 1 +fi + +URL=$1 +ID=$2 +DST=$3 + +if [[ "$#" -eq 4 ]] ; then + ENC=$4 +else + ENC="dabplus-enc" +fi + +BITRATE=80 + +running=1 + +encoderpid=0 + +# The trap for Ctrl-C +sigint_trap() { + printerr "Got Ctrl-C, killing mplayer and encoder" + running=0 + + if [[ "$encoderpid" != "0" ]] ; then + kill -TERM $encoderpid + sleep 2 + kill -KILL $encoderpid + fi + + printmsg "quitting" + exit +} + +trap sigint_trap SIGTERM +trap sigint_trap SIGINT + +while [[ "$running" == "1" ]] +do + + printmsg "Launching encoder" + if [[ "$ENC" == "dabplus-enc" ]] ; then + dabplus-enc -v "$URL" -b $BITRATE -r 32000 -o "$DST" -l & + encoderpid=$! + elif [[ "$ENC" == "toolame" ]] ; then + toolame -V -s 48 -L -b $BITRATE "$URL" "$DST" & + encoderpid=$! + fi + printerr "Detected crash of encoder!" + + sleep 5 + + checkloop=1 + while [[ "$checkloop" == "1" ]] + do + sleep 2 + + kill -s 0 $encoderpid + if [[ "$?" != "0" ]] ; then + printerr "the encoder died" + + encoderpid=0 + checkloop=0 + fi + done + + MAILTO=$(cat site/mail-warning.txt) + + if [[ "$MAILTO" != "" ]] ; then + NOW=$(date) + + mail -s "Encoder $ID restart $URL" "$MAILTO" << EOF +The encoder id:$ID +encoding $URL -> $DST using encode-libvlc was restarted at +$NOW + +EOF + + fi + sleep 5 + +done + diff --git a/examplesite/configuration.sh b/examplesite/configuration.sh index 6312f21..6ff72eb 100644 --- a/examplesite/configuration.sh +++ b/examplesite/configuration.sh @@ -10,8 +10,8 @@ declare -A radios # for each radio, write here the full encoder command. # encode-jack needs: # URL ID dabmux-URL [amplitude correction] -radios[radio1]="./encode-jack.sh http://fbpc5.epfl.ch:8000/fb_192 radio1 tcp://localhost:9001" +radios[radio1]="./encode-libvlc.sh http://fbpc5.epfl.ch:8000/fb_192 radio1 tcp://localhost:9001" # Attenuate radio2 by 3dB -radios[radio2]="./encode-jack.sh http://91.121.151.197:8016 radio2 tcp://localhost:9002" +radios[radio2]="./encode-libvlc.sh http://mp3lg.tdf-cdn.com/fip/all/fiphautdebit.mp3 radio2 tcp://localhost:9002 toolame" |