-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_loop.sh
executable file
·30 lines (25 loc) · 1.06 KB
/
stream_loop.sh
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
29
30
#!/bin/bash
VIDEO_PATH="/usr/src/app/video.mp4"
if [ ! -z "$WEBHOOK_URL" ]; then
curl -H "Content-Type: application/json" \
-X POST \
-d '{"content": "[info] Streaming started!"}' \
$WEBHOOK_URL
fi
# Loop the video and stream it using ffmpeg
while true; do
echo "Stream started!"
ffmpeg -loglevel warning -re -i "$VIDEO_PATH" -c:v libx264 -preset veryfast -tune zerolatency -c:a aac -b:a 128k -ac 2 -r 30 -g 60 -vb 1369k -minrate 1369k -maxrate 1369k -bufsize 2730k -ar 44100 -x264-params "nal-hrd=cbr" -vf "scale=1280:720,format=yuv420p,bwdif=mode=send_field:parity=auto:deint=all" -profile:v main -f flv -flvflags no_duration_filesize "$STREAM_URL/$STREAM_KEY"
if [[ $? -eq 0 ]]; then
echo "Command succeeded! Restarting stream..."
else
echo "Stream interrupted with an error, restarting in 10 seconds..."
if [ ! -z "$WEBHOOK_URL" ]; then
curl -H "Content-Type: application/json" \
-X POST \
-d '{"content": "[alert] stream interrupted, restarting in 10 seconds..."}' \
$WEBHOOK_URL
fi
sleep 10
fi
done