Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- worker_processes auto;
- events {
- worker_connections 768; # Max clients = worker_processes * worker_connections. In this example: 1 * 768 = 768 max clients.
- # multi_accept on; # "Off" will accept 1 new connection at a time. "On" will accept all new connections. Default is off.
- }
- rtmp {
- server {
- listen 1935; # This is the listening port. Open it on your router and/ or allow it in your firewall. These variables are possible:
- # (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt|proxy_protocol].
- chunk_size 4096; # Max chunk size for multiplexing. The bigger this value, the lower CPU overhead. Cannot be < 128. Default=4096.
- application live { # Name it whatever you prefer. You will need at least one application, but you can have many more applications.
- live on; # on|off. Enables this application and allowing live streaming to it. Default=on.
- ## TRANSCODING USING FFMPEG EXEC ##
- ## The following lines will take our incoming RTMP stream and transcode it to several different HLS streams with variable bitrates ##
- ## Once receive stream, transcode for adaptive streaming. This single ffmpeg command takes the input and transforms the source into ##
- ## 4 or 5 different streams with different bitrate and quality. P.S. The scaling done here respects the aspect ratio of the input. ##
- ## EXEC - Many things are possible using exec. To learn more visit https://github.com/arut/nginx-rtmp-module/wiki/Directives#exec ##
- exec ffmpeg -i rtmp://localhost/$app/$name -async 1 -vsync -1
- -c:v libx264 -c:a libvo_aacenc -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 libvo_aacenc -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 libvo_aacenc -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 libvo_aacenc -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_ higher
- -c copy -f flv rtmp://localhost/hls/$name_src;
- }
- application hls { # This application is for splitting the stream into HLS fragments
- live on; # on|off. Enables this application and allowing live streaming to it. Default=on.
- hls on; # on|off. Toggles HLS on or off for this application. Enables HTTP Live Streaming.
- hls_path /tmp/hls; # Location to store the video fragment files. Will be created if it doesn't exist.
- ## HLS_VARIANT - Used for variable bitrate streaming. Please read: https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_variant ##
- ## When hls_variant suffix is matched on stream name then variant playlist is created for the current stream with all entries specified by hls_variant
- ## directives in current application. Stripped name without suffix is used as variant stream name. The original stream is processed as usual.
- ## Optional parameters following the suffix are appended to EXT-X-STREAM-INF in m3u8 playlist. See HLS spec 3.3.10. EXT-X-STREAM-INF for full list.
- hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
- hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
- hls_variant _high BANDWIDTH=1152000; # Higher-than-SD resolution
- hls_variant _higher BANDWIDTH=2048000; # High bitrate, HD 720p resolution
- hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
- }
- }
- }
- http {
- sendfile off; # on|off. Toggles the use of sendfile. Default=off. For optimal HLS delivery disable this.
- tcp_nodelay on; # on|off. Forces a socket to send the data in its buffer, whatever the packet size. Default=on.
- tcp_nopush on; # on|off. Sends the response header and beginning of a file in one packet. Default=off.
- server_tokens off; # on|off|build. Toggles showing nginx version in the response header field. Default=on.
- default_type application/octet-stream; # Emit this MIME type for all requests.
- server {
- listen 80;
- gzip off;
- server_name localhost;
- index index.html index.htm index.nginx-debian.html;
- location / {
- root /var/www/html/;
- add_header Strict-Transport-Security "max-age=63072000;";
- }
- location /hls {
- expires -1;
- autoindex on;
- types {
- application/vnd.apple.mpegurl m3u8;
- text/html html;
- }
- # root /tmp/;
- alias /tmp/hls;
- add_header Cache-Control no-cache; # Prevent caching of HLS fragments
- add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
- }
- }
- }
Add Comment
Please, Sign In to add comment