Commit 558e143d authored by hatsch's avatar hatsch
Browse files

update hls.

parent 191fb5a1
...@@ -38,7 +38,7 @@ Example Playbook ...@@ -38,7 +38,7 @@ Example Playbook
key: live key: live
secret: mynewsecret secret: mynewsecret
roles: roles:
- { role: username.rolename } - { role: dorftv.nginx-rtmp }
License License
------- -------
......
- debug: var=rtmp - debug: var=rtmp
- name: "Create HLS directory for {{ rtmp.key }}"
file:
state: directory
path: "/var/www/{{ site.key }}/{{ item }}/{{ rtmp.key }}"
owner: www-data
group: www-data
with_items:
- hls
- player
- name: "Template rtmp application {{ rtmp.key }} for {{ site.key }}" - name: "Template rtmp application {{ rtmp.key }} for {{ site.key }}"
template: template:
src: rtmp.j2 src: rtmp.j2
...@@ -14,3 +24,8 @@ ...@@ -14,3 +24,8 @@
state: link state: link
notify: notify:
- reload nginx - reload nginx
- name: "Add index.html"
template:
src: index.html.j2
dest: "/var/www/{{ site.key }}/player/{{ rtmp.key }}/index.html"
<!DOCTYPE html>
<html lang="en">
<head>
<title>Clappr/Hls.js with P2P Media Loader</title>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/build/p2p-media-loader-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@latest/build/p2p-media-loader-hlsjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clappr@latest"></script>
</head>
<body>
<div id="player"></div>
</br></br></br>
<div id="info">
RTMP Url: {{ site.key }}/{{rtmp.key}}
</br>
###### To be removed</br>
KEY: {{ rtmp.value.key }}</br>
Secret: {{ rtmp.value.secret }}</br>
</div>
<script>
if (p2pml.hlsjs.Engine.isSupported()) {
var engine = new p2pml.hlsjs.Engine();
var player = new Clappr.Player({
parentId: "#player",
source: "http://{{ site.key }}/hls/{{rtmp.key}}/{{ rtmp.value.key }}/index.m3u8",
actualLiveTime: true,
mute: true,
autoPlay: true,
width: '640',
height: '360',
hideMediaControl: true,
playback: {
hlsjsConfig: {
liveSyncDurationCount: 7,
loader: engine.createLoaderClass()
}
}
});
p2pml.hlsjs.initClapprPlayer(player);
} else {
document.write("Not supported :(");
}
</script>
</body>
</html>
application {{ rtmp.key }} { application {{ rtmp.key }} {
#GENERAL STREAM SETTING #GENERAL STREAM SETTING
wait_key on; wait_key on;
interleave on; interleave on;
sync 10ms; sync 10ms;
hls_cleanup on;
drop_idle_publisher 60s; drop_idle_publisher 60s;
live on; live on;
#ALLOW SETTINGS
allow publish all;
allow play all;
#HLS SETTINGS #HLS SETTINGS
hls on; hls on;
#hls_dvr on; #hls_dvr on;
hls_path /var/www/{{ site.key }}/data/{{rtmp.key}}; hls_cleanup on;
hls_nested on; hls_path /var/www/{{ site.key }}/hls/{{rtmp.key}}/;
hls_type live; hls_type live;
hls_fragment 5s; hls_nested on;
hls_base_url https://{{ site.key }}/{{ rtmp.value.key }}; hls_base_url http://{{ site.key }}/hls/{{ rtmp.key }}/;
hls_variant _high BANDWIDTH=1200000; hls_fragment_naming system;
hls_variant _mid BANDWIDTH=664000;
hls_variant _low BANDWIDTH=362000;
#RECORD SETTINGS
record all;
record_path /var/www/{{ site.key }}/data/record;
record_suffix -%d-%b-%y-%T.flv;
hls_fragment_slicing plain; hls_fragment_slicing plain;
hls_playlist_length 180m;
hls_continuous on; hls_continuous on;
hls_playlist_length 10s;
hls_fragment 1s;
#ALLOW SETTINGS
allow publish all;
allow play all;
#RECORD SETTINGS
#record all;
#record_path /var/www/{{ site.key }}/data/record;
#record_suffix -%d-%b-%y-%T.flv;
meta off; meta off;
#hls_allow_client_cache enabled; #hls_allow_client_cache enabled;
......
...@@ -8,8 +8,30 @@ server { ...@@ -8,8 +8,30 @@ server {
index index.html; index index.html;
{% for key, value in site.value.endpoints.items() %} {% for key, value in site.value.endpoints.items() %}
############## {{ value.key }} #######################
location /{{ key }}/ {
alias /var/www/{{ site.key }}/player/{{ key }}/;
}
location /hls/{{ key }} {
alias /var/www/{{ site.key }}/hls/{{ key }};
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers accept;
try_files $uri $uri/ =404;
}
location /auth/{{ key }}/{{ value.key }} { location /auth/{{ key }}/{{ value.key }} {
if ($arg_psk = '{{ value.secret }}') { if ($arg_psk = '{{ value.secret }}') {
return 201; return 201;
...@@ -17,6 +39,8 @@ server { ...@@ -17,6 +39,8 @@ server {
return 404; return 404;
} }
############## END {{ value.key }} #######################
{% endfor %} {% endfor %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment