Setting up HLS live streaming server using NGINX

How To Install Nginx RTMP Media Server?

An HLS Streaming Server is one of the most prevalent video streaming protocols. It’s possible to broadcast media material adapted to the user’s device and network circumstances using HLS, an adaptive streaming technique. Further, the Nginx RTMP module may be used to combine HLS and RTMP with the Nginx web server. This tutorial will set up the HLS live streaming server on Ubuntu.

Installation Instructions:

1)start updating your apt repositories

#apt-get update

step1-kb

2) Install required packages:

#apt-get install -y git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev

ngnix-KB

3) Clone Module:

#git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git

nginx-kb-infinitive host

4)Download Nginx

#wget http://nginx.org/download/nginx-1.17.6.tar.gz

KB- nginx

5) Extract and compile the Nginx with RTMP module

#tar -zxvf nginx-1.17.6.tar.gz
#cd Nginx-1.17.6
#./configure --prefix=/usr/local/nginx --with-http_ssl_module –add-module=../nginx-rtmp-module
#make -j 1
#make install

nginx-kb-infinitive host

6) Configure Nginx Daemon

#wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
#chmod +x /etc/init.d/nginx

7)Enable on boot Nginx service

#update-rc.d nginx defaults

Editing nginx configuration:

#cp -p /usr/local/nginx/conf/nginx.conf nginx.conf_backup

Open Nginx configuration file:

#vim /usr/local/nginx/conf/nginx.conf

Add the following configuration:-

worker_processes 1;
error_log logs/rtmp_error.log debug;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
location /hls {
# Serve HLS fragments
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt;
add_header Cache-Control no-cache;
}
}
}
rtmp {
server {
listen 1935;
chunk_size 8192;
application hls {
live on;
meta copy;
hls on;
hls_path /mnt/hls;
}
}
}
:wq (Save and exit vim editor)

Create the required directories:

#mkdir /mnt/hls
#mkdir /mnt/recordings

Restart the Nginx service:

#systemctl restart nginx

Check the Nginx listening ports using the netstat command:

#netstat -tulpn | grep nginx

KB-infinitivehost-nginx

Start stream with any key using OBS:

rtmp://localhost/hls

kb-nginx

KB -infinitive Host

Check your streaming in VLC using network stream:

http://localhost/hls/manualtesting.m3u8

 

 

nginx-infinitivehost-KB

KB-nginx

A free consultation with an Nginx RTMP or HLS server expert is a good idea if you have any concerns or queries regarding the process. Your video streaming project might benefit from our expertise in determining the best server hardware for your needs.

Last Update: July 26, 2022  

February 1, 2022   1098   jincy john    Streaming Server    
Total 0 Votes:

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Add A Knowledge Base Question !

You will get a notification email when Knowledgebase answerd/updated!

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Post a Comment

0 Comments