├── Dockerfile ├── README.md ├── nginx.conf └── static └── stat.xsl /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | 3 | ENV DEBIAN_FRONTEND noninteractive 4 | ENV PATH $PATH:/usr/local/nginx/sbin 5 | 6 | EXPOSE 1935 7 | EXPOSE 80 8 | 9 | # create directories 10 | RUN mkdir /src /config /logs /data /static 11 | 12 | # update and upgrade packages 13 | RUN apt-get update && \ 14 | apt-get upgrade -y && \ 15 | apt-get clean && \ 16 | apt-get install -y --no-install-recommends build-essential \ 17 | wget software-properties-common && \ 18 | # ffmpeg 19 | add-apt-repository ppa:mc3man/trusty-media && \ 20 | apt-get update && \ 21 | apt-get install -y --no-install-recommends ffmpeg && \ 22 | # nginx dependencies 23 | apt-get install -y --no-install-recommends libpcre3-dev \ 24 | zlib1g-dev libssl-dev wget && \ 25 | rm -rf /var/lib/apt/lists/* 26 | 27 | # get nginx source 28 | WORKDIR /src 29 | RUN wget http://nginx.org/download/nginx-1.7.5.tar.gz && \ 30 | tar zxf nginx-1.7.5.tar.gz && \ 31 | rm nginx-1.7.5.tar.gz && \ 32 | # get nginx-rtmp module 33 | wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.6.tar.gz && \ 34 | tar zxf v1.1.6.tar.gz && \ 35 | rm v1.1.6.tar.gz 36 | 37 | # compile nginx 38 | WORKDIR /src/nginx-1.7.5 39 | RUN ./configure --add-module=/src/nginx-rtmp-module-1.1.6 \ 40 | --conf-path=/config/nginx.conf \ 41 | --error-log-path=/logs/error.log \ 42 | --http-log-path=/logs/access.log && \ 43 | make && \ 44 | make install 45 | 46 | ADD nginx.conf /config/nginx.conf 47 | ADD static /static 48 | 49 | WORKDIR / 50 | CMD "nginx" 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NGINX RTMP Dockerfile 2 | ===================== 3 | 4 | This Dockerfile installs NGINX configured with `nginx-rtmp-module`, ffmpeg 5 | and some default settings for HLS live streaming. 6 | 7 | **Note: in the current state, this is just an experimental project to play with 8 | RTMP and HLS.** 9 | 10 | 11 | How to use 12 | ---------- 13 | 14 | 1. Build and run the container (`docker build -t nginx_rtmp .` & 15 | `docker run -p 1935:1935 -p 8080:80 --rm nginx_rtmp`). 16 | 17 | 2. Stream your live content to `rtmp://localhost:1935/encoder/stream_name` where 18 | `stream_name` is the name of your stream. 19 | 20 | 3. In Safari, VLC or any HLS compatible browser / player, open 21 | `http://localhost:8080/hls/stream_name.m3u8`. Note that the first time, 22 | it might take a few (10-15) seconds before the stream works. This is because 23 | when you start streaming to the server, it needs to generate the first 24 | segments and the related playlists. 25 | 26 | 27 | Links 28 | ----- 29 | 30 | * http://nginx.org/ 31 | * https://github.com/arut/nginx-rtmp-module 32 | * https://www.ffmpeg.org/ 33 | * https://obsproject.com/ 34 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | daemon off; 2 | 3 | events { 4 | worker_connections 1024; 5 | } 6 | 7 | error_log stderr; 8 | 9 | rtmp { 10 | server { 11 | listen 1935; 12 | chunk_size 4000; 13 | 14 | application encoder { 15 | live on; 16 | 17 | exec ffmpeg -i rtmp://localhost:1935/encoder/$name 18 | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs 19 | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs 20 | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs 21 | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p528kbs 22 | -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p264kbs; 23 | } 24 | 25 | application hls { 26 | live on; 27 | hls on; 28 | hls_fragment_naming system; 29 | hls_fragment 5s; 30 | hls_path /data/hls; 31 | hls_nested on; 32 | 33 | hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720; 34 | hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480; 35 | hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360; 36 | hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=426x240; 37 | hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=426x240; 38 | } 39 | } 40 | } 41 | 42 | http { 43 | server { 44 | listen 80; 45 | 46 | location /hls { 47 | types { 48 | application/vnd.apple.mpegurl m3u8; 49 | video/mp2t ts; 50 | } 51 | root /data; 52 | add_header Cache-Control no-cache; 53 | add_header Access-Control-Allow-Origin * always; 54 | } 55 | 56 | location /stat { 57 | rtmp_stat all; 58 | rtmp_stat_stylesheet static/stat.xsl; 59 | } 60 | 61 | location /static { 62 | alias /static; 63 | } 64 | 65 | location /crossdomain.xml { 66 | default_type text/xml; 67 | return 200 ' 68 | 69 | 70 | 71 | 72 | 73 | '; 74 | expires 24h; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /static/stat.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | RTMP statistics 16 | 17 | 18 | 19 |
20 | Generated by 21 | nginx-rtmp-module , 22 | nginx , 23 | pid , 24 | built   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 | 58 | 63 | 70 | 77 | 83 | 84 | 85 |
RTMP#clientsVideoAudioIn bytesOut bytesIn bits/sOut bits/sStateTime
Accepted: codecbits/ssizefpscodecbits/sfreqchan 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 64 | 65 | 66 | 67 | 68 | 69 | 71 | 72 | 73 | 74 | 75 | 76 | 78 | 79 | 80 | 81 | 82 |
86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | live streams 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | vod streams 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | #cccccc 131 | #dddddd 132 | 133 | 134 | 135 | 136 | 137 | var d=document.getElementById('-'); 138 | d.style.display=d.style.display=='none'?'':'none'; 139 | return false 140 | 141 | 142 | 143 | [EMPTY] 144 | 145 | 146 | 147 | 148 | 149 |    150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 |   166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | - 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 |
IdStateAddressFlash versionPage URLSWF URLDroppedTimestampA-VTime
231 | 232 | 233 |
234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | d 245 | 246 | 247 | 248 | h 249 | 250 | 251 | 252 | m 253 | 254 | 255 | s 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | T 269 | 270 | 271 | G 272 | 273 | 274 | M 275 | 276 | K 277 | 278 | 279 | 280 | b 281 | B 282 | 283 | /s 284 | 285 | 286 | 287 | 288 | 289 | active 290 | idle 291 | 292 | 293 | 294 | 295 | 296 | 297 | publishing 298 | playing 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | #cccccc 308 | #eeeeee 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | http://apps.db.ripe.net/search/query.html?searchtext= 317 | 318 | whois 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | publishing 345 | 346 | 347 | 348 | active 349 | 350 | 351 | 352 | x 353 | 354 | 355 |
--------------------------------------------------------------------------------