Introduction to the installation and use of ZLMediaKit

Introduction to ZLMediaKit

ZLMediaKit is an open source streaming media server developed based on C++. It provides high-performance audio and video processing capabilities, supports common streaming media protocols such as RTSP, RTMP, HLS and HTTP-FLV, and has low latency and high concurrent processing capabilities.

Open source address: https://github.com/xia-chu/ZLMediaKit

insert image description here 

 Some key features and functions of ZLMediaKit:

  • Developed based on C++11, avoiding the use of naked pointers, the code is stable and reliable, and the performance is superior.
  • Support multiple protocols (RTSP/RTMP/HLS/HTTP-FLV/Websocket-FLV/GB28181/MP4), and support protocol conversion.
  • Developed using multiplexing/multithreading/asynchronous network IO mode, it has excellent concurrency performance and supports massive client connections.
  • The code has undergone a large number of long-term stability and performance tests, and has been verified for online commercial use for a long time. Support all platforms of linux, macos, ios, android, windows.
  • Support screen opening in seconds, extremely low delay (within 500 milliseconds, the lowest can reach 100 milliseconds). Provide a complete standard C API, which can be used as SDK or called by other languages.
  • Provide a complete MediaServer server, which can be directly deployed as a commercial server without development. Provide a complete restful api and web hook to support rich business logic. The video surveillance protocol stack and live broadcast protocol stack have been opened up, and the support for RTSP/RTMP is very complete.
  • Full support for H265/H264/AAC/G711/OPUS.

In short, ZLMediaKit is a powerful and high-performance open source streaming media server, suitable for building real-time audio and video transmission and processing applications, such as live broadcast, video conferencing, video surveillance, etc. It provides support for multiple streaming media protocols, has low latency and high concurrent processing capabilities, and supports dynamic transcoding and cross-platform operation. 

Compile and install under linux

Install:

#国内用户推荐从同步镜像网站gitee下载 
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd ZLMediaKit
#千万不要忘记执行这句命令
git submodule update --init
# 安装gcc
sudo apt-get install build-essential
# 安装cmake
sudo apt-get install cmake
# 安装依赖库
#除了openssl,其他其实都可以不安装
sudo apt-get install libssl-dev -y
# 构建和编译项目
cd ZLMediaKit
mkdir build
cd build
cmake ..
# 如果编译release版本 使用 cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4

run:

cd ZLMediaKit/release/linux/Debug
#通过-h可以了解启动参数
./MediaServer -h
#以守护进程模式启动
./MediaServer -d &

ZLMediaKit的HTTP API

The HTTP API of ZLMediaKit is a set of interfaces accessed through the HTTP protocol, which is used to control and manage the functions and status of the ZLMediaKit streaming server.

The api list can be viewed through the following access:

http://127.0.0.1/index/api/getApiList

Get server configuration: /index/api/getServerConfig

Get the stream list: /index/api/getMediaList

Detailed documentation:  mirrors/xia-chu/zlmediakit · GitCode

Through the HTTP API, you can achieve the following functions:

1. Control the start and stop of streaming media: You can send requests through the HTTP API to start and stop streaming media playback and streaming, and control the start and end of streaming media.

2. Obtain the status information of the streaming media: You can use the HTTP API to obtain the status information of the streaming media server, including the current number of connections, the running status of the streaming media, bandwidth usage, etc.

3. Obtain streaming media statistics: HTTP API provides an interface to obtain streaming media server statistics, including statistics such as bit rate, frame rate, and packet loss rate of each stream.

4. Configure streaming server parameters: You can use HTTP API to set and modify streaming server configuration parameters, such as network port, transcoding parameters, recording parameters, etc.

5. Control recording and screenshot functions: Through the HTTP API, you can control the streaming media server to perform recording and screenshot operations, including starting recording, stopping recording, obtaining a list of recorded files, etc.

6. Real-time monitoring and log viewing: HTTP API provides an interface for real-time monitoring of streaming media servers, allowing you to view real-time log information and running status. By using the HTTP API of ZLMediaKit, you can control and manage the streaming media server by writing simple HTTP requests, and easily integrate and expand the functions of the streaming media server to meet specific application requirements.

ffmpeg streaming

UDP streaming

ffmpeg -re -i input.mp4 -c copy -f rtsp rtsp://127.0.0.1:8554/stream

TCP streaming

ffmpeg -re -i input.mp4 -c copy -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/stream

reincarnation streaming

ffmpeg -re -stream_loop -1 -i input.mp4 -c copy -f rtsp rtsp://127.0.0.1:8554/stream

Among them:

-re is read by stream method;

-stream_loop is the number of times to read the video source in loop, -1 is infinite loop;

-i is the input file;

-f to format the output there;

Using -stream_loop -1the option, a video or audio file can be played in a loop. This is useful in applications that need to loop specific content, such as looping video or audio during a presentation session or exhibition.

Using -stream_loop -1the option, it is possible to loop a stream to RTMP or other streaming servers. This is very useful in applications that need to continuously push specific content, such as live broadcast, video surveillance, etc.

For example, push stream in tcp mode:

ffmpeg -re -i input.mp4 -vcodec h264 -acodec aac -f rtsp -rtsp_transport tcp rtsp://114.115.170.245/live/test

How ZLMediaKit implements on-demand

ZLMediaKitVOD is generally mp4implemented through files. It is recommended that you use http mp4VOD. This is the easiest way, and the server does not need to demultiplex mp4 files. Of course, ZLMediaKitmp4 VOD of rtsp, rtmp, http-flv, and websocket-flv is currently supported. The corresponding url and The live url is similar to implement in
, you just need to put it down. By default, the path name is record, which can be modified in config.ini.ZLMediaKit点播mp4 文件www/record

rtsp://114.115.170.245/record/test.mp4

You can use the HTTP protocol to access on-demand media files. Enter the following URL in the browser to play on demand:

http://服务器IP地址:服务器端口/文件相对路径

Use ffmpeg to pull on-demand files and store them locally:

ffmpeg -i rtsp://114.115.170.245/record/input.mp4  -c copy output.mp4

Play the stream with ffplay:

ffplay rtsp://127.0.0.1:8554/stream

If you want to use VLC to pull streams, you need to install VLC player.

 FFmpeg pulls the stream and saves it as a video:

ffmpeg -stimeout 30000000 -i rtsp://127.0.0.1:8554/stream -c copy output.mp4

-stimeout 30000000 is the time to wait for the RTSP stream connection, the unit is us microseconds, 30000000 is to wait for 30 seconds, and exit if the connection fails. Pay special attention to this field before the rtsp address, otherwise it will be invalid. 

other resources

Audio and video development 5. Getting started with ZLMediaKit library, using compilation and installation_zlmediakit compilation_Programming Circle Blog-CSDN Blog

2 Basic use of ZLMediaKit streaming server - short book

The rtsp server is built and used! - Know almost

ZLMediaKit push/pull stream_zlmediakit pull stream_La-La-La-La-La vida's Blog-CSDN Blog

Use FFmpeg tools to push stream, pull stream, screenshot, change speed, convert, and deal with common problems_ffmpeg push stream_FarryNiu's Blog-CSDN Blog

 RTSP push and pull stream based on FFmpeg (detailed tutorial)--Technician 007 ଘ(੭ˊᵕˋ)੭

ZLMediaKit video streaming and playback steps - ywxuan's blog - CSDN blog

Guess you like

Origin blog.csdn.net/qq8864/article/details/131440376