226b87a633
rtp时间戳可能被截断,ntp时间戳生成时优先使用未截断的原始时间戳,防止音视频不同步 |
||
---|---|---|
.github | ||
3rdpart | ||
Android | ||
api | ||
cmake | ||
conf | ||
docker | ||
ext-codec | ||
golang | ||
package/rpm | ||
player | ||
postman | ||
server | ||
src | ||
srt | ||
tests | ||
tools/openapi | ||
webrtc | ||
www | ||
.clang-format | ||
.gitattributes | ||
.gitignore | ||
.gitmodules | ||
.gitmodules_github | ||
AUTHORS | ||
build_docker_images.sh | ||
CMakeLists.txt | ||
default.pem | ||
dockerfile | ||
k8s_readme.md | ||
LICENSE | ||
README_en.md | ||
README.md | ||
sources.list | ||
ZLMVersion.h.ini |
简体中文 | English
An high-performance, enterprise-level streaming media service framework based on C++11.
Project Features
- Developed with C++11, avoiding the use of raw pointers, providing stable and reliable code with superior performance.
- Supports multiple protocols (RTSP/RTMP/HLS/HTTP-FLV/WebSocket-FLV/GB28181/HTTP-TS/WebSocket-TS/HTTP-fMP4/WebSocket-fMP4/MP4/WebRTC), and protocol conversion.
- Developed with multiplexing/multithreading/asynchronous network IO models, providing excellent concurrency performance and supporting massive client connections.
- The code has undergone extensive stability and performance testing, and has been extensively used in production environments.
- Supports all major platforms, including linux, macos, ios, android, and windows.
- Supports multiple instruction set platforms, such as x86, arm, risc-v, mips, Loongson, and Shenwei.
- Provides ultra-fast startup, extremely low latency (within 500 milliseconds, and can be as low as 100 milliseconds), and excellent user experience.
- Provides a comprehensive standard C API that can be used as an SDK or called by other languages.
- Provides a complete MediaServer server, which can be deployed directly as a commercial server without additional development.
- Provides a complete restful api and web hook, supporting rich business logic.
- Bridges the video surveillance protocol stack and the live streaming protocol stack, and provides comprehensive support for RTSP/RTMP.
- Fully supports H265/H264/AAC/G711/OPUS.
- Provides complete functions, including clustering, on-demand protocol conversion, on-demand push/pull streams, playback before publishing, and continuous publishing after disconnection.
- Provides ultimate performance, supporting 10W-level players on a single machine and 100Gb/s-level IO bandwidth capability.
- Provides ultimate user experience with exclusive features.
- Who is using zlmediakit?
- Fully supports IPv6 networks.
Project Positioning
- Cross-platform streaming media solution for mobile and embedded systems.
- Commercial-grade streaming media server.
- Network programming secondary development SDK.
Feature List
Overview of Features
-
RTSP[S]
- RTSP[S] server, supports RTMP/MP4/HLS to RTSP[S] conversion, supports devices such as Amazon Echo Show
- RTSP[S] player, supports RTSP proxy, supports generating silent audio
- RTSP[S] push client and server
- Supports four RTP transmission modes:
rtp over udp
rtp over tcp
rtp over http
rtp multicast
- Server/client fully supports Basic/Digest authentication, asynchronous configurable authentication interface
- Supports H265 encoding
- The server supports RTSP pushing (including
rtp over udp
andrtp over tcp
) - Supports H264/H265/AAC/G711/OPUS/MJPEG encoding. Other encodings can be forwarded but cannot be converted to protocol
-
RTMP[S]
- RTMP[S] playback server, supports RTSP/MP4/HLS to RTMP conversion
- RTMP[S] publishing server, supports recording and publishing streams
- RTMP[S] player, supports RTMP proxy, supports generating silent audio
- RTMP[S] push client
- Supports http[s]-flv live streaming server
- Supports http[s]-flv live streaming player
- Supports websocket-flv live streaming
- Supports H264/H265/AAC/G711/OPUS encoding. Other encodings can be forwarded but cannot be converted to protocol
- Supports RTMP-H265
- Supports RTMP-OPUS
- Supports enhanced-rtmp(H265)
-
HLS
- Supports HLS file(mpegts/fmp4) generation and comes with an HTTP file server
- Through cookie tracking technology, it can simulate HLS playback as a long connection, which can achieve HLS on-demand pulling, playback statistics, and other businesses
- Supports HLS player and can pull HLS to rtsp/rtmp/mp4
- Supports H264/H265/AAC/G711/OPUS encoding
-
TS
- Supports http[s]-ts live streaming
- Supports ws[s]-ts live streaming
- Supports H264/H265/AAC/G711/OPUS encoding
-
fMP4
- Supports http[s]-fmp4 live streaming
- Supports ws[s]-fmp4 live streaming
- Supports H264/H265/AAC/G711/OPUS/MJPEG encoding
-
HTTP[S] and WebSocket
- The server supports
directory index generation
,file download
,form submission requests
- The client provides
file downloader (supports resume breakpoint)
,interface requestor
,file uploader
- Complete HTTP API server, which can be used as a web backend development framework
- Supports cross-domain access
- Supports http client/server cookie
- Supports WebSocket server and client
- Supports http file access authentication
- The server supports
-
GB28181 and RTP Streaming
- Supports UDP/TCP RTP (PS/TS/ES) streaming server, which can be converted to RTSP/RTMP/HLS and other protocols
- Supports RTSP/RTMP/HLS and other protocol conversion to RTP streaming client, supports TCP/UDP mode, provides corresponding RESTful API, supports active and passive modes
- Supports H264/H265/AAC/G711/OPUS encoding
- Supports ES/PS/TS/EHOME RTP streaming
- Supports ES/PS RTP forwarding
- Supports GB28181 active pull mode
- Supports two-way voice intercom
-
MP4 VOD and Recording
- Supports recording as FLV/HLS/MP4
- Supports MP4 file playback for RTSP/RTMP/HTTP-FLV/WS-FLV, supports seek
- Supports H264/H265/AAC/G711/OPUS encoding
-
WebRTC
- Supports WebRTC streaming and conversion to other protocols
- Supports WebRTC playback and conversion from other protocols to WebRTC
- Supports two-way echo testing
- Supports simulcast streaming
- Supports uplink and downlink RTX/NACK packet loss retransmission
- Supports single-port, multi-threaded, and client network connection migration (unique in the open source community).
- Supports TWCC RTCP dynamic rate control
- Supports REMB/PLI/SR/RR RTCP
- Supports RTP extension parsing
- Supports GOP buffer and instant WebRTC playback
- Supports data channels
- Supports WebRTC over TCP mode
- Excellent NACK and jitter buffer algorithms with outstanding packet loss resistance
- Supports WHIP/WHEP protocols
-
Others
- Supports rich RESTful APIs and webhook events
- Supports simple Telnet debugging
- Supports hot reloading of configuration files
- Supports traffic statistics, stream authentication, and other events
- Supports virtual hosts for isolating different domain names
- Supports on-demand streaming and automatic shutdown of streams with no viewers
- Supports pre-play before streaming to increase the rate of timely stream openings
- Provides a complete and powerful C API SDK
- Supports FFmpeg stream proxy for any format
- Supports HTTP API for real-time screenshot generation and return
- Supports on-demand demultiplexing and protocol conversion, reducing CPU usage by only enabling it when someone is watching
- Supports cluster deployment in traceable mode, with RTSP/RTMP/HLS/HTTP-TS support for traceable mode and HLS support for edge stations and multiple sources for source stations (using round-robin tracing)
- Can reconnect to streaming after abnormal disconnection in RTSP/RTMP/WebRTC pushing within a timeout period, with no impact on the player.
System Requirements
- Compiler with c++11 support, such as GCC 4.8+, Clang 3.3+, or VC2015+.
- CMake 3.1+.
- Linux (32-bit and 64-bit).
- Apple macOS (32-bit and 64-bit).
- Any hardware with x86, x86_64, ARM, or MIPS CPU.
- Windows.
How to build
It is recommended to compile on Ubuntu or macOS. Compiling on Windows is cumbersome, and some features are not compiled by default.
Before Building
- You must use Git to clone the complete code. Do not download the source code by downloading the ZIP package. Otherwise, the submodule code will not be downloaded by default. You can do it like this:
git clone https://github.com/ZLMediaKit/ZLMediaKit.git
cd ZLMediaKit
git submodule update --init
Building on Linux
-
My Environment
- Ubuntu 16.04 (64-bit) with GCC 5.4.
- CMake 3.5.1.
-
Guidance
# If it is on CentOS 6.x, you need to install a newer version of GCC and CMake first, # and then compile manually according to the "build_for_linux.sh" script. # If it is on a newer version of a system such as Ubuntu or Debian, # step 4 can be manipulated directly. # 1. Install GCC 5.2 (this step can be skipped if the GCC version is higher than 4.7). sudo yum install centos-release-scl -y sudo yum install devtoolset-4-toolchain -y scl enable devtoolset-4 bash # 2. Install CMake (this step can be skipped if the CMake version is higher than 3.1). tar -xvf cmake-3.10.0-rc4.tar.gz #you need to download the CMake source file manually cd cmake-3.10.0-rc4 ./configure make -j4 sudo make install # 3. Switch to a higher version of GCC. scl enable devtoolset-4 bash # 4. Build. cd ZLMediaKit ./build_for_linux.sh
Building on macOS
-
My Environment
- macOS Sierra (10.12.1) with Xcode 8.3.1.
- Homebrew 1.1.3.
- CMake 3.8.0.
-
Guidance
cd ZLMediaKit ./build_for_mac.sh
Building on iOS
-
You can generate Xcode projects and recompile them , learn more:
cd ZLMediaKit mkdir -p build cd build # Generate Xcode project, project file is in build directory cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED
Building on Android
Now you can open the Android Studio project in the Android
folder. This is an AAR
library and demo project.
-
My environment
- macOS Sierra (10.12.1) + Xcode 8.3.1
- Homebrew 1.1.3
- CMake 3.8.0
- Android NDK r14b
-
Guidance
cd ZLMediaKit export ANDROID_NDK_ROOT=/path/to/ndk ./build_for_android.sh
Building on Windows
-
My environment
- Windows 10
- Visual Studio 2017
- CMake GUI
-
Guidance
1. Enter the ZLMediaKit directory and execute `git submodule update --init` to download the code for ZLToolKit.
2. Open the project with CMake GUI and generate the Visual Studio project file.
3. Find the project file (ZLMediaKit.sln), double-click to open it with VS2017.
4. Choose to compile the Release version. Find the target file and run the test cases.
Usage
-
As a server:
TcpServer::Ptr rtspSrv(new TcpServer()); TcpServer::Ptr rtmpSrv(new TcpServer()); TcpServer::Ptr httpSrv(new TcpServer()); TcpServer::Ptr httpsSrv(new TcpServer()); rtspSrv->start<RtspSession>(mINI::Instance()[Config::Rtsp::kPort]); rtmpSrv->start<RtmpSession>(mINI::Instance()[Config::Rtmp::kPort]); httpSrv->start<HttpSession>(mINI::Instance()[Config::Http::kPort]); httpsSrv->start<HttpsSession>(mINI::Instance()[Config::Http::kSSLPort]);
-
As a player:
MediaPlayer::Ptr player(new MediaPlayer()); weak_ptr<MediaPlayer> weakPlayer = player; player->setOnPlayResult([weakPlayer](const SockException &ex) { InfoL << "OnPlayResult:" << ex.what(); auto strongPlayer = weakPlayer.lock(); if (ex || !strongPlayer) { return; } auto videoTrack = strongPlayer->getTrack(TrackVideo); if (!videoTrack) { WarnL << "No video Track!"; return; } videoTrack->addDelegate([](const Frame::Ptr &frame) { //please decode video here }); }); player->setOnShutdown([](const SockException &ex) { ErrorL << "OnShutdown:" << ex.what(); }); //RTP transport over TCP (*player)[Client::kRtpType] = Rtsp::RTP_TCP; player->play("rtsp://admin:jzan123456@192.168.0.122/");
-
As a proxy server:
//Support RTMP and RTSP URLs, but only H264 + AAC codec is supported auto urlList = {"rtmp://live.hkstv.hk.lxdns.com/live/hks", "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"}; map<string , PlayerProxy::Ptr> proxyMap; int i=0; for(auto url : urlList){ PlayerProxy::Ptr player(new PlayerProxy("live",to_string(i++).data())); player->play(url); proxyMap.emplace(string(url),player); }
-
As a pusher:
PlayerProxy::Ptr player(new PlayerProxy("app","stream")); player->play("rtmp://live.hkstv.hk.lxdns.com/live/hks"); RtmpPusher::Ptr pusher; NoticeCenter::Instance().addListener(nullptr,Config::Broadcast::kBroadcastRtmpSrcRegisted, [&pusher](BroadcastRtmpSrcRegistedArgs){ const_cast<RtmpPusher::Ptr &>(pusher).reset(new RtmpPusher(app,stream)); pusher->publish("rtmp://jizan.iok.la/live/test"); });
Binary file download
zlmediakit uses github action to continuously integrate automatic compilation package and upload the compilation output package. Please download the latest sdk library file and executable file at [issue list] (https://github.com/ZLMediaKit/ZLMediaKit/issues/483).
Docker Image
You can download the pre-compiled image from Docker Hub and start it:
#This image is pushed by the GitHub continuous integration automatic compilation to keep up with the latest code (master branch)
docker run -id -p 1935:1935 -p 8080:80 -p 8443:443 -p 8554:554 -p 10000:10000 -p 10000:10000/udp -p 8000:8000/udp -p 9000:9000/udp zlmediakit/zlmediakit:master
You can also compile the image based on the Dockerfile:
bash build_docker_images.sh
Collaborative Projects
-
Visual management website
-
Media management platform
- GB28181 complete solution with web management website, supporting webrtc and h265 playback
- Powerful media control and management interface platform, supporting GB28181
- GB28181 server implemented in C++
- GB28181 server implemented in Go
- Node-js version of GB28181 platform
- Hikvision ehome server implemented in Go
-
Client
-
Player
License
The self-owned code of this project is licensed under the permissive MIT License and can be freely applied to commercial and non-commercial projects while retaining copyright information. However, this project also uses some scattered open source code , please replace or remove it for commercial use. Any commercial disputes or infringement caused by using this project have nothing to do with the project and developers and shall be at your own legal risk. When using the code of this project, the license agreement should also indicate the license of the third-party libraries that this project depends on.
Contact Information
- Email: 1213642868@qq.com (For project-related or streaming media-related questions, please follow the issue process. Otherwise, we will not reply to emails.)
- QQ groups: Both QQ groups with a total of 4000 members are full. We will not create new QQ groups in the future. Users can join the Knowledge Planet to ask questions and support this project.
- Follow WeChat Official Account:
How to Ask Questions?
If you have any questions about the project, we recommend that you:
-
- Carefully read the readme and wiki. If necessary, you can also check the issues.
-
- If your question has not been resolved, you can raise an issue.
-
- Some questions may not be suitable for issues, but can be raised in QQ groups.
-
- We generally do not accept free technical consulting and support via QQ private chat. (Why we don't encourage QQ private chat).
-
- If you need more timely and thoughtful technical support, you can join the Knowledge Planet for a fee.
Special Thanks
This project uses the media-server library developed by Lao Chen. The reuse and de-multiplexing of ts/fmp4/mp4/ps container formats in this project depend on the media-server library. Lao Chen has provided invaluable help and support multiple times in implementing many functions of this project, and we would like to express our sincere gratitude to him!
Acknowledgments
Thanks to all those who have supported this project in various ways, including but not limited to code contributions, problem feedback, and donations. The following list is not in any particular order:
老陈 Gemfield 南冠彤 凹凸慢 chenxiaolei 史前小虫 清涩绿茶 3503207480 DroidChow 阿塞 火宣 γ瑞γミ linkingvision 茄子 好心情 浮沉 Xiaofeng Wang doodoocoder qingci swwheihei KKKKK5G Zhou Weimin Jim Jin 西瓜丶 MingZhuLiu chengxiaosheng big panda tanningzhong hctym1995 hewenyuan sunhui mirs Kevin Cheng Liu Jiang along qingci lyg1949 zhlong 大裤衩 droid.chow 陈晓林 CharleyWangHZ Johnny DoubleX69 lawrencehj yangkun Xinghua Zhao hejilin rqb500 Alex Dw9 明月惊鹊 cgm hejilin alexliyu7352 cgm haorui wang joshuafc JayChen0519 zx wangcker WuPeng starry mtdxc 胡刚风 zhao85 dreamisdream dingcan Haibo Chen Leon custompal PioLing KevinZang gongluck a-ucontrol TalusL ahaooahaz TempoTian Derek Liu ljx0305 朱如洪 lijin PioLing BackT0TheFuture perara codeRATny dengjfzh 百鸣 fruit Juice tbago Luosh linxiaoyan87 waken Deepslient imp_rayjay ArmstrongCN leibnewton 1002victor Grin xbpeng121 lvchenyun Fummowo Jovial Young yujitai KisChang zjx94 LeiZhi.Mai JiaHao chdahuzi snysmtx SetoKaiba sandro-qiang Paul Philippov 张传峰 lidaofu-hub huangcaichun jamesZHANG500 weidelong 小强先生 李之阳
Also thank to JetBrains for their support for open source project, we developed and debugged zlmediakit with CLion:
Use Cases
This project has gained recognition from many companies and individual developers. According to the author's incomplete statistics, companies using this project include well-known Internet giants, leading cloud service companies in China, several well-known AI unicorn companies, as well as a series of small and medium-sized companies. Users can endorse this project by pasting their company name and relevant project information on the issue page. Thank you for your support!