Skip to content

Instantly share code, notes, and snippets.

@hex128
Created November 22, 2016 14:38
Show Gist options
  • Save hex128/68a789a5bdc21e55d671d8d6ecde4ae1 to your computer and use it in GitHub Desktop.
Save hex128/68a789a5bdc21e55d671d8d6ecde4ae1 to your computer and use it in GitHub Desktop.
#!/bin/bash
ontrap () {
for j in $(jobs -p)
do
kill -s SIGTERM $j > /dev/null 2>&1 || (sleep 1 && kill -9 $j > /dev/null 2>&1 &)
done
}
trap ontrap INT TERM EXIT
server () {
while :
do
python -m SimpleHTTPServer 8000
done
}
stream () {
while :
do
${phantomjs} runner.js | ${ffmpeg} \
-y -c:v png -f image2pipe -r 1 \
-i - -f lavfi -i anullsrc \
-c:v libx264 -pix_fmt yuv420p -preset ultrafast -vf fps=25 \
-c:a aac -ar 44100 -ac 2 \
-f flv ${rtmp}
done
}
phantomjs='/usr/local/bin/phantomjs'
ffmpeg='/usr/local/bin/ffmpeg'
rtmp=${1}
server &
stream &
wait $(jobs -p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment