nginx.conf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #daemon off;
  2. error_log /dev/stdout info;
  3. events {
  4. worker_connections 1024;
  5. }
  6. rtmp {
  7. # 从20M增加到50M,因为4K视频帧可能会更大
  8. max_message 50M;
  9. server {
  10. listen ${RTMP_PORT};
  11. # 从4000增加到8192,提高传输效率
  12. chunk_size 8192;
  13. application stream {
  14. live on;
  15. exec ffmpeg -i rtmp://localhost:1935/stream/$name
  16. # 4K (2160p) - 比特率设置为 20Mbps
  17. -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 20000k -f flv -g 60 -r 60 -s 3840x2160 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_2160p20000kbs
  18. # 2K (1440p) - 比特率设置为 12Mbps
  19. -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 12000k -f flv -g 60 -r 60 -s 2560x1440 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1440p12000kbs
  20. # 1080p - 比特率设置为 6Mbps
  21. -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 6000k -f flv -g 60 -r 60 -s 1920x1080 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1080p6000kbs
  22. # 720p
  23. -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
  24. # 480p
  25. -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
  26. # 360p
  27. -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;
  28. }
  29. application hls {
  30. live on;
  31. hls on;
  32. hls_fragment_naming system;
  33. hls_fragment 5;
  34. hls_playlist_length 10;
  35. hls_path /opt/data/hls;
  36. hls_nested on;
  37. # 添加新的分辨率变体
  38. hls_variant _2160p20000kbs BANDWIDTH=20192000,RESOLUTION=3840x2160;
  39. hls_variant _1440p12000kbs BANDWIDTH=12192000,RESOLUTION=2560x1440;
  40. hls_variant _1080p6000kbs BANDWIDTH=6192000,RESOLUTION=1920x1080;
  41. hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
  42. hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
  43. hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
  44. }
  45. }
  46. }
  47. http {
  48. include mime.types;
  49. default_type application/octet-stream;
  50. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  51. '$status $body_bytes_sent "$http_referer" '
  52. '"$http_user_agent" "$http_x_forwarded_for"';
  53. access_log /dev/stdout main;
  54. root /www/static;
  55. sendfile off;
  56. tcp_nopush on;
  57. server_tokens off;
  58. # 安全设置
  59. add_header X-Frame-Options "SAMEORIGIN";
  60. add_header X-XSS-Protection "1; mode=block";
  61. add_header X-Content-Type-Options "nosniff";
  62. # 超时设置
  63. client_body_timeout 12;
  64. client_header_timeout 12;
  65. keepalive_timeout 65;
  66. server {
  67. listen ${HTTP_PORT};
  68. location /hls {
  69. types {
  70. application/vnd.apple.mpegurl m3u8;
  71. video/mp2t ts;
  72. }
  73. root /opt/data;
  74. add_header Cache-Control no-cache;
  75. add_header Access-Control-Allow-Origin *;
  76. }
  77. location /live {
  78. alias /opt/data/hls;
  79. types {
  80. application/vnd.apple.mpegurl m3u8;
  81. video/mp2t ts;
  82. }
  83. add_header Cache-Control no-cache;
  84. add_header Access-Control-Allow-Origin *;
  85. }
  86. location /stat {
  87. rtmp_stat all;
  88. rtmp_stat_stylesheet stat.xsl;
  89. }
  90. location /stat.xsl {
  91. root /www/static;
  92. }
  93. location = /healthcheck {
  94. access_log off;
  95. add_header Content-Type text/plain;
  96. return 200 'ok';
  97. allow 127.0.0.1;
  98. deny all;
  99. }
  100. location /crossdomain.xml {
  101. default_type text/xml;
  102. expires 24h;
  103. }
  104. }
  105. }