ustoopia

nginx.conf for HLS RTMP streaming

Mar 29th, 2019
5,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. user www-data;
  2. worker_processes 1;
  3. pid /run/nginx.pid;
  4. include /etc/nginx/modules-enabled/*.conf;
  5.  
  6. events {
  7. worker_connections 768;
  8. # multi_accept on;
  9. }
  10.  
  11. http {
  12. sendfile off;
  13. tcp_nopush on;
  14. tcp_nodelay on;
  15. keepalive_timeout 65;
  16. types_hash_max_size 2048;
  17. # server_tokens off;
  18.  
  19. # server_names_hash_bucket_size 64;
  20. # server_name_in_redirect off;
  21.  
  22. include /etc/nginx/mime.types;
  23. default_type application/octet-stream;
  24.  
  25. access_log /var/log/nginx/access.log;
  26. error_log /var/log/nginx/error.log;
  27.  
  28. gzip on;
  29.  
  30. # gzip_vary on;
  31. # gzip_proxied any;
  32. # gzip_comp_level 6;
  33. # gzip_buffers 16 8k;
  34. # gzip_http_version 1.1;
  35. # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  36.  
  37. include /etc/nginx/conf.d/*.conf;
  38. include /etc/nginx/sites-enabled/*;
  39. }
  40.  
  41.  
  42. rtmp {
  43. server {
  44. listen 1935;
  45. chunk_size 8192;
  46.  
  47. application live {
  48. live on;
  49. interleave off;
  50. meta on;
  51. wait_key on;
  52. wait_video on;
  53. idle_streams off;
  54. sync 300ms;
  55. session_relay on;
  56. allow publish all;
  57. # deny publish all;
  58. # disable consuming the stream from nginx as rtmp #
  59. # deny play all;
  60. allow play all;
  61. #respawn on;
  62. #respawn_timeout 10s;
  63. # drop_idle_publisher 60s;
  64.  
  65. ## == RECORDING OPTIONS: OFF/ALL == ##
  66. # default recorder #
  67. record off;
  68. record_suffix all-%d-%b-%y-%T.flv;
  69. record_path /var/www/recordings;
  70. record_max_size 4096M;
  71. record_unique on;
  72. record_append off;
  73. record_lock on;
  74.  
  75. ## == FORWARD STREAM (OPTIONAL) == ##
  76. # == == TWITCH RE-STREAM == == #
  77. # push rtmp://live-ams.twitch.tv/app/LIVESTREAM_KEY;
  78. # == == YOUTUBE RE-STREAM == == #
  79. # push rtmp://a.rtmp.youtube.com/live2/LIVESTREAM_KEY;
  80. # == == MIXER.com RE-STREAM == == #
  81. # push rtmp://ingest-ams.mixer.com:1935/beam/LIVESTREAM_KEY;
  82.  
  83. publish_notify off;
  84. # play_restart off;
  85. # on_publish http://your-website/on_publish.php;
  86. # on_play http://your-website/on_play.php;
  87. # on_record_done http://your-website/on_record_done.php;
  88.  
  89. ## == HLS == ##
  90. hls on;
  91. hls_nested on;
  92. hls_path /var/www/hls/live;
  93. # hls_base_url http://abc.de:1953/hls;
  94. hls_playlist_length 60s;
  95. hls_fragment 10s;
  96. hls_sync 100ms;
  97. hls_cleanup on;
  98.  
  99. ## == DASH == ##
  100. dash on;
  101. dash_nested on;
  102. dash_path /var/www/dash;
  103. dash_fragment 10s;
  104. dash_playlist_length 60s;
  105. dash_cleanup on;
  106.  
  107. # == creates the downsampled or "trans-rated" mobile video stream as a 400kbps, re-sized video == #
  108. # exec ffmpeg -i rtmp://localhost/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -vf scale=-2:360,setdar=16:9 -b:v 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://localhost/low/${name};
  109.  
  110. # https://selimatmaca.com/index.php/live-streaming/165-adaptive-bitrate-streaming-with-nginx-and-videojs #
  111. }
  112.  
  113. # application liveout {
  114. # live on;
  115. # hls on;
  116. # hls_path /var/www/hls/liveout;
  117. # hls_fragment 10s;
  118. # hls_playlist_length 60s;
  119. # allow play all;
  120. # allow publish 127.0.0.1;
  121. # allow publish 192.168.2.88;
  122. # allow publish 192.168.2.0/24;
  123. # deny publish all;
  124.  
  125. # # hls_variant _240 BANDWIDTH=288000;
  126. # hls_variant _360 BANDWIDTH=448000;
  127. # hls_variant _480 BANDWIDTH=1152000;
  128. # hls_variant _720 BANDWIDTH=2048000;
  129. # # hls_variant _1080 BANDWIDTH=4096000;
  130. # }
  131.  
  132. application hls {
  133. live on;
  134. allow play all;
  135. hls on;
  136. hls_path /var/www/hls;
  137. hls_fragment 10s;
  138. hls_playlist_length 60s;
  139. }
  140.  
  141. # Creates "mobile" lower-res HLS videostream from ffmpeg-created stream and where to put the manifest and video fragments #
  142. application low {
  143. live on;
  144. allow play all;
  145. hls on;
  146. hls_nested on;
  147. hls_path /var/www/hls/low;
  148. hls_fragment 10s;
  149. hls_playlist_length 60s;
  150. }
  151.  
  152. # application ipcam {
  153. # live on;
  154. # exec_pull ffmpeg -i rtsp://192.168.4.250:554/h264.sdp -c copy -f flv rtmp://localhost/ipcam/h264;
  155. # exec_pull ffmpeg -i rtsp://192.168.4.250:554/mjpeg.sdp -c copy -f flv rtmp://localhost/ipcam/mjpeg;
  156. # }
  157.  
  158. # Allows playing earlier recorded files #
  159. application vod {
  160. play /var/www/recordings;
  161. allow play all;
  162. }
  163. application vod_http {
  164. play http://yourserver.ddns.net/recordings;
  165. allow play all;
  166. }
  167. # application vod_mirror {
  168. # # try local location first, then access remote location
  169. # play /var/www/recordings http://yourserver.ddns.net/vods;
  170. # }
  171. }
  172. }
Add Comment
Please, Sign In to add comment