Build Nginx + nginx-rtmp-module of hls streaming server and a plug flow OBS

Recently doing live projects, access to relevant information about the service and then successful build, implementation and pit stepped on organized here next record.
I. Introduction broadcast agreement:

First of all, before you set up the service to understand the current mainstream broadcast several protocols:

1、RTMP:

     Real-time messaging protocol, Real Time Messaging Protocol, is Adobe Systems' audio, video, and data transfer between Flash Player and the development of open server protocol. Based on the TCP protocol, a protocol suite, including protocols and RTMP substantially RTMPT / RTMPS / RTMPE other variants. RTMP is a network protocol designed for real-time data communication, mainly used between streaming Flash / AIR platform and support RTMP protocol / server interaction for audio, video and data communications. This real-time approach is relatively strong, basically guaranteed late in 1-2s, is one of the ways the country now live mainly used; however, the use of this protocol, you must install flash, and H5, IOS, Android and not the native support for flash, so this agreement will pop how long, do not know, after all, is the current mainstream mobile terminal.

2、HLS:

     hls is Apple launched the live protocol is to slice through a video stream file fragment to live. The client will first request a m3u8 file, which will have a different rate of flow, or directly to the file list ts, ts through the file to the address given in turn to play. In the broadcast time, the client will continue to request m3u8 file, check the list of new ts ts slices. The real poor in this way, but the advantage is H5, IOS, Android have native support.

3、HTTP-FLV:

      HTTP-FLV is to RTMP protocol encapsulated, compared to RTMP, it is an open protocol. So he has the development of real-time and RTMP RTMP do not have, and with the flv.js appears (thanks B station), so that the browser without relying on the flash, flv video player, which is compatible with the mobile terminal, so now many broadcast platforms, especially mobile phones broadcast platform, it will choose
 
two, HLS live configuration

nginx server configuration:

New directory: nginx for storing and nginx-rtmp-moudle module

mkdir /usr/local/nginx

Download archive: Go to the download directory created under nginx, here if unsuccessful can download https instead http, before been available for download, back after a cloud for a https server can not download it, do not know is not being shielded reasons, replaced after http solved

    cd /usr/local/nginx
    wget http://nginx.org/download/nginx-1.12.2.tar.gz
    wget https://codeload.github.com/arut/nginx-rtmp-module/zip/master

If you do not wget command, then execute the following command to install

yum -y install wget

Decompression:

    tar -zxvf nginx-1.12.2.tar.gz
    unzip nginx-rtmp-module-master.zip

Similarly, do not unzip command to perform the following command to install

yum -y install unzip

Before you install nginx nginx and install the module, first install some dependent libraries:

    yum -y install gcc-c++
    yum -y install pcre pcre-devel  
    yum -y install zlib zlib-devel
    yum -y install openssl openssl-devel

Then install nginx-rtmp-module module:

    /usr/local/nginx/nginx-1.12.2 CD
    # rtmp complete module is installed, input your back = absolute path of the module package
    ./configure --add-module = / usr / local / nginx / nginx-rtmp-module -master
    the make & the make install

Use the following command to see whether nginx started successfully:

    cd /usr/local/nginx/sbin
    ./nginx -t

The following figure prompted configuration is successful

and a correlation module installed nginx

 

Configuration and start the service support hls

Since nginx-rtmp-module support for hls agreement, so we can be configured directly in nginx.conf:

we /usr/local/nginx/conf/nginx.conf

Rtmp add the following modules: (rtmp {} content and http {} is at the same level, do not put in the wrong location)

    RTMP {  
      
        Server {  
      
            the listen 1935; # listening port
      
            chunk_size 4000;  
            
            file application HLS {
                Live ON;
                HLS ON;
                hls_path / usr / local / HTML / HLS; # video stream storage address
                hls_fragment 5S;
                hls_playlist_length 15s;
                hls_continuous ON; # continuous mode .
                hls_cleanup on; # of extra sections were deleted.
                hls_nested on; # nested mode.
            }
        }  
    }

As shown below

Add http address in a live stream container:

    location / hls {# add address for storing the video stream.
            {types
                the Application / vnd.apple.mpegurl M3U8;
                Video / MP2T TS;
            }
            # open access, or access to this address will be reported 403
            autoindex ON;
            Alias / usr / local / HTML / HLS; # video streams stored address above the hls_path corresponding to the difference between this and root alias may Baidu self
            Expires -1;
            the add_header the Cache Cache-Control-NO;
            # prevent cross-domain problem
            the add_header 'Access-Control-the Allow-Origin' '*';
            the add_header 'Access-Control Credentials--ALLOW '' to true ';
            the add_header' Access-Control-the Allow-Methods' 'the GET, the POST, the OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';  
        }

Figure:

After setting up the save file and restart the server:

    cd /usr/local/nginx/sbin
    ./nginx -s reload

Live plug-flow configuration

Plug flow refers to the end of the live video stream to the server pushes the set position. I'm using here is obs be pushed streams:

In Settings -> Fill in the information in the stream: URL is rtmp: // xxx: 1935 / hls , xxx is the IP address of your server, hls is used to store streaming media, "corresponding to the conf file is set in the application name, stream name can be customized, server-generated m3u8 this file is named. after the setup is complete, click "start plug flow", set the plug-flow side is complete.
Third, pull flow settings

Watch live relatively simple, you can simply use the h5 tag you can watch the vedio.

Can visit http: // xxx: 80 / hls / abcd.m3u8 to watch live, where xxx is the IP address of your server, the latter is in a plug flow abcd keys when used, is customizable. Or use

    <video>  
        <source src="http://xxx:80/hls/abcd.m3u8"/>  
        <p class="warning">Your browser does not support HTML5 video.</p>  
    </video>

Here encountered a pit, said access online information is based on my address to write, but found the key used to push the server automatically generates a stream directory, then the container stream files to the inside when I actually use not directly generate abcd.m3u8, following FIG.

So I use the access address is http: // xxx: 80 / hls / abcd / index.m3u8, then pulled on the success of the live stream.
----------------
Disclaimer: This article is the original article CSDN bloggers "Ricartu", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/Ricardo18/article/details/89359623

Published 117 original articles · won praise 4 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_36266449/article/details/104363764