-
Notifications
You must be signed in to change notification settings - Fork 979
Set up my own Stream Server
Source Information :
- https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp
- https://github.com/arut/nginx-rtmp-module/wiki/Directives
Adicional Information : I'll be installing it on Ubuntu 18.04
For new installations :
Ubuntu 18.04 ( recommended ) : https://github.com/WWBN/AVideo/wiki/How-to-install-LAMP,-FFMPEG-and-Git-on-a-fresh-Ubuntu-18.x-for-AVideo-Platform-version-4.x-or-newer
sudo apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev php7.2-xml
sudo mkdir ~/build && cd ~/build && sudo git clone git://github.com/arut/nginx-rtmp-module.git
sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz && sudo tar xzf nginx-1.16.1.tar.gz
cd nginx-1.16.1 && sudo ./configure --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-rtmp-module
sudo make && sudo make install
sudo mkdir /usr/local/nginx/ssl/ && sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /usr/local/nginx/ssl/nginx.key -out /usr/local/nginx/ssl/nginx.crt
sudo /etc/init.d/apache2 restart && sudo mkdir /HLS && sudo mkdir /HLS/live
Additional Notes :
For Ubuntu 18.04 you need the php7.2-xml , Ubuntu 16.04 php7.0-xml
For Ubuntu 18.04 I recommend using the version 1.16.1 at the least . Older version may result in erros during the installation
The packages zlib1g zlib1g-dev
are installed to avoid error the HTTP gzip module requires the zlib library.
cd /usr/local/nginx/html && wget https://youphptube.com/docs/stat.xsl
sudo mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old
cd /usr/local/nginx/conf/ && sudo wget https://raw.githubusercontent.com/DanielnetoDotCom/YouPHPTube/master/plugin/Live/install/nginx.conf
Open the config file , and replace [AVideoURL]
with your domain name or IP
sudo nano /usr/local/nginx/conf/nginx.conf
The result should look something like this :
IMPORTANT NOTE : NGINX not not recognize https url , even if your site does support SSL , you will have to use the http url . On the point 10 of this guide , you will find how to configure the SLL .
Access to your AVideo website , login with admin account . Browse to Plugins , and install the tables for the plugins Live (Live) and LiveChat (LiveChat) , then enable them .
Note: The Live Chat plugin is deprecated, will be removed next version . In case you're reading this in the future , this feature could be missing . We strongly recommend upgrading to Chat2 (Chat2) . You can find it here : https://youphp.tube/plugins/
button_title: The text that gonna be displayed on the live's button .
server: The RTMP root url
playerServer: Where the server gonna be listen
stats: Url where to check/monitor/display the streams stats
Enable/Disable RVD: Feature to playback streams . This feature requires hls_playlist_length
. More information at the Extra Settings ( NGINX.CONF ) section ( at the bottom )
disableGifThumbs If enabled the AVideo script will automatically generate GifThumbs from streams .
useAadaptiveMode To use this feature you will need HLS plugin https://youphp.tube/plugins/ , and configure live transcoding ; We have a guide here : https://github.com/WWBN/AVideo/wiki/Adaptive-Bitrates-on-Livestream
experimentalWebcam Experimental feature for webcam
doNotShowLiveOnVideosList If enabled , live streams will not be displayed on the welcome page .
doNotProcessNotifications In case you have the Notification plugin but you don't wanna send notification , you may want to select this option . Default disabled .
hls_path: The path we have set earlier on the nginx.conf
for the hls fragments . Default /HLS/live
Execute the command line ( on the server's terminal ) that you have on your plugin section . This will initialize the connection of your chat plugin .
nohup php /var/www/YouPHPTube/plugin/LiveChat/chat-server.php &
Then press Ctrl+C
sudo /usr/local/nginx/sbin/nginx
Note: If you're getting this type of ''errors'' when you starting nginx , that means your nginx is already running . Is not an error or issue .
To stop nginx : sudo /usr/local/nginx/sbin/nginx -s stop
To restart nginx : sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx
Check if the server is running . We can check that by accessing the stat page we indicated on our plugin . Default : http://YourIP:8080/stat
sudo nano /etc/apache2/mods-available/proxy.conf
Add : ProxyPass /wss/ ws://127.0.0.1:8888/
Make the file looks like this :
Enable the module and restart apache
sudo a2enmod proxy_wstunnel
/etc/init.d/apache2 restart
10. Configure SSL certificate for the nginx config
I'm assuming that you already having a signed certificate . Now you need to include it on the nginx.conf
sudo nano /usr/local/nginx/conf/nginx.conf
Find the http section . You will need to indicate the SSL port that you wanna use . Avoid using 443 , since it's already used by Apache . In this case , we will use the port 444 .
Lines to be added :
listen 444 ssl;
ssl_certificate /etc/letsencrypt/live/demo.avideo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/demo.avideo.com/privkey.pem;
server_name demo.avideo.com;
Replace demo.avideo.com with your path to certificate or your domain name . The result should look like this :
11. Extra Settings ( NGINX.CONF )
This settings are not required , but I'll share with you and explain some of the features .
I'll not explain everything . If you need to understand some parameters , remove them or change them take a look at the source information : https://github.com/arut/nginx-rtmp-module/wiki/Directives
Important things that you may wanna consider are the latency ( stream delay ) . You may wanna consider adding:
hls_fragment 2s;
( make sure your keyframe is double the video's framerate video )
max_streams 32;
The maximum streams you wanna allow
hls_nested on;
This is important if you wanna enable DVR . Will create a sub-directory for each streamer .
hls_playlist_length 120m;
This feature is for DVR . How much minutes you want NGINX to save for playback . All the fragments will be saved under the ID streamer .
hls_cleanup on;
Clear the HLS fragment at the restart of the nginx server . NGINX will hand it .
Those are the most important feature to consider . After changing the config , don't forget to restart nginx . sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx