1. Business scenarios

Recently, the company’s live streaming business has been connected to multiple third-party live streaming services (netease Yunxin and Tencent Cloud). The company uses OBS to push streaming to two platforms at the same time, but one OBS can only push streaming to one address, so new solutions are needed.

According to the business scenario, three schemes commonly used on the Internet are investigated:

1. Multiple OBS:

A computer uses multiple OBS push, but as OBS requires TRANScoding by CPU, enabling two OBS will occupy a large amount of CPU resources, which may lead to transcoding overload and lead to frame drop in live broadcast

2. Use third-party streaming services

The third-party streaming media service is used to push OBS to the third-party server, which then pushes configuration information to multiple platforms. However, this problem depends on the third-party streaming service, and the stability of the third-party server will directly affect the effect of live broadcast

3. Set up a local Nginx server

Set up local Nginx server, use OBS to push video stream to local Nginx server, then use Nginx server to forward to each platform

Of course, there should be other solutions, but the video streaming part of my own is useless, and the company’s implementation schedule is urgent, so I chose Nginx’s solution practice among the three solutions found in the limited time. (Reasons for choosing: The current push-stream process is relatively less variable, and the cost is lower), and successfully realized the need to push stream to multiple platforms.

Ii. Implementation Scheme (Under MacOS)

Since the computer is MacOS, the Nginx shunting scheme based on MacOS is divided into the following three steps:

1. Install the brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

Unified management of system plug-in packages

2. Install nginx

brew tap denji/nginx
brew install nginx-full --with-rtmp-module
brew info nginx-full
Copy the code

Note that there are two operations:

First, brew Tap denji/nginx is used, because you need to install nginx with the RTMP module, which will cause installation errors, so you need to use it here

Second, be sure to install the RTMP module to configure the RTMP configuration

3. Add configurations to the nginx configuration file

After install Nginx configuration file address: / usr/local/etc/Nginx/Nginx. Conf, append RTMP configuration file configuration

rtmp { server { listen 1935; chunk_size 10240; application live { live on; record off; push rtmp://p4275c5f7.live.126.net/live/377faa0e54d84db49de0239805f858e8?wsSecret=d25c205a7ab8620ec2078fa11301c4a2&wsTime=156 3965458; push rtmp://pushschool.icourt.cc/live/619fb940aac711e98ab27cd30aeb1494? txSecret=5e58356cd2fcc3384b258637a3d8fc90&txTime=5D3C74FF; }}}Copy the code

Where, push is the live address of the platform to be pushed.

4. Other

Because the address of the push stream often changes, the operator is not familiar with the technology of colleagues, so in the Nginx configuration folder, add conf folder, use include, reference Nginx configuration file, directly modify the configuration file, execute Nginx -s reload reload configuration file can be

rtmp {
    server {
        listen 1935;
        chunk_size 10240;
        application live {
            live on;
            record off;
            include ./conf/push.conf
        }
    }
}
Copy the code

Third, summary

Generally speaking, the operation process is very simple for developers. However, for non-developers, there are also some technical barriers to configuring the Nginx server, so we will consider providing a shell script for direct installation later, and may integrate Nginx later to provide software with operable interfaces. I hope I can complete this flag

Four, reference

How to configure Nginx to push multiple live platforms

———– 08.06 Added ———–

Run the script to save the content as install.mand. Nginx-full may be slow to download. If you have any problems, repeat the command:

echo 'to install homebrew'
if command -v brew; then
    echo 'Homebrew has been found, now try updating >>>'
    echo 'Replace brew.git repository address >>>' 
    cd "$(brew --repo)"
    git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
    echo 'Replace homebrew-core-git repository >>>'
    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
    echo 'Brew update... '
    cd "$(brew --repo)"
    git pull origin master
    brew update
    echo 'Restore brew.git repository >>>'
    cd "$(brew --repo)"
    git remote set-url origin https://github.com/Homebrew/brew.git
    echo 'Restore homebrew-core-git repository address' 
    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://github.com/Homebrew/homebrew-core.git
else
    echo 'Homebrew not found, start installation >>>'
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

echo 'Check nginx-full installation >>>'
if command -v nginx; then
    echo 'Ngxin-full installed >>>'
else
    echo 'Install nginx-full >>>'
    brew tap denji/nginx
    brew install nginx-full --with-rtmp-module
fi

echo '开始配置 nginx.conf >>> '
cd /usr/local/etc/nginx
mkdir conf
touch conf/push.conf
echo ' rtmp { server { listen 1935; chunk_size 10240; application live { live on; record off; include ./conf/push.conf } } } ' >> nginx.conf

echo 'Open the push.conf directory and configure the relevant command line files'
touch conf/reload.command
chmod 777 conf/reload.command
echo 'nginx -s reload' >> reload.command
open conf
echo 'Set nginx startup >>>'
brew services start denji/nginx/nginx-full
echo 'Configuration successful! '
Copy the code