SHARE
TWEET

Untitled

a guest Aug 24th, 2016 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #user  nobody;
  3. worker_processes  auto;
  4.  
  5. #error_log  logs/error.log;
  6. #error_log  logs/error.log  notice;
  7. #error_log  logs/error.log  info;
  8.  
  9. #pid        logs/nginx.pid;
  10.  
  11.  
  12. events {
  13.     worker_connections  1024;
  14. }
  15.  
  16.  
  17. http {
  18.     include       mime.types;
  19.     default_type  application/octet-stream;
  20.    
  21.     sendfile off;
  22.     tcp_nopush on;
  23.     aio on;
  24.     directio 512;
  25.  
  26.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  27.     #                  '$status $body_bytes_sent "$http_referer" '
  28.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  29.  
  30.     #access_log  logs/access.log  main;
  31.  
  32.     #sendfile        on;
  33.     #tcp_nopush     on;
  34.  
  35.     #keepalive_timeout  0;
  36.     keepalive_timeout  65;
  37.  
  38.     #gzip  on;
  39.  
  40.     server {
  41.         listen       80;
  42.         server_name  localhost;
  43.  
  44.         #charset koi8-r;
  45.  
  46.         #access_log  logs/host.access.log  main;
  47.  
  48.         location / {
  49.             root   html;
  50.             index  index.html index.htm;
  51.            
  52.             # Disable cache
  53.             add_header Cache-Control no-cache;
  54.  
  55.             # CORS setup
  56.             add_header 'Access-Control-Allow-Origin' '*' always;
  57.             add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
  58.             add_header 'Access-Control-Allow-Headers' 'Range';
  59.  
  60.             # allow CORS preflight requests
  61.             if ($request_method = 'OPTIONS') {
  62.                 add_header 'Access-Control-Allow-Origin' '*';
  63.                 add_header 'Access-Control-Allow-Headers' 'Range';
  64.                 add_header 'Access-Control-Max-Age' 1728000;
  65.                 add_header 'Content-Type' 'text/plain charset=UTF-8';
  66.                 add_header 'Content-Length' 0;
  67.                 return 204;
  68.             }
  69.         }
  70.  
  71.         location /stat {
  72.             rtmp_stat all;
  73.             allow 127.0.0.1;
  74.             rtmp_stat_stylesheet stat.xsl;
  75.         }
  76.        
  77.         location /stat.xsl {
  78.             # you can move stat.xsl to a different location
  79.             # under linux you could use /var/user/www for example
  80.             root html/stats/;          
  81.         }
  82.        
  83.         location /views {
  84.             add_header Access-Control-Allow-Origin *;
  85.             proxy_pass http://127.0.0.1/stat;
  86.             xslt_stylesheet html/nclients.xsl app='$arg_app' name='$arg_name';
  87.             add_header Refresh "3; $request_uri";
  88.         }
  89.        
  90.         location /status {
  91.             add_header Access-Control-Allow-Origin *;
  92.             proxy_pass http://127.0.0.1/stat;
  93.             xslt_stylesheet html/status.xsl app='$arg_app' name='$arg_name';
  94.             add_header Refresh "3; $request_uri";
  95.         }
  96.        
  97.         location /hls {
  98.            
  99.             #alias /tmp/stream/hls;
  100.            
  101.             types {
  102.                 application/vnd.apple.mpegurl m3u8;
  103.             }
  104.            
  105.             root /tmp/stream/;
  106.            
  107.             add_header Cache-Control no-cache; # Prevent caching of HLS fragments
  108.             add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
  109.         }
  110.        
  111.         location /dash {
  112.             alias /tmp/stream/dash;
  113.        
  114.             # necessary if media files contain more than one DASH fragment
  115.             if ($request_method = 'OPTIONS') {
  116.                 add_header 'Access-Control-Allow-Credentials' 'true';
  117.                 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
  118.                
  119.                 # Custom headers and headers various browsers *should* be OK with but aren't
  120.                 add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  121.                
  122.                 # Tell client that this pre-flight info is valid for 20 days
  123.                 add_header 'Access-Control-Max-Age' 1728000;
  124.                
  125.                 add_header 'Content-Type' 'text/plain charset=UTF-8';
  126.                 add_header 'Content-Length' 0;
  127.                 add_header 'Access-Control-Allow-Origin' '*';
  128.              
  129.                 return 200;
  130.             }
  131.            
  132.             if ($request_method = 'GET') {
  133.                 add_header 'Access-Control-Allow-Origin' '*';
  134.                 add_header 'Access-Control-Allow-Credentials' 'true';
  135.                 add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  136.                 add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  137.             }
  138.            
  139.         }
  140.        
  141.         #error_page  404              /404.html;
  142.  
  143.         # redirect server error pages to the static page /50x.html
  144.         #
  145.         error_page   500 502 503 504  /50x.html;
  146.         location = /50x.html {
  147.             root   html;
  148.         }
  149.  
  150.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  151.         #
  152.         #location ~ \.php$ {
  153.         #    proxy_pass   http://127.0.0.1;
  154.         #}
  155.  
  156.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  157.         #
  158.         #location ~ \.php$ {
  159.         #    root           html;
  160.         #    fastcgi_pass   127.0.0.1:9000;
  161.         #    fastcgi_index  index.php;
  162.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  163.         #    include        fastcgi_params;
  164.         #}
  165.  
  166.         # deny access to .htaccess files, if Apache's document root
  167.         # concurs with nginx's one
  168.         #
  169.         #location ~ /\.ht {
  170.         #    deny  all;
  171.         #}
  172.     }
  173.  
  174.  
  175.     # another virtual host using mix of IP-, name-, and port-based configuration
  176.     #
  177.     #server {
  178.     #    listen       8000;
  179.     #    listen       somename:8080;
  180.     #    server_name  somename  alias  another.alias;
  181.  
  182.     #    location / {
  183.     #        root   html;
  184.     #        index  index.html index.htm;
  185.     #    }
  186.     #}
  187.  
  188.  
  189.     # HTTPS server
  190.     #
  191.     #server {
  192.     #    listen       443 ssl;
  193.     #    server_name  localhost;
  194.  
  195.     #    ssl_certificate      cert.pem;
  196.     #    ssl_certificate_key  cert.key;
  197.  
  198.     #    ssl_session_cache    shared:SSL:1m;
  199.     #    ssl_session_timeout  5m;
  200.  
  201.     #    ssl_ciphers  HIGH:!aNULL:!MD5;
  202.     #    ssl_prefer_server_ciphers  on;
  203.  
  204.     #    location / {
  205.     #        root   html;
  206.     #        index  index.html index.htm;
  207.     #    }
  208.     #}
  209.  
  210. }
  211.  
  212. rtmp {
  213.     server {
  214.         listen 1935;
  215.         chunk_size 4000;
  216.  
  217.         application live {
  218.             live on;
  219.             idle_streams off;
  220.  
  221.             #exec ffmpeg -i rtmp://localhost/live/$name
  222.             #-c:v libx264 -profile:v baseline -b:v 128K -vf "scale=360:trunc(ow/a/2)*2" -f flv -c:a #aac -ac 1 #-strict -2 -b:a 32k rtmp://localhost/hls/$name_low
  223.             #-c:v libx264 -profile:v baseline -b:v 256K -vf "scale=480:trunc(ow/a/2)*2" -f flv -c:a #aac -ac 1 #-strict -2 -b:a 96k rtmp://localhost/hls/$name_mid
  224.             #-c:v libx264 -profile:v baseline -b:v 512K -vf "scale=720:trunc(ow/a/2)*2" -f flv -c:a #aac -ac 1 #-strict -2 -b:a 128k rtmp://localhost/hls/$name_hi;
  225.            
  226.             #exec ffmpeg -i rtmp://localhost/live/$name
  227.             #-c:v libx264 -profile:v baseline -b:v 512K -vf "scale=720:trunc(ow/a/2)*2" -f flv -c:a #aac -ac 1 #-strict -2 -b:a 128k rtmp://localhost/hls/$name;
  228.            
  229.             # Once receive stream, transcode for adaptive streaming
  230.             # This single ffmpeg command takes the input and transforms
  231.             # the source into 4 different streams with different bitrate
  232.             # and quality. P.S. The scaling done here respects the aspect
  233.             # ratio of the input.
  234.             exec ffmpeg -v verbose -i rtmp://localhost/$app/$name -async 1 -vsync -1
  235.             -c:v libx264 -c:a aac -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/hls/$name_low
  236.             -c:v libx264 -c:a aac -b:v 768k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/hls/$name_mid
  237.             -c:v libx264 -c:a aac -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/hls/$name_high
  238.             -c:v libx264 -c:a aac -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/hls/$name_hd720;
  239.            
  240.             recorder videos {
  241.                 record all manual;
  242.                 record_max_size 51200K;
  243.                 record_path /usr/local/nginx/html;
  244.                 exec_record_done /ftp_bash_script.sh $name.flv;
  245.             }
  246.             recorder preview {
  247.                 record keyframes;
  248.                 record_path /var/rec;
  249.                 record_interval 5s;
  250.                 exec_record_done ffmpeg -i http://127.0.0.1/hls/$name.m3u8 -vcodec png  -vframes 1 -an -f rawvideo -s 190x100 -y /usr/local/nginx/html/scr/scr_$name.png;
  251.                 exec_record_done ffmpeg -i http://127.0.0.1/hls/$name.m3u8 -vcodec png  -vframes 1 -an -f rawvideo -s 380x200 -y /usr/local/nginx/html/scr/scr_$name@x2.png;
  252.                 exec_record_done ffmpeg -i http://127.0.0.1/hls/$name.m3u8 -vcodec png  -vframes 1 -an -f rawvideo -s 1280x720 -y /usr/local/nginx/html/scr/scr_$name@hd.png;
  253.             }
  254.         }
  255.         application hls {
  256.        
  257.             live on;
  258.             hls on;
  259.            
  260.             #hls_fragment 6s;
  261.             #hls_playlist_length 10s;
  262.             # disable consuming the stream from nginx as rtmp
  263.             #deny play all;
  264.             #hls_nested on;
  265.            
  266.             #hls_variant _low BANDWIDTH=160000;
  267.             #hls_variant _mid BANDWIDTH=320000;
  268.             #hls_variant _hi  BANDWIDTH=640000;
  269.            
  270.             hls_path /tmp/stream/hls;
  271.            
  272.             # Instruct clients to adjust resolution according to bandwidth
  273.             hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
  274.             hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
  275.             hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
  276.             hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
  277.             #hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
  278.  
  279.         }
  280.  
  281.         # MPEG-DASH is similar to HLS
  282.  
  283.         application dash {
  284.             live on;
  285.             dash on;
  286.             dash_path /tmp/stream/dash;
  287.         }
  288.     }
  289. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top