Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### ======================================================================================================== ####
- #### NGINX.CONF ####
- #### Go to this page for a list of all variables: https://github.com/arut/nginx-rtmp-module/wiki/Directives ####
- #### Go to this site for many more configuration examples: https://github.com/arut/nginx-rtmp-module ####
- #### This Nginx config file was put together by "ustoopia" for a setup tutorial at https://www.ustoopia.nl ####
- #### ======================================================================================================== ####
- user www-data; # The server will run as this user & group.
- worker_processes 1; # Using 1 will results in a reliable /stat page. Set to auto or a specific number.
- pid /run/nginx.pid;
- include /etc/nginx/modules-enabled/*.conf; # Include all the .conf files located in this folder.
- events {
- worker_connections 768; #
- # multi_accept on;
- }
- http {
- sendfile off; # Default=on. Toggles the use of sendfile. For optimal HLS delivery disable this.
- tcp_nopush on; # Default=off. Sends the response header and beginning of a file in one packet.
- tcp_nodelay on; # Default=on. Forces a socket to send data in its buffer, whatever packet size.
- server_tokens off; # Default=on. Enables/disables the server signature.
- keepalive_timeout 65;
- types_hash_max_size 2048;
- server_name_in_redirect off;
- server_names_hash_bucket_size 64;
- default_type application/octet-stream;
- ssl_protocols TLSv1.2 TLSv1.3;
- ssl_prefer_server_ciphers on;
- #### This logging format is optimal for Amplify monitoring (https://amplify.nginx.com) ####
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for" $request_time';
- access_log /var/log/nginx/access.log main;
- error_log /var/log/nginx/error.log warn;
- gzip off; # Compresses responses using gzip method. Helps to reduce size of transmitted data by half or more.
- # gzip_vary on;
- # gzip_proxied any;
- # gzip_comp_level 6;
- # gzip_buffers 16 8k;
- # gzip_http_version 1.1;
- # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
- include /etc/nginx/mime.types; # This will include the mime.types. Do not remove this.
- include /etc/nginx/conf.d/*.conf; # This line will include all the config files in this folder to our configuration.
- include /etc/nginx/sites-enabled/*; # This line will include all the virtual hosts file to our configuration.
- } # HTTP closing tag
- #### RTMP SERVER ####
- rtmp {
- server {
- listen 1935; # The port where RTMP will listen on. Default = 1935.
- chunk_size 4096;
- timeout 30s;
- buflen 1s;
- #### THE /LIVE APPLICATION WILL BE USED TO SEND OUR LIVESTREAM TO, INCLUDING A STREAMKEY. ####
- application live { # The /live application will receive the incoming live-stream.
- live on; # Enable/disable the live application.
- interleave off; # Audio and video data is transmitted on the same RTMP chunk stream. Default=off.
- wait_key off; # Makes video stream start with a key frame. Default=off.
- wait_video off; # Disable audio until first video frame is sent (can cause delay). Default=off.
- idle_streams off; # If disabled prevents viewers from connecting to idle/nonexistent streams and disconnects all.
- drop_idle_publisher off; # Drop publisher that has been idle for this time.
- allow publish all; # Default=all. Anybody can stream to our server. Change this to restrict this behaviour.
- # deny publish all; # Enable this in case you set an IP address for previous option allow publish.
- # deny publish 10.0.0.9 # Example of how to deny access from a specific IP. Uncomment to use.
- allow play 127.0.0.1; # Diables direct playback and restricts it to localhost. To allow all playback change to: all
- # deny playback all; # Uncomment to truly allow only playback on localhost (this includes ffmpeg)
- #### We aren't using these next few lines here. Serves as an example of how to implement potential authentification ####
- # on_publish http://127.0.0.1/streamauth/auth.php; # Event is triggered when livestreaming starts.
- # on_publish_done http://127.0.0.1/streamauth/deauth.php; # Event is triggered when livestreaming stops
- # on_play http://127.0.0.1/streamauth/play.php; # Event is triggered when a vierwer starts watching
- #### OPTIONS TO PUSH OR FORWARD THE INCOMING VIDEO STREAM TO ####
- # push rtmp://localhost/hls; # Push the source stream as-is to /hls to create a single HLS stream. Low CPU usage.
- # push rtmp://localhost/dash; # Push the source stream to the /dash app to create a DASH outgoing stream. Low CPU usage.
- # push rtmp://localhost/rec; # Enable this to record the source streams. Also see /rec application below!
- # exec_push /etc/nginx/ffmpeg/transcode.sh; # Alternative to the lines below, placing ffmpeg command in a seperate file.
- #### FFMPEG WILL GRAB THE SOURCE STREAM AT /live, CREATE THE VARIANTS, AND SENDS THEM TO /hls | HIGH CPU! ####
- #### IF YOU DON'T NEED THIS MANY ADAPTIVE STREAMS, OR CPU USAGE IS TOO HIGH, DISABLE ONE OR MORE OF THESE LINES. ####
- exec_push ffmpeg -i rtmp://localhost/live/$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_higher
- -c copy -f flv rtmp://localhost/hls/$name_src;
- #### AN ALTERNATIVE METHOD TO CREATE THE ADAPTIVE BITRATE STREAMS. DISABLE THE PREVIOUS ONE BEFORE TESTING | HIGH CPU USAGE! ####
- #exec_push ffmpeg -i rtmp://localhost/live/$name -async 1 -vsync -1
- #-c:a aac -strict -2 -b:a 128k -c:v libx264 -vf scale=-2:240 -g 48 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -b:v 400k -maxrate 700k -bufsize 1200k -b:a 96k -r 20 -f flv rtmp://localhost/hls/$name_low
- #-c:a aac -strict -2 -b:a 128k -c:v libx264 -vf scale=-2:480 -g 48 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -b:v 1200k -maxrate 2100k -bufsize 2400k -b:a 128k -f flv rtmp://localhost/hls/$name_med
- #-c:a aac -strict -2 -b:a 128k -c:v libx264 -vf scale=-2:720 -g 48 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -b:v 2400k -maxrate 4200k -bufsize 100000k -b:a 128k -f flv rtmp://localhost/hls/$name_high
- #-c copy -f flv rtmp://localhost/hls/$name_src;
- }
- #### THE /HLS APPLICATION AUTOMATICALLY CREATES THE FILES FOR THE OUTGOING HLS STREAM. ####
- application hls { # The /hls app will reads the input and create a useable outgoing HLS stream.
- hls_path /mnt/livestream/hls; # Location where the temporary video fragment files will be stored.
- hls on; # This makes sure that a m3u8 index file will be created to play our .ts video files.
- live on; # This enables or disables this application.
- hls_fragment 10; # Sets HLS fragment length in seconds or minutes. Default = 5s.
- hls_playlist_length 50; # Sets HLS playlist length in seconds or minutes. Default = 30s.
- # hls_sync 100ms; # Timestamp threshold. Prevents crackling noise after conversion from low (1KHz) to highres(90KHz)
- hls_nested on; # In this mode a subdirectory is created for each stream under hls_path.
- hls_type live; # Options: live|event. Live plays from the current position. Event plays from start of playlist.
- hls_continuous off; # HLS sequence number is started from where it stopped last time. Old fragments are kept.
- hls_cleanup on; # Automatically clean up temp files. When turned on, it automatically negates hls_continues
- allow publish 127.0.0.1; # Only localhost (this includes /live feed) is allowed to publish to the /hls application
- # deny publish all; # Uncomment this to truly restrict publish to localhost.
- allow play all; # Allow everybody to play the HLS streams.
- #### HLS VARIANTS ####
- # When hls_variant suffix is matched on stream-name, a variant playlist is created for current stream with all entries specified
- # Stripped name without suffix is used as variant stream name. The original stream is processed as usual.
- # Make sure you use the same naming convention as used in the output names of the ffmpeg commands above.
- 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; # Copy of source stream. Source bitrate, source resolution.
- }
- #### DASH APPLICATION CREATES THE FILES THAT WILL FORM THE OUTGOING DASH STREAM ####
- application dash {
- dash on; # on|off. Toggles MPEG-DASH on the current application.
- live on; # Enables or disables the application.
- dash_path /mnt/livestream/dash; # Location to store the video fragment files. Will be created if it doesn't exist.
- dash_fragment 5s; # Sets DASH fragment length in seconds or minutes. Default= 5s.
- dash_playlist_length 30s; # Sets MPEG-DASH playlist length. Defaults= 30s.
- dash_nested on; # In this mode a subdirectory of dash_path is created for each stream. Default=off.
- dash_cleanup on; # Cache manager process removes old DASH fragments and playlist files from dash_path.
- allow publish 127.0.0.1; # Allow only localhost to publish to /dash
- allow play all; # Allow everybody to play these streams.
- }
- ##### RECORDING /rec #####
- application rec {
- live on; # on|off. Enables this application and allowing live streaming to it. Default=on.
- record all; # Records everything sent to /rec. Options are: off|all|audio|video|keyframes|manual
- record_unique on; # Appends timestamp to files. Otherwise the same file is over-written
- record_path /mnt/livestream/rec; # Location where the recordings will be stored. Adjust this according to your needs.
- record_suffix -%d-%b-%y-%T.flv; # Added to filenames. Example uses 'strftime' results in: -24-Apr-13-18:23:38.flv.
- # record_max_size 128K; # Set maximum file size of the recorded files.
- # record_max_frames 200; # Sets maximum number of video frames per recorded file.
- ##### OPTIONAL! WHEN RECORDING FINISHES, CONVERTS .FLV FILES TO .MP4 | HIGH CPU USEAGE WHILE IT RUNS ####
- exec_record_done ffmpeg -i $path -c copy $dirname/$basename.mp4;
- }
- } # SERVER closing tag
- } # RTMP closing tag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement