NGNIX + RTMP Server Block Example RTMP+M3U8 Streaming

July 2nd, 2015 by
Replace the example.com and rtmp://STREAMURL with your information.
server {
        listen       80;
        server_name  example.com;


        location / {
            root   html;
            index  index.html index.htm;
        }

   # path to HLS application service
       location /media_server {
          			 types {
              			 application/vnd.apple.mpegurl m3u8;
              			 video/mp2t ts;
          			 }
           			root /home/user/tmp;
          			 add_header Cache-Control no-cache;
       			      }
}

rtmp {
   server {
       listen 1935;
       chunk_size 4000;
       # Transcoding (ffmpeg needed)
       application media_server {
           live on;
           hls on;
           hls_path /home/user/tmp/media_server;
           hls_nested on;
           hls_variant _low  BANDWIDTH=640000;
           hls_variant _hi  BANDWIDTH=2140000;
           # ffmpeg static execution
           exec_static /usr/bin/ffmpeg -i rtmp://STREAMURL
               -c:v libx264 -g 50 -preset fast -b:v 4096k -c:a libfdk_aac -ar 44100 -f flv rtmp://127.0.0.1/media_server/stream_hi
               -c:v libx264 -g 50 -preset fast -b:v 1024k -c:a libfdk_aac -ar 44100 -f flv rtmp://127.0.0.1/media_server/stream_low;
       }
   }
}

Post a Comment

You must be logged in to post a comment.

Cached at: 2024-04-26 07:31:46pm