|
|
@@ -0,0 +1,88 @@
|
|
|
+user root;
|
|
|
+worker_processes auto;
|
|
|
+events {
|
|
|
+ # Allows up to 1024 connections, can be adjusted
|
|
|
+ worker_connections 1024;
|
|
|
+}
|
|
|
+
|
|
|
+# RTMP configuration
|
|
|
+rtmp {
|
|
|
+ server {
|
|
|
+ listen 1935; # Listen on standard RTMP port
|
|
|
+ chunk_size 8192;
|
|
|
+
|
|
|
+ # This application is to accept incoming stream
|
|
|
+ application live {
|
|
|
+ live on; # Allows live input
|
|
|
+ wait_key on;
|
|
|
+ # Once receive stream, transcode for adaptive streaming
|
|
|
+ # This single ffmpeg command takes the input 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 /opt/hls.sh $name;
|
|
|
+ }
|
|
|
+
|
|
|
+ # This application is for splitting the stream into HLS fragments
|
|
|
+ application low {
|
|
|
+ live on; # Allows live input from above
|
|
|
+ hls on; # Enable HTTP Live Streaming
|
|
|
+ wait_key on;
|
|
|
+ wait_video on;
|
|
|
+ hls_cleanup off;
|
|
|
+ hls_nested on;
|
|
|
+ hls_playlist_length 2100ms;
|
|
|
+ hls_fragment 700ms;
|
|
|
+ hls_fragment_naming system;
|
|
|
+
|
|
|
+ # Pointing this to an SSD is better as this involves lots of IO
|
|
|
+ hls_path /hls;
|
|
|
+
|
|
|
+ # Instruct clients to adjust resolution according to bandwidth
|
|
|
+ hls_variant _low BANDWIDTH=288000,RESOLUTION=640x480;
|
|
|
+ }
|
|
|
+
|
|
|
+ application src {
|
|
|
+ live on; # Allows live input from above
|
|
|
+ hls on; # Enable HTTP Live Streaming
|
|
|
+ wait_key on;
|
|
|
+ wait_video on;
|
|
|
+ hls_cleanup off;
|
|
|
+ hls_nested on;
|
|
|
+ hls_playlist_length 2100ms;
|
|
|
+ hls_fragment 700ms;
|
|
|
+ hls_fragment_naming system;
|
|
|
+
|
|
|
+ # Pointing this to an SSD is better as this involves lots of IO
|
|
|
+ hls_path /hls;
|
|
|
+
|
|
|
+ # Instruct clients to adjust resolution according to bandwidth
|
|
|
+ hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+http {
|
|
|
+ # See http://licson.net/post/optimizing-nginx-for-large-file-delivery/ for more detail
|
|
|
+ # This optimizes the server for HLS fragment delivery
|
|
|
+ sendfile off;
|
|
|
+ tcp_nopush on;
|
|
|
+ #aio on;
|
|
|
+ directio 512;
|
|
|
+
|
|
|
+ # HTTP server required to serve the player and HLS fragments
|
|
|
+ server {
|
|
|
+ listen 8080;
|
|
|
+ error_log /var/log/nginx/rtmp-error.log;
|
|
|
+
|
|
|
+ location /show {
|
|
|
+ types {
|
|
|
+ application/vnd.apple.mpegurl m3u8;
|
|
|
+ }
|
|
|
+
|
|
|
+ alias /hls;
|
|
|
+ add_header Cache-Control no-cache; # Prevent caching of HLS fragments
|
|
|
+ add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|