2021-01-24 04:04:16 +01:00
|
|
|
# RTMPDash
|
|
|
|
|
2021-01-31 17:57:20 +01:00
|
|
|
[Production instance](https://chaos.stream)
|
2021-01-24 04:04:16 +01:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
- Adjust all the `const`'s in Program.cs
|
2022-02-04 05:55:27 +01:00
|
|
|
- Install [nginx-mod-rtmp](https://git.zotan.services/zotan/nginx-mod-rtmp) (arch
|
|
|
|
package: `aur/nginx-mod-rtmp-lhaus-git`)
|
2021-01-24 04:09:41 +01:00
|
|
|
- Configure nginx-mod-rtmp, example config below
|
2021-01-28 00:15:16 +01:00
|
|
|
- Install and start `redis` for persistent sessions
|
2021-01-24 04:09:41 +01:00
|
|
|
- Start RTMPDash, example systemd unit below
|
2022-02-04 05:55:27 +01:00
|
|
|
- The admin user is output to stdout on first startup, if RTMPdash started with the systemd unit it will be in the
|
|
|
|
journal
|
2021-01-24 04:09:41 +01:00
|
|
|
|
|
|
|
## Further setup
|
2022-02-04 05:55:27 +01:00
|
|
|
|
2021-01-24 04:09:41 +01:00
|
|
|
- Customize privacy policy to your environment if you plan on hosting it publicly
|
2021-01-24 04:14:25 +01:00
|
|
|
- Set up player, example code below
|
2021-01-24 04:09:41 +01:00
|
|
|
|
2021-01-24 04:16:14 +01:00
|
|
|
### nginx-mod-rtmp example config
|
2021-01-24 04:09:41 +01:00
|
|
|
|
|
|
|
```
|
2021-01-25 23:51:47 +01:00
|
|
|
load_module /usr/lib/nginx/modules/ngx_rtmp_module.so; # load our rtmp module
|
|
|
|
worker_processes 1; # VERY IMPORTANT, otherwise nginx-mod-rtmp breaks
|
|
|
|
|
2021-01-24 04:09:41 +01:00
|
|
|
rtmp {
|
|
|
|
log_format rtmp '[$time_local] $command -> $app with key "$name" - $bytes_received bytes received ($session_readable_time)';
|
2021-01-24 18:28:49 +01:00
|
|
|
server {
|
|
|
|
listen 1935;
|
2021-01-24 04:09:41 +01:00
|
|
|
|
2021-01-24 18:28:49 +01:00
|
|
|
access_log /var/log/nginx/rtmp_access.log rtmp;
|
2021-01-24 04:09:41 +01:00
|
|
|
|
2021-01-24 18:28:49 +01:00
|
|
|
max_message 32M;
|
|
|
|
ping 1m;
|
|
|
|
ping_timeout 10s;
|
|
|
|
drop_idle_publisher 10s;
|
|
|
|
notify_method get;
|
2021-01-24 04:09:41 +01:00
|
|
|
|
2021-01-24 18:28:49 +01:00
|
|
|
application ingress {
|
|
|
|
live on;
|
2021-01-24 04:09:41 +01:00
|
|
|
|
2021-01-24 18:28:49 +01:00
|
|
|
allow play 127.0.0.1;
|
|
|
|
deny play all;
|
2021-01-24 04:09:41 +01:00
|
|
|
|
|
|
|
notify_relay_redirect on;
|
|
|
|
|
2021-01-24 18:28:49 +01:00
|
|
|
on_publish http://localhost:60001/api/authenticate;
|
2021-01-24 04:09:41 +01:00
|
|
|
|
2021-01-24 18:28:49 +01:00
|
|
|
hls on;
|
|
|
|
hls_path /mnt/ssd_data/hls/src;
|
2022-02-06 04:38:06 +01:00
|
|
|
hls_continuous off;
|
2021-01-24 18:28:49 +01:00
|
|
|
hls_fragment 1s;
|
2021-01-24 04:09:41 +01:00
|
|
|
hls_fragment_naming system;
|
2021-01-24 18:28:49 +01:00
|
|
|
hls_playlist_length 60s;
|
2021-01-24 04:09:41 +01:00
|
|
|
hls_allow_client_cache enabled;
|
2021-01-24 18:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-24 04:09:41 +01:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-01-24 04:16:14 +01:00
|
|
|
### RTMPdash example systemd unit (development)
|
2022-02-04 05:55:27 +01:00
|
|
|
|
2021-01-24 04:09:41 +01:00
|
|
|
```
|
|
|
|
[Unit]
|
|
|
|
Description=RTMPDash
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
User=rtmpdash
|
|
|
|
Group=rtmpdash
|
|
|
|
WorkingDirectory=/opt/rtmpdash
|
|
|
|
Environment=ASPNETCORE_URLS='http://*:60001'
|
2021-01-26 00:21:02 +01:00
|
|
|
Environment=ASPNETCORE_ENVIRONMENT=Development
|
2021-01-24 04:09:41 +01:00
|
|
|
ExecStart=/usr/bin/dotnet watch run --no-launch-profile
|
|
|
|
Type=simple
|
|
|
|
TimeoutStopSec=20
|
|
|
|
|
|
|
|
# Lets built in updater work well.
|
|
|
|
Restart=on-failure
|
|
|
|
KillMode=control-group
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
|
|
|
## RTMPdash example systemd unit (production)
|
2022-02-04 05:55:27 +01:00
|
|
|
|
2021-01-24 04:09:41 +01:00
|
|
|
```
|
|
|
|
[Unit]
|
|
|
|
Description=RTMPDash
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
User=rtmpdash
|
|
|
|
Group=rtmpdash
|
|
|
|
WorkingDirectory=/opt/rtmpdash
|
|
|
|
Environment=ASPNETCORE_URLS='http://*:60001'
|
|
|
|
Environment=ASPNETCORE_ENVIRONMENT=Production
|
2021-01-26 00:39:49 +01:00
|
|
|
ExecStart=/usr/bin/dotnet run -c Release --no-launch-profile
|
2021-01-24 04:09:41 +01:00
|
|
|
Type=simple
|
|
|
|
TimeoutStopSec=20
|
|
|
|
|
|
|
|
# Lets built in updater work well.
|
|
|
|
Restart=on-failure
|
|
|
|
KillMode=control-group
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
2021-01-24 04:14:25 +01:00
|
|
|
|
|
|
|
### VideoJS Player example code
|
2022-02-04 05:55:27 +01:00
|
|
|
|
2021-01-24 04:14:25 +01:00
|
|
|
```
|
2022-02-06 04:38:06 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset='utf-8'>
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
|
|
|
<link href="/lib/video-js.min.css" rel="stylesheet" />
|
|
|
|
<title>Player - chaos.stream</title>
|
|
|
|
<style>
|
|
|
|
html, body, #wrapper {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="wrapper">
|
|
|
|
<video id='hls-player' class="video-js vjs-default-skin vjs-big-play-centered" controls autoplay>
|
|
|
|
<source type="application/x-mpegURL">
|
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
<script src="/lib/video.min.js"></script>
|
|
|
|
<script>
|
|
|
|
document.querySelector('source').src = 'https://cdn.chaos.stream/hls/src/' + window.location.pathname.substring(1) + '.m3u8';
|
|
|
|
document.getElementById("hls-player").addEventListener("error",function(event){
|
|
|
|
console.log('HTML5 video error, reloading page in 10sec');
|
|
|
|
setTimeout(function () { location.reload(true); }, 10000);
|
|
|
|
});
|
|
|
|
|
|
|
|
var player = videojs('hls-player', {
|
|
|
|
liveui: true,
|
|
|
|
html5: {
|
|
|
|
vhs: {
|
|
|
|
blacklistDuration: Infinity,
|
|
|
|
maxPlaylistRetries: 5,
|
|
|
|
experimentalBufferBasedABR: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
player.ready(function() {
|
|
|
|
let player = this
|
|
|
|
|
|
|
|
player.on("error", function(){
|
|
|
|
console.log('VJS Error. Treating as offline.');
|
|
|
|
player.poster('https://live.on.chaos.stream/lib/offline.png');
|
|
|
|
player.errorDisplay.hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
player.on("ended", function(){
|
|
|
|
console.log('Stream ended. Redirecting to profile.');
|
|
|
|
document.location = 'https://chaos.stream/profile/' + window.location.pathname.substring(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
player.fill(true);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
2021-01-24 04:14:25 +01:00
|
|
|
```
|
2021-01-24 04:16:14 +01:00
|
|
|
|
|
|
|
### accompanying nginx config for VideoJS Player
|
2022-02-04 05:55:27 +01:00
|
|
|
|
2021-01-24 04:16:14 +01:00
|
|
|
```
|
2022-02-06 04:38:06 +01:00
|
|
|
location = /favicon.ico {
|
|
|
|
#ignore rewrite rules
|
|
|
|
}
|
|
|
|
|
|
|
|
location ^~ /lib/ {
|
|
|
|
#ignore rewrite rules
|
2021-01-24 04:16:14 +01:00
|
|
|
}
|
|
|
|
|
2022-02-06 04:38:06 +01:00
|
|
|
location = /watch.html {
|
|
|
|
#ignore rewrite rules
|
2021-01-24 04:16:14 +01:00
|
|
|
}
|
|
|
|
|
2022-02-06 04:38:06 +01:00
|
|
|
location / {
|
|
|
|
rewrite / /watch.html last;
|
|
|
|
}
|
2021-01-24 04:16:14 +01:00
|
|
|
```
|