How to build a simple live broadcast system for instant messaging development

Real-time live video broadcasting is a very popular technical form in the past two years, and it has penetrated into various business scenarios such as education and online interactive entertainment. But it is not easy to build a real-time video live broadcast system. Of course, the relevant live broadcast technology theory has been written in detail in other articles on the forum, so this article will not expand it.

 

Based on my curiosity about the new technology, I immediately practiced it, so first of all, I would like to share with you the entire construction process. My operating system is mac, and students with other systems can install the software by themselves according to the prompts.

A simple live broadcast system can roughly consist of three parts:

    Build an rtmp media server;
    push stream end;
    pull stream end.


Now the goal is to build it up quickly, so of course with the help of open source projects and some software:

    rtmp media server: srs is used here;
    streaming end: obs is used here;
    streaming end: player vlc is used here.

Construction of rtmp media server

Here use srs,

First clone to the local, enter the trunk directory:
 
git clone [url=https://github.com/ossrs/srs.git]https://github.com/ossrs/srs.git[/url]  
cd srs/trunk

Then execute:
 
./configure --osx
Note: Centos6.x/Ubuntu12 32/64bits users only need to execute ./configure.

Finally execute:
    
make

After the execution is successful, we can start our service:
    
./etc/init.d/srs start
If it is a mac system, it will fail at this time, because the max_connections in srs.conf is too large, and the directory is srs/trunk/conf/ srs.conf can be modified to 248 (other operating systems may not have this problem). Instant messaging chat software app development can add Wei Keyun's v: weikeyun24 consultation

 

Go back to the trunk directory again:
    
./etc/init.d/srs start
At this point, our srs server is set up.

Supplementary note:
Centos and Ubuntu can be built by referring to the official website, which is relatively simple.

If you encounter other errors during startup, you can check the log information:
    
srs/trunk/objs/srs.log

Other instructions:
    
stop ./etc/init.d/srs stop  
restart ./etc/init.d/srs restart

After we have the server, we are ready to start our push stream. If you really fail to build it, you can first use the ip 116.196.121.20 for testing. I built it on JD Cloud, and the configuration is low. It is mainly used for temporary testing. It may be unstable. Just take a look, and it will be turned off later. So try to build it yourself as much as possible.

Use a third-party streaming SDK

The easiest way is to use the third-party streaming SDK. In most cases, the complete solution of the third-party SDK is charged, but their streaming Android SDK can be downloaded without paying to learn and use.

Use ffmpeg to push stream

You can download the source code of ffmepg by yourself, and then compile it into so according to the online method. The simpler and more practical way is to compile so that can execute ffmpeg commands, so that you can do many things.

Direct import, the project supports commands to run ffmpeg directly.

There are many ffmpeg commands, such as the following commands.

Convert .avi to gif animation (uncompressed):
ffmpeg -i video_origine.avi gif_anime.gif

Synthesize video and audio:
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg

One of the commands is to support streaming. Here, zixia.mp4 on the mobile phone is used as input:
ffmpeg -re -i /storage/emulated/0/zixia.mp4  
    -vcodec libx264  
    -acodec aac  
    -f flv  
    -strict -2 rtmp: //192.168.1.102/zhy/mylive=

Then this library supports running ffmpeg commands on mobile phones, it is simple:

Guess you like

Origin blog.csdn.net/weikeyuncn/article/details/128018196