nginx-rtmp.conf.epp 3.46 KB
Newer Older
hark's avatar
hark committed
1
<%- | 
hark's avatar
hark committed
2
      String    $hostname = 'localhost',
hark's avatar
hark committed
3
      String    $ffmpeg_binary = 'ffmpeg',
hark's avatar
hark committed
4
      String    $record_path = '/srv/rtmprec',
hark's avatar
hark committed
5
      String    $relay_server = 'Zombie:Apocalyps3N0w.@intergalactic.tv',
hark's avatar
hark committed
6
7
8
9
10
      String    $hls_path = '/tmp/hls',
      String    $ssl_key = '/etc/ssl/private/ssl-cert-snakeoil.key',
      String    $ssl_cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem',

| -%>
hark's avatar
hark committed
11
load_module modules/ngx_rtmp_module.so;
hark's avatar
hark committed
12
13
14

# receives rtmp streams and fragements them into hls

hark's avatar
hark committed
15
#include /usr/share/nginx/modules-available/mod-rtmp.conf;
hark's avatar
hark committed
16

hark's avatar
hark committed
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
rtmp {
	server {
		listen 1935;
		ping 30s;
		notify_method get;

		application streams {
			live on;

#request: "GET /on_publish?app=streams&flashver=FMLE/3.0%20(compatible%3B%20FMSc/1.0)&swfurl=rtmp://admamsterdam.net/streams&tcurl=rtmp://admamsterdam.net/streams&pageurl=&addr=82.161.145.133&clientid=1&call=publish&name=leftover&type=live HTTP/1.0", host: "localhost"

# sample play/publish handlers
# on_play http://localhost:8080/on_play;
# on_publish http://localhost:8080/on_publish;
#			on_record_done http://localhost:8080/on_record_done/$recorder/$path;

#exec /run/current-system/sw/bin/ffmpeg -i rtmp://localhost/streams/$name
#              -c:a libfdk_aac -b:a 32k  -c:v libx264 -b:v 128K -f flv rtmp://localhost/hls/$name_low
#              -c:a libfdk_aac -b:a 64k  -c:v libx264 -b:v 256k -f flv rtmp://localhost/hls/$name_mid
#              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost/hls/$name_hi;
# -c:v copy -c:a copy -f flv "rtmp://<user>:<pass>@intergalactic.tv/show/leftover
      
      #relays the incoming video to a low quality stream on this server, and to a different server
			exec <%= $ffmpeg_binary %> -i rtmp://localhost/streams/$name
				-c:a copy  -c:v libx264 -b:v 128K -f flv rtmp://localhost/hls/$name_low
				-c:a copy -vn  -f flv rtmp://localhost/hls/$name_audio
				-c:a copy  -c:v copy -f flv rtmp://localhost/hls/$name_hi
				-c:v copy -c:a copy -f flv "rtmp://<%= $relay_server %>/show/$name";

			recorder video {
				record all;
				record_path <%= $record_path %>/streams;
				record_suffix _video.flv;

				record_unique on;
			}
			recorder audio {
				record audio;
				record_path <%= $record_path %>/streams;
				record_suffix _audio.flv;
				record_unique on;
				exec_record_done ffmpeg -i $path -metadata title="$basename" year="2019" -c:a libmp3lame <%= $record_path %>/streams/$basename.mp3;

			}

      # HLS on /hls
			hls on;
			hls_path <%= $hls_path %>/streams ;
			hls_sync 100ms;

			hls_fragment_naming system;
		} # end streams

    # to send video to be recorded on server (not played live)
		application input{
			live on;
      #records audio + video
			recorder video {
				record all;
				record_path <%= $record_path %>/inputrec;
				record_suffix _video.flv;

				record_unique on;
			}
      #records audio
			recorder audio {
				record audio;
				record_path <%= $record_path %>/inputrec;
				record_suffix _audio.flv;
				record_unique on;
        # convert to mp3
				exec_record_done ffmpeg -i $path -metadata title="$basename" year="2020" -c:a libmp3lame <%= $record_path %>/inputrec/$basename.mp3;

			}

# HLS on /hls
			hls on;
			hls_path <%= $hls_path %>/inputhls;
			hls_sync 100ms;

			hls_fragment_naming system;

		}


		application hls {
			live on;

			hls on;
			hls_path <%= $hls_path %>/variants;
			hls_nested on;

			hls_variant _low BANDWIDTH=160000;
			hls_variant _audio BANDWIDTH=500;
			hls_variant _hi  BANDWIDTH=640000;
		}

	} # end server
} # end rtmp