ZLMediaKit installation configuration and push-pull flow

1. Introduction to ZLMediaKit library

ZLMediaKit is a high-performance carrier-grade streaming media service framework based on C++11

Official project features:

  • Developed based on C++11, avoiding the use of raw pointers, the code is stable and reliable, and has superior performance.
  • SupportMultiple protocols(RTSP/RTMP/HLS/HTTP-FLV/Websocket-FLV/GB28181/MP4), support. Protocol conversion
  • Developed using multiplexing/multi-threading/asynchronous network IO mode, it has excellent concurrency performance and supports massive client connections.
  • Epoll, IoCompletionPort
  • The code has undergone long-term and extensive stability and performance testing, and has been verified for online commercial use for a long time. Supports all platforms of linux, macos, ios, android, and windows.
  • supports screen opening in seconds and extremely low latency (within 500 milliseconds, as low as 100 milliseconds). Provides a completestandard C API, which can be used as SDK or called by other languages.
  • Provides a complete MediaServer server, which can be directly deployed as a commercial server without development. Provides complete restful api and web hook, supporting rich business logic. It connects the video surveillance protocol stack and the live broadcast protocol stack, and has complete support for RTSP/RTMP.
  • Full support for H265/H264/AAC/G711/OPUS. It has many functions and supports multiple streaming media formats such as RTSP, RTMP[S], HLS, and GB28181.

2. Linux environment setup

1. Install dependencies

Try to install the following dependent libraries. If something goes wrong, don't worry about it.

When installing dependencies, it may be necessary to complete the

sudo apt install git gcc make cmake python p7zip-full libssl-dev pkg-config autoconf automake build-essential -y
sudo apt-get -y --force-yes install libass-dev
sudo apt-get -y --force-yes install libtheora-dev libtool libva-dev libvdpau-dev
sudo apt-get -y --force-yes install libvorbis-dev libxcb1-dev libxcb-shm0-dev
sudo apt-get -y --force-yes install libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev
# 安装 gcc
sudo apt-get install build-essential
# 安装 cmake
sudo apt-get install cmake
# 安装依赖库 #除了 openssl,其他其实都可以不安装
sudo apt-get install libssl-dev -y
sudo apt-get install libsdl-dev -y
sudo apt-get install libavcodec-dev -y
sudo apt-get install libavutil-dev -y
sudo apt-get install ffmpeg -y

2. Download the source code

Please do not use github to download the zip package to download the source code. Be sure to use git to clone the ZLMediaKit code because

ZLMediaKit relies on third-party code,

The zip package will not download third-party dependency source code. You can do this:

#国内用户推荐从同步镜像网站 gitee 下载
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
#千万不要忘记执行这句命令:第三方库
git submodule update --init

3. Install openssl

Check the version of your system

openssl verison

Compile openssl

git clone https://github.com/openssl/openssl.git

Or make a stable version (it is recommended to use this), please go over the wall yourself

wget https://github.com/openssl/openssl/archive/refs/heads/OpenSSL_1_1_1-stable.zip

Compile after downloading

./config
make
sudo make install

Specify shortcut

Because it is installed to the /usr/local directory by default, or /usr/lib is specified during config, or the library is linked to it.

sudo ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
sudo ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1

4. Install libsrtp

Download source code

git clone https://github.com/cisco/libsrtp.git

Configure compile and install

cd libsrtp
./configure --enable-openssl
make
make runtest
sudo make install

test

# 首先,进入 libsrtp 的测试文件目录
cd test
# 然后,执行测试命令如下
./rtpw_test.sh

Appears at the end: ./rtpw_test.sh: done (test passed)

5. Compile ZLMediaKit

Enter the ZLMediaKit source code directory you just downloaded

Run the root directory script directly

./build_for_linux.sh

Error 1 libsrtp

srtp2/srtp.h: No such file or directory

This is because the libsrtp2 library is missing

so…

sudo apt-get install libsrtp0-dev

The old version doesn't work, just compile the source code honestly

Insert a sentence here, because the openssl version problem leads to the second compilation of libsrtp, so we need to fix openssl first.

Undefined identifier HMAC_CTX_init

MediaServer crash

libsrtp does not have --enable-openssl

Mistake 2: openssl version problem

SSLUtil.cpp:315:33: error: invalid conversion from ‘const rsa_st*’ to ‘RSA* {aka rsa_st*}’

[-fpermissive]

The above are all openssl version issues

ln: cannot create symbolic link '/usr/lib64/libssl.so.1.1': No such file or directory

Create soft connection solution

The compiled program is under ZLMediaKit/release/linux/Debug

Run tests

# 进入MediaServer目录
cd ZLMediaKit/release/linux/Debug
# 将配置文件 ZLMediaKit/conf/config.ini 复制到 MediaServer 同目录下
cp ../../../conf/config.ini ./
# 开始运行
sudo ./MediaServer

Note: The program failed to start, prompting that the port is occupied. Please modify the occupied port number in the configuration file and try again.

3. Push flow and pull flow

Push streaming

rtsp push

ffmpeg -re -i 1.mp4 -vcodec libx264 -bsf:v h264_mp4toannexb -acodec aac -f rtsp -rtsp_transport tcp rtsp://codehere.top:554/live/test1

rtmp push

ffmpeg -re -i ande10.mp4 -vcodec libx264 -bsf:v h264_mp4toannexb -acodec aac -f flv rtmp://codehere.top:1936/live/test2

pull flow

ffplay -i rtsp://codehere.top:554/live/test1 -fflags nobuffer
ffplay -i rtmp://192.168.1.6/live/test1 -fflags nobuffer
 
ffplay -i rtmp://192.168.1.6/live/test2 -fflags nobuffer
ffplay -i rtsp://192.168.1.6/live/test2 -fflags nobuffer

As a benefit for this article, you can receive free C++ audio and video learning materials package + learning route outline, technical videos/codes, including (audio and video development, interview questions, FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, codec, push-pull streaming, srs )↓↓↓↓↓↓See below↓↓Click at the bottom of the article to get it for free↓↓

Guess you like

Origin blog.csdn.net/m0_73443478/article/details/134552126