forked from flavioribeiro/nginx-audio-track-for-hls-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
66 lines (57 loc) · 2.01 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
worker_processes 1;
daemon off;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
server_name localhost;
set $hls_path /mnt/chunks/;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
location ~ -audio\.m3u8$ {
default_type application/vnd.apple.mpegurl;
content_by_lua '
local base_m3u8_url = ngx.var.uri:gsub("-audio.m3u8", ".m3u8")
local res = ngx.location.capture(base_m3u8_url)
if res.status == 200 then
local new_body = res.body:gsub("\.ts", ".aac")
ngx.print(new_body)
else
ngx.exit(res.status)
end
';
}
location ~ /master-playlist.m3u8$ {
rewrite (.*)master-playlist.m3u8$ $1playlist.m3u8 break;
content_by_lua '
local res = ngx.location.capture(ngx.var.uri);
if res.status == 200 then
local first_playlist = res.body:match("[^\\n]*m3u8")
local audio_playlist = first_playlist:gsub("\.m3u8", "-audio.m3u8")
local ext_inf = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000\\n"
ngx.print(res.body)
ngx.print(ext_inf)
ngx.print(audio_playlist)
ngx.print("\\n")
else
ngx.exit(res.status)
end
';
}
location ~ (\.aac)$ {
ngx_hls_audio_track;
ngx_hls_audio_track_rootpath $hls_path;
expires 10m;
}
location ~ \.(ts) {
root $hls_path;
}
location ~ \.(m3u8) {
root $hls_path;
}
}
}