Skip to content

Live Plugin

akhilleusuggo edited this page Nov 19, 2021 · 32 revisions

We call Live streaming when you send a video over the internet in real-time, without first being recorded and stored.

Is very common to use Livestream videos for TV broadcasts, video game streams, social media videos, etc.

In this tutorial we will try to describe our Live Plugin.

Requiriments

As a requirement for this plugin, you need first to configure the NGINX RTMP Server, check this tutorial if you do not have it yet.

AVideo also supports other RTMP servers, but not integrated as the NGINX RTMP is. and to use third parties RTMP servers you need to use the LiveLinks plugin.

How to publish

We have many ways to publish in our site, you can use your mobile or any Desktop RTMP publisher software. currently, you cannot publish using the webcam thru the website page.

More details how to publish, check it here

Saving the Livestream

You can also save the livestreams you make and at the end send it to your encoder and show it on your site.

More details how to save a livestream, check it here

Parameters

  • server = add here the URL for your NGINX Publisher
  • playerServer = that is the URL your HTML5 Player will use to play your HLS Videos
  • stats = We will use this URL to determine if your live is online or not
  • disableDVR = Enable or disable the DVR Feature, you can control the DVR length in your nginx.conf on the parameter hls_playlist_length
  • disableGifThumbs = This option will disable the Animated Gif render, it will save some hardware capacity from your encoder and may speedup your page
  • useAadaptiveMode = This is really useful when you have a good CPU but you are having bandwidth limitations, read this for more information
  • protectLive = With this your encryption key will be protected, and only your site player will be able to play your videos, download tools will not be able to download your video. if you want to share your live externally you can use the embed and you will still be protected. but if you want to use the m3u8 file you must disable this
  • experimentalWebcam = Deprecated, will be removed. not recommend to enable it.
  • doNotShowLiveOnVideosList = We will not show the live thumbs on the main Gallery page
  • doNotShowGoLiveButton = Hide the red top button
  • doNotProcessNotifications = Not used yet
  • useLiveServers = This will enable or disable the remote RTMP servers
  • hls_path = Used only when we stop a Live, we use this path to delete the files;
  • requestStatsTimout = if a remote server does not respond we stop waiting
  • cacheStatsTimout = we will cache the result, this will save some resources
  • requestStatsInterval = how many seconds until request the stats again

Livestream Server Balance

Since Live plugin version 4 you can distribute your live stream in multiple servers, so you can configure your RTMP server in another machine and configure it in the Live Servers menu.

image

How Many Livestream Can I Make?

  • You can have unlimited and simultaneous live streams.
  • You can have unlimited users connected to each live stream.

The only limitation is your hardware, but we can not tell you what hardware is needed to handle a specific amount of users. It depends on your bandwidth and the quality of the video you are transmitting.

But If you plan on using this site for a live broadcast with a large audience, I recommend that you have a dedicated server. Usually, VPSs suspend you because live streams drain a lot of cloud resources.

How many simultaneous users can I have

Those numbers are not exact, but it is an average of what we expect to consume

1080p stream at 5 Mbps 720p stream at 2.5 Mbps 480p stream at 1 Mbps 360p stream at 500 kbps 240p stream at 300 kbps

Data consuption

Video Resolution Bandwidth Simultaneous Users (100Mbps) Simultaneous Users (1Gbps) YPT CDN
1080p 5 Mbps 20 200 unlimited
720p 2.5 Mbps 40 400 unlimited
480p 1 Mbps 100 1000 unlimited
360p 500 kbps 200 2000 unlimited
240p 300 kbps 350 3500 unlimited

YPT CDN

Use our CDN to removes the bottleneck of traffic that could result from delivering streams with a single server. The table above may go to unlimited if you are using our CDN, the bottleneck may be somewhere else, not on the bandwidth consuption.

By connecting your video site into servers across the globe, CDNs create superhighways that truncate the time it takes to deliver video streams from your AVideo to end-user. Sharing the workload across a network of servers also improves scalability should viewership increase.

More Simultaneous Lives (Non-Adaptive)

If you want more simultaneous live streams, you may use the NGINX configuration without the adaptive mode. that will saves you CPU (but will consume more bandwidth for each connected user). By default, we use NGINX to stream your live stream without resizing it, so if you broadcast in 1080p, your users will receive 1080p live, so the consumed bandwidth will depend on the source of the transmitted video.

More Simultaneous Connected Users (Adaptive Mode)

If you want more users connected at the same time, you may use the NGINX configuration with the adaptive mode (requires this configuration). that will consume more of your CPU and disk IO. it will convert your live videos in up to 3 different resolutions (It increase the live latency). The player will analyze your client connection quality and provide the best video quality as possible. So if your live get too many users, it will automatically reduce the quality of the stream, but will still provide a fluid video playback.

Why is my live buffering and has a latency delay?

We use HLS for our live streams because, over the past few years, HLS has become a standard protocol for web video, and with good reason. HLS is pretty simple to set up, it’s free to use, and it’s supported on a wide range of devices.

I think it is impossible to make someone watch your live stream without any second delay Latency. This refers to the elapsed time between when an event occurs in the real world, and when viewers can see it. Essentially, it’s the time that it takes for a video to be recorded by a camera, processed by an encoder, transmitted across the internet, distributed to "edge" servers, and decoded for viewing. For almost all viewers, a high-quality video that is watchable anytime, on any device, is more important than latency.

Note that latency doesn't account for slowdowns due to internet speed and bottlenecks; these are largely separate issues.

If the problem is between your server and your client connection there is nothing you can do, but if the problem is your hardware, you can try to reduce your latency and buffering increasing your hardware capacity, and make some tweaks in your transmission. Just to make clear, be careful with shared servers like virtual machines and Docker containers, usually, they do not provide you all the hardware that they have available, usually, a SATA dedicated Hard Disk is better than a shared server with SSD drives. Again, I am not saying you cannot use a shared server, I am just saying this can be a reason for buffering and a latency delay.

Things to check

  1. If you are NOT using the adaptive mode, make sure your transmission output is a maximum of 720p. if you are transmitting more than that you may have the following problems:

1.1. You will force your users to watch videos in 1080p, so will require a good amount of bandwidth from your server and also from your user.

1.2. will increase your disk I/O because each segment file will be bigger, I mean, higher resolution, more Disk I/O. so SSD disks are preferable.

  1. If you are using the adaptive mode, you should...

2.1. For converting live streams into several streams for adaptive streaming, you need to make sure your server has enough CPU for such a workload. Otherwise, the live stream will suffer from continuous delays, and/or the server becomes unresponsive.

2.2. Something that also worth mention is the I/O limits of the disks. If possible, store the HLS fragments generated to a high-speed SSD helps maintain smooth streaming experiences. Each live transmission will write 3 times more files than the non-adaptive. So if you do not have SSD disks and a good CPU, I do not recommend you to use Adaptive mode.

  1. If you are recording lives it directly reflects into your disk I/O as well. but the recorded file will be in the same resolution, so be careful even if you are transcoding the live into the adaptive mode. if your output is a 4K video you will record a 4K video on your disk

Where is the video output configuration on OBS

You can use the 720p with no problem, but for myself, I use the 540p, and it always works for me. image

Record a video on a remote server

getRemoteFile (getRecordedFile.php)

On the Live Servers, menu make sure you use the correct path for the getRemoteFile This parameter will inform your plugin, in case the recorded file is not found locally, where should it look for it

Nginx Only Installation

Ubuntu 18

sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get install build-essential libssl-dev php-fpm php-cli libpcre3 libpcre3-dev python-certbot-nginx ffmpeg -y && sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev && sudo mkdir ~/build && cd ~/build && sudo git clone https://github.com/arut/nginx-rtmp-module.git && sudo wget http://nginx.org/download/nginx-1.13.8.tar.gz && sudo tar xzf nginx-1.13.8.tar.gz && cd nginx-1.13.8 && sudo ./configure --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-rtmp-module && sudo make && sudo make install && cd /usr/local/nginx/html && sudo wget https://www.youphptube.com/docs/stat.xsl --no-check-certificate && sudo mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old && cd /usr/local/nginx/conf/ && sudo wget https://www.youphptube.com/docs/nginx.conf --no-check-certificate && sudo mkdir /HLS && sudo mkdir /HLS/live && sudo mkdir /HLS/low && sudo mkdir /var/www/tmp/ && chmod 777 /var/www/tmp && wget https://raw.githubusercontent.com/WWBN/AVideo/master/plugin/Live/standAloneFiles/getRecordedFile.php -O /usr/local/nginx/html/getRecordedFile.php

Also add this in your nginx.conf

                location ~ \.php$ {
                       include /etc/nginx/snippets/fastcgi-php.conf;
                       fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                }

Your file will be something like this ....

            server {
                listen 8080;
                server_name localhost;
                location /live {
                        add_header 'Cache-Control' 'no-cache';
                        add_header 'Access-Control-Allow-Origin' '*' always;
                        add_header 'Access-Control-Expose-Headers' 'Content-Length';

                        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;
                        }
                        alias /HLS/live;
                }
                location /stat {
                        rtmp_stat all;
                        rtmp_stat_stylesheet stat.xsl;
                }
                location /stat.xsl {
                        root html;
                }
                location /control {
                        allow 127.0.0.1;
                        deny all;
                        rtmp_control all;
                }
                #allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"     
                location / {
                        root   html;
                        index  index.html index.htm;
                }   

                location ~ \.php$ {
                       include /etc/nginx/snippets/fastcgi-php.conf;
                       fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                }

        }
 ....

Restream

It is a service, that allows users to simultaneously stream video content to multiple platforms and social networks, including Facebook, YouTube, Twitch, Mixer, and LinkedIn.

All will happen in the restreamer.json.php file. You can find this file inside your Live Plugin.

For security reasons, this file will need to check the provided token on your site. then it will proceed with the restream, but you still can use this restream file in separate Live servers as a standalone file.

Control

This is about the HTTP control module for recording audio/video and dropping clients. The control module is an HTTP module which makes it possible to control the RTMP module from outside using HTTP protocol.

What is it for

We will use this module to start/stop a recording, also we will use it to interrupt a live stream

Parameters

First, make sure you have the following configuration in your nginx.conf file

http {
        server {
                ...
                location /control {
                        allow 127.0.0.1;
                        deny all;
                        rtmp_control all;
                }
                ...
        }
}

The controller

The controller is the following file https://github.com/WWBN/AVideo/blob/master/plugin/Live/standAloneFiles/control.json.php this file MUST be on the same server as the Nginx RTMP server

Remote live server

  • If you are using a remote Live server you will need to copy the control.json.php file into your Live server and make sure you edit the variables inside it.

https://github.com/WWBN/AVideo/blob/64e2f7bb1b5f75df0797910f031284c6e1f42655/plugin/Live/standAloneFiles/control.json.php#L20-L22

$streamerURL = "http://192.168.1.4/YouPHPTube/"; // change it to your streamer URL
$record_path = "/var/www/tmp/"; //update this URL
$controlServer = "http://localhost:8080/";

Local Live server

  • If your Live server is on the same server as your streamer you do not need to do anything with this file and it should work fine
Clone this wiki locally