forked from gsalucci/streamplatform
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nginx.conf
125 lines (110 loc) · 6.09 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
load_module modules/ngx_rtmp_module.so;
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /var/sock;
user nginx;
error_log stderr;
pid /var/run/nginx.pid;
worker_processes auto;
events {
# Allows up to 1024 connections, can be adjusted
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
# Listen on standard RTMP port
listen 1935;
chunk_size 128;
on_connect http://localhost:8080/on_connect;
on_play http://localhost:8080/on_play;
on_play_done http://localhost:8080/on_play_done;
on_publish http://localhost:8080/on_publish;
on_publish_done http://localhost:8080/on_publish_done;
on_done http://localhost:8080/on_done;
# This application will accept the incoming stream
application live {
# Allows live input
live on;
# Once we receive the stream, we transcode it for adaptive streaming
# This single ffmpeg command takes the input stream and transforms
# the source into 4 different streams with different bitrate
# and quality. P.S. The scaling done here respects the aspect
# ratio of the input.
exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -profile:v baseline -b:v 256K -vf "scale=480:trunc(ow/a/2)*2" -f flv -c:a aac -ac 1 -strict -2 -b:a 32k rtmp://localhost/show/$name_low -c:v libx264 -profile:v baseline -b:v 768K -vf "scale=800:trunc(ow/a/2)*2" -f flv -c:a aac -ac 1 -strict -2 -b:a 96k rtmp://localhost/show/$name_mid -c:v libx264 -profile:v baseline -b:v 1920K -vf "scale=1280:trunc(ow/a/2)*2" -f flv -c:a aac -ac 1 -strict -2 -b:a 128k rtmp://localhost/show/$name_high -c copy -f flv rtmp://localhost/show/$name_src;
exec_publish_done sh -c 'echo "#EXT-X-ENDLIST" >> /tmp/hls/$name_src/index.m3u8 && echo "#EXT-X-ENDLIST" >> /tmp/hls/$name_high/index.m3u8 && echo "#EXT-X-ENDLIST" >> /tmp/hls/$name_mid/index.m3u8 && echo "#EXT-X-ENDLIST" >> /tmp/hls/$name_low/index.m3u8 && echo "#EXT-X-ENDLIST" >> /tmp/hls/$name.m3u8';
#'tee -a /tmp/hls/$name_src/index.m3u8 <<< "#EXT-X-ENDLIST" && tee -a /tmp/hls/$name_high/index.m3u8 <<< "#EXT-X-ENDLIST" && tee -a /tmp/hls/$name_mid/index.m3u8 <<< "#EXT-X-ENDLIST" && tee -a /tmp/hls/$name_low/index.m3u8 <<< "#EXT-X-ENDLIST" tee -a /tmp/hls/$name.m3u8 <<< "#EXT-X-ENDLIST"'
# Uncomment the lines below to enable recording ############
record all;
record_path /var/rec;
# record_suffix _%d%m%Y_%H%M%S.flv;
# record_unique on;
# exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 -strftime /var/rec/$name.mp4;
# exec_record_done ffmpeg -i $path -c:v libx264 -preset ultrafast -crf 17 /var/rec/$name;
# exec_record_done ffmpeg -i $path -c:a aac -strict -2 -b:a 128k -c:v libx264 -profile:v baseline /var/rec/$name;
exec_record_done sh -c 'ffmpeg -y -i $path -c:a aac -ar 44100 -ac 2 -vcodec copy -movflags faststart -f mp4 /var/rec/$name.mp4 && cd /var/rec && rm *.flv';
}
# This application will split all the streams coming in from the ffmpeg command into HLS fragments and will generate
# the master playlist ($name.m3u8 wich will reference the other variants, e.g. $name_src, $name_low etc)
application show {
live on; # Allows live input from above
hls on; # Enable HTTP Live Streaming
hls_fragment 1s;
hls_nested on; # Will put playlists'relative fragments in different folders, one for each variant e.g. all *.ts fragments
# and the playlists' .m3u8 for variant "$name_src" will be in $hls_path/$name_src/ while the master playlist will be placed in $hls_path/$name.m3u8
# Pointing this to an SSD is better as this involves lots of IO
hls_path /tmp/hls/;
# Instruct clients to adjust resolution according to bandwidth
hls_variant _low BANDWIDTH=288000;
hls_variant _mid BANDWIDTH=448000;
hls_variant _high BANDWIDTH=1152000;
hls_variant _src BANDWIDTH=4096000;
}
}
}
http {
# See http://licson.net/post/optimizing-nginx-for-large-file-delivery/ for more detail
# This optimizes the server for HLS fragment delivery
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
directio 512;
# HTTP server required to serve the player and HLS fragments
server {
listen 80;
location / {
root /www;
log_not_found off;
}
location /hls {
log_not_found off;
types {
application/vnd.apple.mpegurl m3u8;
}
root /tmp/;
add_header Cache-Control no-cache; # Prevent caching of HLS fragments
add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
}
# Proxying socketio requests to backend
location ^~ /socket.io/ {
log_not_found off;
proxy_pass http://127.0.0.1:8080/socket.io/;
# proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Generating a JSON list of available recordings
location /vod/ {
autoindex on;
autoindex_format json;
autoindex_exact_size off;
autoindex_localtime on;
alias /var/rec/;
}
}
}