-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream
executable file
·28 lines (24 loc) · 1.19 KB
/
stream
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# stream - Stream video when called from crontab
# Usage: stream <tag>
# The tag refers to video files in ./uploadpage/streams without the
# '.mp4', that should have been re-encoded by `encode`. The tag has no path
# information, has the "streamkey" at the start before the first dot (there
# has to be a dot!) and the "target" at the very end, after the last '@'.
# Required: ffmpeg coreutils(tail rm)
_=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*}
log=$repopath/process.log
in=$repopath/uploadpage/streams/$1.mp4 key=${1%%.*} target=${1##*@}
case $target in
Facebook) rtmp=rtmps://live-api-s.facebook.com:443/rtmp/$key ;;
YouTube) rtmp=rtmp://a.rtmp.youtube.com/live2/$key ;;
RestreamSG) rtmp=rtmp://singapore.restream.io/live/$key ;;
*) rtmp=rtmp://live.restream.io/live/$key
esac
# Stream, log it, and remove all files if successful
set -o pipefail # to get ffmpeg's returncode
ffmpeg -re -y -i "$in" -c:v copy -c:a copy -f flv "$rtmp" 2>&1 |tail -n 20 >"$in.log" &&
rm "$in.log" "$in" "${in%.mp4}" ||
echo "Error while streaming $1" >>"$log"
# In any case, comment-out the crontab entry so it's not waiting for next year
crontab -l| sed "/$1/ s/^/#/" |crontab -