-
Notifications
You must be signed in to change notification settings - Fork 976
Adaptive Bitrates on Livestream
To enable adaptive streaming for your live broadcasts, you'll need to adjust the NGINX configuration to handle multiple stream resolutions. This setup allows for dynamic adjustment of the video quality based on the viewer's bandwidth, ensuring a smoother streaming experience.
-
Access the NGINX Configuration File: Open your terminal and use the following command to edit your NGINX configuration file:
sudo nano /usr/local/nginx/conf/nginx.conf
-
Modify the RTMP Section: Within the
nginx.conf
file, you will find several sections that are initially commented out (indicated by#
). To enable adaptive streaming, you need to uncomment (remove the#
symbol) the specific lines in the RTMP section that set up different stream resolutions and the adaptive application. Here’s what you should do:-
Uncomment the
exec ffmpeg
lines: These lines are responsible for transcoding the incoming live stream into three different resolutions (low, mid, high). Remove the#
at the beginning of each line to activate them.
exec ffmpeg -re -i rtmp://localhost/live/$name -c:v libx264 -vf scale=-2:240 -r 20 -g 40 -keyint_min 40 -sc_threshold 0 -bf 3 -b_strategy 2 -b:v 400k -maxrate 700k -bufsize 1400k -c:a aac -strict -2 -b:a 96k -f flv rtmp://localhost/adaptive/$name_low -c:v libx264 -vf scale=-2:480 -r 30 -g 60 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -b:v 1200k -maxrate 2100k -bufsize 4200k -c:a aac -strict -2 -b:a 128k -f flv rtmp://localhost/adaptive/$name_mid -c:v libx264 -vf scale=-2:720 -r 30 -g 60 -keyint_min 48 -sc_threshold 0 -bf 3 -b_strategy 2 -b:v 2400k -maxrate 3000k -bufsize 6000k -c:a aac -strict -2 -b:a 128k -f flv rtmp://localhost/adaptive/$name_hi;
-
Uncomment the
application adaptive
section: This section configures the adaptive bitrate options for HLS streaming. Ensure to uncomment all lines except for the one specifically noted to remain commented.
application adaptive { live on; hls on; hls_fragment 2s; hls_path /HLS/live; hls_nested on; hls_playlist_length 10m; allow play all; allow publish 127.0.0.1; deny publish all; hls_variant _low BANDWIDTH=900000; hls_variant _mid BANDWIDTH=2400000; hls_variant _hi BANDWIDTH=3500000; }
Important: Do not uncomment the line with
BANDWIDTH=264000, RESOLUTION=1280x720
as instructed. -
Uncomment the
-
Save and Restart NGINX: After making these changes, save the file and restart NGINX to apply the new settings:
sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx
Finally, to complete the setup, ensure to enable the adaptive mode in the AVideo Live plugin. Go to the Live plugin parameters configuration under the 'Advanced' section and check the option for adaptive mode.
By following these steps, you've successfully configured adaptive streaming on your server, enhancing the viewing experience for your audience by adjusting the stream quality based on their network conditions.