#!/bin/env bash ################################################################################ SOURCE_HOST="127.0.0.1:8000" ################################################################################ main() { if [[ $# -lt 2 ]] ; then usage exit 0 fi transcode "$1" "$2" "${3:-192k}" } transcode() { local source_name="$1" local password="$2" local bitrate="$3" local bitrate_num=$(echo "$bitrate" | tr -d "k") local stream="http://$SOURCE_HOST/${source_name}" while : ; do ffmpeg -icy 1 \ -i "${stream}" \ -vn -map_metadata:s:0 0:g \ -acodec libfdk_aac \ -b:a "$bitrate" \ "icecast://source:${password}@${SOURCE_HOST}/${bitrate_num}.aac" checkStatus "$source" done } checkStatus() { local status echo "Stream is down, waiting…" while : ; do status=$(curl -Is -o /dev/null -w "%{http_code}" "$1") if [[ "$status" == "200" ]] ; then echo "Stream is up, resume transcoding…" return fi sleep 1 done } usage() { echo "nohup ./transcoder.sh {source-name} {password} {bitrate} &" } ################################################################################ main "$@"