add README, fix a bunch of paths, reorganise, make more suitable for public

master
Thomas Lynch 1 year ago
parent eeeabfe3e0
commit e57c8015a1
  1. 13
      README.md
  2. 17
      anime.sh
  3. 0
      auth-server/package-lock.json
  4. 0
      auth-server/package.json
  5. 2
      auth-server/server.js
  6. 0
      auth-server/streamkeys.js.example
  7. 3
      crontab
  8. 21
      music.sh
  9. 6
      nginx/rtmp.conf
  10. 15
      nginx/sites-available/stream.conf
  11. 4
      posters.sh
  12. 0
      public/css/video-js.min.css
  13. 0
      public/dash.html
  14. 0
      public/favicon.ico
  15. 0
      public/hls.html
  16. 0
      public/js/video.min.js
  17. 0
      public/offline.png
  18. 0
      public/stat.xsl
  19. 0
      public/viewers.txt
  20. 4
      viewers.sh

@ -0,0 +1,13 @@
# stream
The source of [stream.loki](http://stream.loki) (or another simple nginx-rtmp-based streaming site).
The aim is to have a simple streaming site with chat (irc iframe), view count, an index page ([/streams](http://stream.loki/streams)) of all live streams, and do it with minimal backend.
This repo provides:
- the nginx configs and static files
- small nodejs http server for nginx to authenticate stream keys (optional)
- some cronjobs to generate viewer counts and stream thumbnails
## License
GNU AGPLv3, see [LICENSE](LICENSE).

@ -1,17 +0,0 @@
STREAM_NAME=""
STREAM_KEY=""
while true;
do
rm ~/anime/list.*
for f in ~/anime/*.mp4 ; do
echo file "$f" >> ~/anime/list.txt;
#echo file "$f" >> ~/anime/list.tmp;
done
#shuf ~/anime/list.tmp > ~/anime/list.txt
ffmpeg \
-re -f concat -safe 0 -i ~/anime/list.txt \
-c:a copy -c:v copy \
-f flv "rtmp://stream.loki/live/${STREAM_NAME}?key=${STREAM_KEY}"
sleep 15
done

@ -11,7 +11,7 @@ const streamKeys = require(__dirname+'/streamkeys.js')
app.set('query parser', 'simple');
app.use(express.urlencoded({extended: false}));
app.post('/forms/stream', (req, res, next) => {
app.post('/forms/stream', (req, res) => {
if (req.body
&& req.body.name
&& req.body.key

@ -0,0 +1,3 @@
# every minute, run both scripts to update viewer count and stream thumbnails
* * * * * bash /var/www/stream/viewers.sh
* * * * * bash /var/www/stream/posters.sh

@ -1,21 +0,0 @@
STREAM_NAME=""
STREAM_KEY=""
while true;
do
rm ~/music/list.*
for f in ~/music/*.opus ; do
echo file "$f" >> ~/music/list.tmp;
done
shuf ~/music/list.tmp > ~/music/list.txt
#NOTE: creates 2x2 dummy video stream to make nginx happy, or else it will not show in the stream list.
#NOTE: timeout kills after 12 hours, because nginx is shite. it will loop, shuffle and run again.
timeout --foreground --kill-after=10 43200 ffmpeg \
-re -f lavfi -i "color=size=2x2:rate=1:color=black" \
-re -f concat -safe 0 -thread_queue_size 512 -i ~/music/list.txt \
-map 0:v:0 -map 1:a:0 \
-c:v libx264 -pix_fmt yuv420p -preset superfast -r 2 -g 2 -b:v 1k \
-c:a aac -b:a 128k -bufsize 512k \
-f flv "rtmp://stream.loki/live/${STREAM_NAME}?key=${STREAM_KEY}"
sleep 15
done

@ -7,8 +7,10 @@ rtmp {
server {
listen 172.16.0.1:1935;
allow 172.16.0.0/16;
deny all;
listen x.x.x.x:1935;
allow publish x.x.x.x;
deny publish all;
allow play all;
chunk_size 4096;
application live {
# sync 100ms;

@ -1,12 +1,8 @@
server {
server {
server_name stream.loki www.stream.loki;
listen unix:/var/lib/haproxy/haproxy-nginx.sock;
real_ip_header X-Forwarded-For;
set_real_ip_from unix:;
listen 172.16.0.1:80;
allow 172.16.0.0/16;
deny all;
@ -26,26 +22,25 @@ server {
}
location /stat.xsl {
root /var/www/stream/;
root /var/www/stream/public/;
}
location /viewers/ {
default_type text/plain;
add_header Content-Type "text/plain";
add_header Refresh "30; $request_uri";
root /var/www/stream/;
root /var/www/stream/public/;
try_files $uri /viewers.txt =404;
}
location /posters/ {
root /var/www/stream/;
root /var/www/stream/public/;
try_files $uri /offline.png =404;
}
location / {
root /var/www/stream/;
root /var/www/stream/public/;
try_files $uri $uri/hls.html =404;
}
}

@ -10,8 +10,8 @@ do
tsfile=`bash -c "ls -t /tmp/hls/$streamer-*.ts" | head -n1`
ffmpeg -hide_banner -loglevel error -y \
-ss 00:00:00.00 -i "$tsfile" \
-frames:v 1 "/var/www/stream/posters/$streamer.jpg" < /dev/null;
-frames:v 1 "/var/www/stream/public/posters/$streamer.jpg" < /dev/null;
done <<< "$all_live"
# delete old posters
bash -c 'find /var/www/stream/posters/*.jpg -mmin +2 -exec rm {} \;'
bash -c 'find /var/www/stream/public/posters/*.jpg -mmin +2 -exec rm {} \;'

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -37,8 +37,8 @@ while read -r line
do
num=`echo $line | cut -f1 -d" "`
name=`echo $line | cut -f2 -d" "`
echo "👁 $num" > "/var/www/stream/viewers/$name.txt"
echo "👁 $num" > "/var/www/stream/public/viewers/$name.txt"
done <<< "$viewers"
# delete any not updated viewer files (no longer live)
bash -c 'find /var/www/stream/viewers/*.txt -mmin +0.5 -exec rm {} \;'
bash -c 'find /var/www/stream/public/viewers/*.txt -mmin +0.5 -exec rm {} \;'

Loading…
Cancel
Save