Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #user nobody;
- worker_processes auto;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile off;
- tcp_nopush on;
- aio on;
- directio 512;
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main;
- #sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #gzip on;
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html;
- index index.html index.htm;
- # Disable cache
- add_header Cache-Control no-cache;
- # CORS setup
- add_header 'Access-Control-Allow-Origin' '*' always;
- add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
- add_header 'Access-Control-Allow-Headers' 'Range';
- # allow CORS preflight requests
- if ($request_method = 'OPTIONS') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Headers' 'Range';
- add_header 'Access-Control-Max-Age' 1728000;
- add_header 'Content-Type' 'text/plain charset=UTF-8';
- add_header 'Content-Length' 0;
- return 204;
- }
- }
- location /stat {
- rtmp_stat all;
- allow 127.0.0.1;
- rtmp_stat_stylesheet stat.xsl;
- }
- location /stat.xsl {
- # you can move stat.xsl to a different location
- # under linux you could use /var/user/www for example
- root html/stats/;
- }
- location /views {
- add_header Access-Control-Allow-Origin *;
- proxy_pass http://127.0.0.1/stat;
- xslt_stylesheet html/nclients.xsl app='$arg_app' name='$arg_name';
- add_header Refresh "3; $request_uri";
- }
- location /status {
- add_header Access-Control-Allow-Origin *;
- proxy_pass http://127.0.0.1/stat;
- xslt_stylesheet html/status.xsl app='$arg_app' name='$arg_name';
- add_header Refresh "3; $request_uri";
- }
- location /hls {
- #alias /tmp/stream/hls;
- types {
- application/vnd.apple.mpegurl m3u8;
- }
- root /tmp/stream/;
- add_header Cache-Control no-cache; # Prevent caching of HLS fragments
- add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
- }
- location /dash {
- alias /tmp/stream/dash;
- # necessary if media files contain more than one DASH fragment
- if ($request_method = 'OPTIONS') {
- add_header 'Access-Control-Allow-Credentials' 'true';
- add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
- # Custom headers and headers various browsers *should* be OK with but aren't
- 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';
- # Tell client that this pre-flight info is valid for 20 days
- add_header 'Access-Control-Max-Age' 1728000;
- add_header 'Content-Type' 'text/plain charset=UTF-8';
- add_header 'Content-Length' 0;
- add_header 'Access-Control-Allow-Origin' '*';
- return 200;
- }
- if ($request_method = 'GET') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Credentials' 'true';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- 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';
- }
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
- # another virtual host using mix of IP-, name-, and port-based configuration
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- # HTTPS server
- #
- #server {
- # listen 443 ssl;
- # server_name localhost;
- # ssl_certificate cert.pem;
- # ssl_certificate_key cert.key;
- # ssl_session_cache shared:SSL:1m;
- # ssl_session_timeout 5m;
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ssl_prefer_server_ciphers on;
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
- }
- rtmp {
- server {
- listen 1935;
- chunk_size 4000;
- application live {
- live on;
- idle_streams off;
- #exec ffmpeg -i rtmp://localhost/live/$name
- #-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
- #-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
- #-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;
- #exec ffmpeg -i rtmp://localhost/live/$name
- #-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;
- # Once receive stream, transcode for adaptive streaming
- # This single ffmpeg command takes the input and transforms
- # the source into 4 different streams with different bitrate
- # and quality. P.S. The scaling done here respects the aspect
- # ratio of the input.
- exec ffmpeg -v verbose -i rtmp://localhost/$app/$name -async 1 -vsync -1
- -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
- -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
- -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
- -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;
- recorder videos {
- record all manual;
- record_max_size 51200K;
- record_path /usr/local/nginx/html;
- exec_record_done /ftp_bash_script.sh $name.flv;
- }
- recorder preview {
- record keyframes;
- record_path /var/rec;
- record_interval 5s;
- 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;
- 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;
- 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;
- }
- }
- application hls {
- live on;
- hls on;
- #hls_fragment 6s;
- #hls_playlist_length 10s;
- # disable consuming the stream from nginx as rtmp
- #deny play all;
- #hls_nested on;
- #hls_variant _low BANDWIDTH=160000;
- #hls_variant _mid BANDWIDTH=320000;
- #hls_variant _hi BANDWIDTH=640000;
- hls_path /tmp/stream/hls;
- # Instruct clients to adjust resolution according to bandwidth
- hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
- hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
- hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
- hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
- #hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
- }
- # MPEG-DASH is similar to HLS
- application dash {
- live on;
- dash on;
- dash_path /tmp/stream/dash;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement