Used to be able to use! Simple steps to build a live system | Force program

Author | mind_programmonkey

Zebian | Wu Xingling

Produced | CSDN blog

The streaming server with a built Ngix + RTMP + FFmpeg, live simple effects.

Nginx is a lightweight Web server / reverse proxy server and e-mail (IMAP / POP3) proxy server. nginx-rmtp-module is a streaming media plug Nginx server. Nginx by RTMP provides modules RTMP service, FFmpeg push a RTMP flow Nginx, and then the client by visiting Nginx to watch live streaming video.

Anyway, still have to smile in the face of it!

Currently kind of live products

  • Pan live entertainment

Pepper, reflect off other entertainment anchor, as well as other games live betta

  • Real-time interactive live

Audio and video conferencing, broadcast and other education, like nails, Tencent meeting

1. Pan currently live entertainment architecture

2. Real-time interactive live architecture

Additional knowledge: CDN Network

1. The general access mode site

First look at the general access mode site.

When a user wants to access a Web site, specify the domain name of this site, DNS will resolve the domain name address, then the address user requests, returning a web page. Just like you want to buy something, we must first find the location of the store, then went inside the store to find what they want, and finally holding something back home.

CDN: Content Delivery Network, the content provider (distribution) network.

2. Use the "intermediate depot" to optimize

For example, you go to buy electricity supplier website single thing, this thing must, from the central warehouse in the electricity business headquarters to send over it? The original is basically like this, every single individual is the distribution, so you may take a long time to receive your baby. But after the call's Web site logistics system wiser, they established throughout the country a lot of warehouses, rather than only the central warehouse headquarters before they can deliver.

According to statistics electricity supplier website probably know, Beijing, Shanghai, Guangzhou, Shenzhen, Hangzhou and other places, how much can sell books, toilet paper, bags, electrical appliances and other relatively long shelf life to everyday objects. These items do not need to send out from a central warehouse, so usually they can be distributed around the warehouse, about a single customer, the nearest warehouse is issued, the next day can be received.

In this way, the user experience is greatly improved.

3. Network in the "nearest distribution"

There are so many global data center, regardless of where the Internet, are basically not far away near the data center. Is not able to deploy several machines in the data center, forming a cluster cache to cache some data, then when the user access to data, you can access the nearest of it?

Of course it is possible. These nodes respective data centers located in various places, it is referred to as edge nodes.

Since the number of edge nodes more, but each edge node cluster size is relatively small, it can not be cached all things, and therefore may not be hit. This will over the edge node, there will be regional nodes, larger scale is necessary, the cached data is more, the greater the probability of hitting. Over an area of ​​the node is the central point, larger, more cache data. If you do not hit, I had visited the site back to the source.

Ngix + RTMP + FFmpeg up a simple stream server

Nginx is a lightweight Web server / reverse proxy server and e-mail (IMAP / POP3) proxy server. nginx-rmtp-module is a streaming media plug Nginx server. Nginx provided by the module RTMP RTMP service, FFmpeg push a RTMP flow nginx, and then the client by visiting Nginx to watch live streaming video.

So, the next step is to build the environment, go, go, go! ! ! !

In order to quickly download, mirror source can replace it. Ubuntu apt-get domestic mirror source replacement https://blog.csdn.net/qq_21095573/article/details/99736630

1. Based on the Linux RTMP service set up Nginx

a. Download nginx

wget http://nginx.org/download/nginx-1.15.3.tar.gz

b. decompression nginx

 tar xvf nginx-1.15.3.tar.gz

c. Download the Nginx rtmp module

wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz

d. decompression

tar xvf v1.2.1.tar.gz

e. Install libraries needed to compile nginx

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

f. be nginx directory

cd nginx-1.15.3

g. # -add-module execution module directory pointing rtmp

./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1

h. compiled and installed in the bin directory of the current directory

make&&make install

You can start in the current directory execute bin / sbin / nginx

bin/sbin/nginx -s stop  停止

In the browser, enter [IP]: 8080

note:

Note that if the port is occupied with the directory, such as if 8080 port is occupied, can be changed to 8081, and then need to open ports.

Port occupancy inspection: lsof -i: 8080

2.FFmpeg

FFmpeg mounted two ways: one is simple, the other is slightly more complex.

a. Simple installation

First come simple, three-step

Step one: Add the source.

sudo add-apt-repository ppa:djcj/hybrid

Step two: update source.

sudo apt-get update

The third step: to download and install.

sudo apt-get install ffmpeg

b. complicated installation

The first step to support the library is installed

sudo apt-get install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
apt install libavformat-dev
apt install libavcodec-dev

apt install libswresample-dev

apt install libswscale-dev

apt install libavutil-dev

apt install libsdl1.2-dev

sudo apt-get install yasm

The second step, x264

gir clone https://github.com/qupai/x264

cd x264 

./configure --enable-shared --enable-pthread --enable-pic

make

make install

The third step, FFmpeg

Official website to download: http: //www.ffmpeg.org/download.html

tar -jxvf ffmpeg-4.1.tar.bz2

cd ffmpeg-4.1

./configure --enable-libx264 --enable-gpl --enable-shared  --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-pic

make

sudo make install

export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib:$LD_LIBRARY_PATH

ldd ffmpeg

If you encounter this problem:

ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory

 -    sudo find / -name libavdevice.so.58  # 找到文件对应地址

 -    sudo vim /etc/ld.so.conf # 文件尾添加一行 /usr/local/lib

 -    sudo ldconfig # 执行该句,使上面的文件生效

Re-run ffmpeg -encoders | grep x264 will find that the installation was successful

After a successful installation, verify results, ffmpeg -version

3. Push Pull flow stream begins

Plug flow refers to the transmission content acquisition phase good packet to the server process, the anchor end of the voice collected locally pushed to the media server streaming video. It is to live video signals to process network.

Then show you:

The host file in Windows Media 1.mp4 flow to push Ubuntu virtual machine streaming media server Nginx, and then in the drop-down ubuntu flow through ffplayer play out this process.

Windows pushdown flow:

ffmpeg -i 1.mp4  -f flv rtmp://192.168.8.169/live/room

ubuntu open Nginx Service

Nginx.conf file in the following newly added content, RTMP increase functionality and make Nginx can have the function of monitoring the live status:

After that, start the service

bin/sbin/nginx

ubuntu pull Streaming

ffplay rtmp://192.168.8.169:1935/live/room

And you're done! ! !

Well, this time on the first case.

Disclaimer: This article is the original article CSDN bloggers "mind_programmonkey", 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/Mind_programmonkey/article/details/104584444

【End】

2020  AI developers million people congress will be held June 26 through online live form, allowing developers to stop learning about the current AI research in cutting-edge technology, the core technology and applications as well as practical experience in the business case , while also online participate in exciting and diverse developer Sharon and programming projects . Prospective involved a series of activities, live online interaction, not only can communicate with tens of thousands of developers, as well as the chance to win a live exclusive gifts , and great coffee Lianmai technology .

Today's welfare : Comments Guest Book elected, are available to the value of 299 yuan, "2020 AI developers million people congress" live online ticket . Come fingertips, write down what you want to say it

Recommended Reading 

programmers Why do not blind effort?

micro-channel iOS version officially supports deep color mode; Google announced the total elimination of I / O Developer Conference; Visual Studio 2019 16.5 release | Geeks headlines

5 bn bo suspected data leak, how to avoid stepping Python reptile sinkhole?

Kubernetes fire so you do not know what? Quickly and see it ~

healthcare, retail, finance, manufacturing ...... you read the article with great impact on the industry in the field of data!

How to develop daily to attract one million active users DApp? First collection Look!

You look at every point, I seriously as a favorite

Click to read text, view details !

Released 1873 original articles · won praise 40000 + · views 17 million +

Guess you like

Origin blog.csdn.net/csdnnews/article/details/105085714