nginx.conf 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. user root;
  2. worker_processes auto;
  3. events {
  4. # Allows up to 1024 connections, can be adjusted
  5. worker_connections 1024;
  6. }
  7. # RTMP configuration
  8. rtmp {
  9. server {
  10. listen 1935; # Listen on standard RTMP port
  11. chunk_size 8192;
  12. # This application is to accept incoming stream
  13. application live {
  14. live on; # Allows live input
  15. wait_key on;
  16. # Once receive stream, transcode for adaptive streaming
  17. # This single ffmpeg command takes the input and transforms
  18. # the source into 4 different streams with different bitrate
  19. # and quality. P.S. The scaling done here respects the aspect
  20. # ratio of the input.
  21. exec /opt/hls.sh $name;
  22. }
  23. # This application is for splitting the stream into HLS fragments
  24. application low {
  25. live on; # Allows live input from above
  26. hls on; # Enable HTTP Live Streaming
  27. wait_key on;
  28. wait_video on;
  29. hls_cleanup off;
  30. hls_nested on;
  31. hls_playlist_length 2100ms;
  32. hls_fragment 700ms;
  33. hls_fragment_naming system;
  34. # Pointing this to an SSD is better as this involves lots of IO
  35. hls_path /hls;
  36. # Instruct clients to adjust resolution according to bandwidth
  37. hls_variant _low BANDWIDTH=288000,RESOLUTION=640x480;
  38. }
  39. application src {
  40. live on; # Allows live input from above
  41. hls on; # Enable HTTP Live Streaming
  42. wait_key on;
  43. wait_video on;
  44. hls_cleanup off;
  45. hls_nested on;
  46. hls_playlist_length 2100ms;
  47. hls_fragment 700ms;
  48. hls_fragment_naming system;
  49. # Pointing this to an SSD is better as this involves lots of IO
  50. hls_path /hls;
  51. # Instruct clients to adjust resolution according to bandwidth
  52. hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
  53. }
  54. }
  55. }
  56. http {
  57. # See http://licson.net/post/optimizing-nginx-for-large-file-delivery/ for more detail
  58. # This optimizes the server for HLS fragment delivery
  59. sendfile off;
  60. tcp_nopush on;
  61. #aio on;
  62. directio 512;
  63. # HTTP server required to serve the player and HLS fragments
  64. server {
  65. listen 8080;
  66. error_log /var/log/nginx/rtmp-error.log;
  67. location /show {
  68. types {
  69. application/vnd.apple.mpegurl m3u8;
  70. }
  71. alias /hls;
  72. add_header Cache-Control no-cache; # Prevent caching of HLS fragments
  73. add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
  74. }
  75. }
  76. }