25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README_en.md 8.7KB

6 달 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. ![logo](https://raw.githubusercontent.com/zlmediakit/ZLMediaKit/master/www/logo.png)
  2. # A lightweight ,high performance and stable stream server and client framework based on C++11.
  3. [![license](http://img.shields.io/badge/license-MIT-green.svg)](https://github.com/xia-chu/ZLMediaKit/blob/master/LICENSE)
  4. [![C++](https://img.shields.io/badge/language-c++-red.svg)](https://en.cppreference.com/)
  5. [![platform](https://img.shields.io/badge/platform-linux%20|%20macos%20|%20windows-blue.svg)](https://github.com/xia-chu/ZLMediaKit)
  6. [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-yellow.svg)](https://github.com/xia-chu/ZLMediaKit/pulls)
  7. [![Build Status](https://travis-ci.org/xia-chu/ZLMediaKit.svg?branch=master)](https://travis-ci.org/xia-chu/ZLMediaKit)
  8. ## Why ZLMediaKit?
  9. - Developed based on C++ 11, the code is stable and reliable, avoiding the use of raw pointers, cross-platform porting is simple and convenient, and the code is clear and concise.
  10. - Support rich streaming media protocols(`RTSP/RTMP/HLS/HTTP-FLV/WebSocket-flv/HTTP-TS/WebSocket-TS/HTTP-fMP4/Websocket-fMP4/MP4/WebRTC`),and support Inter-protocol conversion.
  11. - Multiplexing asynchronous network IO based on epoll and multi thread,extreme performance.
  12. - Well performance and stable test,can be used commercially.
  13. - Support linux, macos, ios, android, Windows Platforms.
  14. - Very low latency(lower then one second), video opened immediately.
  15. ## Features
  16. - RTSP[S]
  17. - RTSP[S] server,support rtsp push.
  18. - RTSP[S] player and pusher.
  19. - RTP Transport : `rtp over udp` `rtp over tcp` `rtp over http` `rtp udp multicast` .
  20. - Basic/Digest/Url Authentication.
  21. - H265/H264/AAC/G711/OPUS codec.
  22. - Recorded as mp4.
  23. - Vod of mp4.
  24. - RTMP[S]
  25. - RTMP[S] server,support player and pusher.
  26. - RTMP[S] player and pusher.
  27. - Support HTTP-FLV/WebSocket-FLV sever.
  28. - H265/H264/AAC/G711/OPUS codec.
  29. - Recorded as flv or mp4.
  30. - Vod of mp4.
  31. - support [RTMP-H265](https://github.com/ksvc/FFmpeg/wiki)
  32. - HLS
  33. - RTSP RTMP can be converted into HLS,built-in HTTP server.
  34. - Play authentication based on cookie.
  35. - Support HLS player, support streaming HLS proxy to RTSP / RTMP / MP4.
  36. - TS
  37. - Support HTTP-TS/WebSocket-TS sever.
  38. - fMP4
  39. - Support HTTP-fMP4/WebSocket-fMP4 sever.
  40. - HTTP[S]
  41. - HTTP server,suppor directory meun、RESTful http api.
  42. - HTTP client,downloader,uploader,and http api requester.
  43. - Cookie supported.
  44. - WebSocket Server and Client.
  45. - File access authentication.
  46. - WebRTC(experiential)
  47. - Support webrtc push stream and transfer to other protocols
  48. - Support webrtc play, support other protocol to webrtc
  49. - Support simulcast
  50. - Support rtx/nack
  51. - Support transport-cc rtcp/rtp ext
  52. - [SRT support](./srt/srt_en.md)
  53. - Others
  54. - Support stream proxy by ffmpeg.
  55. - RESTful http api and http hook event api.
  56. - Config file hot loading.
  57. - Vhost supported.
  58. - Auto close stream when nobody played.
  59. - Play and push authentication.
  60. - Pull stream on Demand.
  61. - Support TS / PS streaming push through RTP,and it can be converted to RTSP / RTMP / HLS / FLV.
  62. - Support real-time online screenshot http api.
  63. ## System Requirements
  64. - Compiler support c++11,GCC4.8/Clang3.3/VC2015 or above.
  65. - cmake3.1 or above.
  66. - All Linux , both 32 and 64 bits
  67. - Apple OSX(Darwin), both 32 and 64bits.
  68. - All hardware with x86/x86_64/arm/mips cpu.
  69. - Windows.
  70. ## How to build
  71. It is recommended to compile on Ubuntu or MacOS,compiling on windows is cumbersome, and some features are not compiled by default.
  72. ### Before build
  73. - **You must use git to clone the complete code. Do not download the source code by downloading zip package. Otherwise, the sub-module code will not be downloaded by default.You can do it like this:**
  74. ```
  75. git clone https://github.com/xia-chu/ZLMediaKit.git
  76. cd ZLMediaKit
  77. git submodule update --init
  78. ```
  79. ### Build on linux
  80. - My environment
  81. - Ubuntu16.04 64 bit and gcc5.4
  82. - cmake 3.5.1
  83. - Guidance
  84. ```
  85. # If it is on centos6.x, you need to install the newer version of GCC and cmake first,
  86. # and then compile manually according to the script "build_for_linux.sh".
  87. # If it is on a newer version of a system such as Ubuntu or Debain,
  88. # step 4 can be manipulated directly.
  89. # 1、Install GCC5.2 (this step can be skipped if the GCC version is higher than 4.7)
  90. sudo yum install centos-release-scl -y
  91. sudo yum install devtoolset-4-toolchain -y
  92. scl enable devtoolset-4 bash
  93. # 2、Install cmake (this step can be skipped if the cmake version is higher than 3.1)
  94. tar -xvf cmake-3.10.0-rc4.tar.gz #you need download cmake source file manually
  95. cd cmake-3.10.0-rc4
  96. ./configure
  97. make -j4
  98. sudo make install
  99. # 3、Switch to high version GCC
  100. scl enable devtoolset-4 bash
  101. # 4、build
  102. cd ZLMediaKit
  103. ./build_for_linux.sh
  104. ```
  105. ### Build on macOS
  106. - My environment
  107. - macOS Sierra(10.12.1) + xcode8.3.1
  108. - Homebrew 1.1.3
  109. - cmake 3.8.0
  110. - Guidance
  111. ```
  112. cd ZLMediaKit
  113. ./build_for_mac.sh
  114. ```
  115. ### Build on iOS
  116. - You can generate Xcode projects and recompile them , [learn more](https://github.com/leetal/ios-cmake):
  117. ```
  118. cd ZLMediaKit
  119. mkdir -p build
  120. cd build
  121. # Generate Xcode project, project file is in build directory
  122. cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED
  123. ```
  124. ### Build on Android
  125. Now you can open android sudio project in `Android` folder,this is a `aar library` and damo project.
  126. - My environment
  127. - macOS Sierra(10.12.1) + xcode8.3.1
  128. - Homebrew 1.1.3
  129. - cmake 3.8.0
  130. - [android-ndk-r14b](https://dl.google.com/android/repository/android-ndk-r14b-darwin-x86_64.zip)
  131. - Guidance
  132. ```
  133. cd ZLMediaKit
  134. export ANDROID_NDK_ROOT=/path/to/ndk
  135. ./build_for_android.sh
  136. ```
  137. ### Build on Windows
  138. - My environment
  139. - windows 10
  140. - visual studio 2017
  141. - [cmake-gui](https://cmake.org/files/v3.10/cmake-3.10.0-rc1-win32-x86.msi)
  142. - Guidance
  143. ```
  144. 1 Enter the ZLMediaKit directory and execute git submodule update -- init downloads the code for ZLToolKit
  145. 2 Open the project with cmake-gui and generate the vs project file.
  146. 3 Find the project file (ZLMediaKit.sln), double-click to open it with vs2017.
  147. 4 Choose to compile Release version. Find the target file and run the test case.
  148. ```
  149. ## Usage
  150. - As server:
  151. ```cpp
  152. TcpServer::Ptr rtspSrv(new TcpServer());
  153. TcpServer::Ptr rtmpSrv(new TcpServer());
  154. TcpServer::Ptr httpSrv(new TcpServer());
  155. TcpServer::Ptr httpsSrv(new TcpServer());
  156. rtspSrv->start<RtspSession>(mINI::Instance()[Config::Rtsp::kPort]);
  157. rtmpSrv->start<RtmpSession>(mINI::Instance()[Config::Rtmp::kPort]);
  158. httpSrv->start<HttpSession>(mINI::Instance()[Config::Http::kPort]);
  159. httpsSrv->start<HttpsSession>(mINI::Instance()[Config::Http::kSSLPort]);
  160. ```
  161. - As player:
  162. ```cpp
  163. MediaPlayer::Ptr player(new MediaPlayer());
  164. weak_ptr<MediaPlayer> weakPlayer = player;
  165. player->setOnPlayResult([weakPlayer](const SockException &ex) {
  166. InfoL << "OnPlayResult:" << ex.what();
  167. auto strongPlayer = weakPlayer.lock();
  168. if (ex || !strongPlayer) {
  169. return;
  170. }
  171. auto viedoTrack = strongPlayer->getTrack(TrackVideo);
  172. if (!viedoTrack) {
  173. WarnL << "none video Track!";
  174. return;
  175. }
  176. viedoTrack->addDelegate([](const Frame::Ptr &frame) {
  177. //please decode video here
  178. });
  179. });
  180. player->setOnShutdown([](const SockException &ex) {
  181. ErrorL << "OnShutdown:" << ex.what();
  182. });
  183. //rtp transport over tcp
  184. (*player)[Client::kRtpType] = Rtsp::RTP_TCP;
  185. player->play("rtsp://admin:jzan123456@192.168.0.122/");
  186. ```
  187. - As proxy server:
  188. ```cpp
  189. //support rtmp and rtsp url
  190. //just support H264+AAC
  191. auto urlList = {"rtmp://live.hkstv.hk.lxdns.com/live/hks",
  192. "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"};
  193. map<string , PlayerProxy::Ptr> proxyMap;
  194. int i=0;
  195. for(auto url : urlList){
  196. PlayerProxy::Ptr player(new PlayerProxy("live",to_string(i++).data()));
  197. player->play(url);
  198. proxyMap.emplace(string(url),player);
  199. }
  200. ```
  201. - As puser:
  202. ```cpp
  203. PlayerProxy::Ptr player(new PlayerProxy("app","stream"));
  204. player->play("rtmp://live.hkstv.hk.lxdns.com/live/hks");
  205. RtmpPusher::Ptr pusher;
  206. NoticeCenter::Instance().addListener(nullptr,Config::Broadcast::kBroadcastRtmpSrcRegisted,
  207. [&pusher](BroadcastRtmpSrcRegistedArgs){
  208. const_cast<RtmpPusher::Ptr &>(pusher).reset(new RtmpPusher(app,stream));
  209. pusher->publish("rtmp://jizan.iok.la/live/test");
  210. });
  211. ```
  212. ## Docker Image
  213. You can pull a pre-built docker image from Docker Hub and run with
  214. ```bash
  215. 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
  216. ```
  217. Dockerfile is also supplied to build images on Ubuntu 16.04
  218. ```bash
  219. cd docker
  220. docker build -t zlmediakit .
  221. ```
  222. ## Contact
  223. - Email:<1213642868@qq.com>
  224. - QQ chat group:542509000