WebRTC/RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181/SRT server and client framework based on C++11
Go to file
2023-12-09 16:23:51 +08:00
.github release 8.0 2023-12-09 16:23:51 +08:00
3rdpart release 8.0 2023-12-09 16:23:51 +08:00
Android release 8.0 2023-12-09 16:23:51 +08:00
api release 8.0 2023-12-09 16:23:51 +08:00
cmake 升级jemalloc到5.3版本 (#2884) 2023-10-09 19:37:04 +08:00
conf release 8.0 2023-12-09 16:23:51 +08:00
docker release 8.0 2023-12-09 16:23:51 +08:00
package/rpm release 8.0 2023-12-09 16:23:51 +08:00
player release 8.0 2023-12-09 16:23:51 +08:00
postman 新增downloadFile接口,支持下载限定目录下任意文件 (#3073) 2023-12-02 15:58:40 +08:00
server release 8.0 2023-12-09 16:23:51 +08:00
src release 8.0 2023-12-09 16:23:51 +08:00
srt release 8.0 2023-12-09 16:23:51 +08:00
tests release 8.0 2023-12-09 16:23:51 +08:00
tools/openapi 通过持续集成自动生成openapi相关文件 (#3042) 2023-11-30 17:58:28 +08:00
webrtc release 8.0 2023-12-09 16:23:51 +08:00
webrtc_player/android android webrtc player 2022-09-25 10:51:43 +08:00
www release 8.0 2023-12-09 16:23:51 +08:00
.clang-format clang-format列宽调整为160 2023-04-18 10:34:00 +08:00
.gitattributes 去除gfs依赖 2019-10-25 10:46:59 +08:00
.gitignore 更新.gitignore文件,排除out目录。 2022-08-26 10:37:47 +08:00
.gitmodules 更新webassist 2023-10-27 21:45:03 +08:00
.gitmodules_github 新增web后台管理网页 2023-10-25 20:36:19 +08:00
AUTHORS 更新作者列表 2023-12-02 14:11:54 +08:00
build_docker_images.sh 使用docker buildx, 用于支持跨平台build 2022-09-14 10:08:18 +08:00
CMakeLists.txt release 8.0 2023-12-09 16:23:51 +08:00
default.pem 更新默认ssl证书 2023-09-28 15:48:51 +08:00
dockerfile Docker镜像新增支持webrtc datachannel (#3020 #3019) 2023-11-24 17:32:32 +08:00
k8s_readme.md 添加k8s部署相关说明 2021-09-13 21:16:22 +08:00
LICENSE release 8.0 2023-12-09 16:23:51 +08:00
README_en.md release 8.0 2023-12-09 16:23:51 +08:00
README.md Update README.md (#3075) 2023-12-05 01:58:45 +08:00
sources.list 修改docker镜像为国内源,加快镜像构建速度 2022-01-04 21:13:55 +08:00
version.h.ini 完善版本信息 2022-11-06 00:38:14 +08:00

logo

简体中文 | 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

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 and rtp 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
  • 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
  • SRT support

  • 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

  • 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 viedoTrack = strongPlayer->getTrack(TrackVideo);
        if (!viedoTrack) {
            WarnL << "No video Track!";
            return;
        }
        viedoTrack->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");
    });
    
    

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

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:

    1. Carefully read the readme and wiki. If necessary, you can also check the issues.
    1. If your question has not been resolved, you can raise an issue.
    1. Some questions may not be suitable for issues, but can be raised in QQ groups.
    1. We generally do not accept free technical consulting and support via QQ private chat. (Why we don't encourage QQ private chat).
    1. 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

Also thank to JetBrains for their support for open source project, we developed and debugged zlmediakit with CLion:

JetBrains

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!