Last active
May 25, 2019 02:20
-
-
Save hoangdh/d16f8b53deaedb2ab79b1ae196fd5ab2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ENCODER="-c:v libx264 -b:v 1.5M -preset superfast -tune zerolatency -c:a aac -ar 44100" | |
ENCODER2="-c:v libx264 -b:v 1.5M -pix_fmt yuv420p -c:a aac -strict experimental -b:a 192k -ac 2" | |
genPort() { | |
while | |
port=$(shuf -n 1 -i 49152-65535) | |
netstat -atun | grep -q "$port" | |
do | |
continue | |
done | |
echo $port | |
} | |
LOCAL=$(genPort) | |
EXT=$(genPort) | |
# echo 1 2 3 4 $LOCAL $EXT | |
ID=`echo $1 | md5sum | awk {'print $1'}` | |
if [ $(expr $1 - 0) -gt 0 ] | |
then | |
# echo ID-$1 | |
sp-sc sop://broker.sopcast.com:3912/$1 $LOCAL $EXT > /dev/null 2>&1 & | |
else | |
sp-sc $1 $LOCAL $EXT > /dev/null 2>&1 & | |
fi | |
STREAM="stream-`echo $1 | md5sum | cut -d ' ' -f1`" | |
sleep 20 | |
if netstat -atun | grep -q $EXT | |
then | |
echo "http://$(hostname -I | cut -d' ' -f1):$EXT" | |
echo "http://$(hostname -I | cut -d' ' -f1)/hls/$STREAM/index.m3u8" | |
ffmpeg -re -i https://localhost:$EXT $ENCODER -f flv rtmp://localhost/live/${STREAM} # > /dev/null 2&>1 | |
# exit 0 | |
else | |
echo "$1 invaild. - $STREAM" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment