Skip to content

Instantly share code, notes, and snippets.

@andyone
Last active March 30, 2020 16:17
Show Gist options
  • Select an option

  • Save andyone/63eb855430ee516f38b7d47620c5ad57 to your computer and use it in GitHub Desktop.

Select an option

Save andyone/63eb855430ee516f38b7d47620c5ad57 to your computer and use it in GitHub Desktop.
Icecast FFmpeg Transcoder
#!/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 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment