Tutorial
This tutorial will guide you compiling and running ZLMediaKit.
Build Environment
Beginner Notice
If you're a beginner, we highly recommend compiling ZLMediaKit using Ubuntu16 or later versions. macOS is the second recommended platform. We don't recommend using CentOS6.x or Windows.
vcpkg
ZLMediaKit has been launched on vcpkg, please refer to install zlmediakit using vcpkg for convenient installation.
Compiler Supporting C++11
ZLMediaKit uses C++11 syntax and libraries, hence, it's required that your compiler fully supports the C++11 standard. This means:
- On Linux, gcc version >= 4.8 (4.7 should also be supported)
- On macOS, clang >= ??? (it's uncertain, but most likely won't encounter any issues)
- On Windows, Visual Studio >= 2015 (some versions of VS2013 can also compile, but for a smoother experience, VS2017 is recommended)
sudo apt install build-essential
sudo yum -y install gcc
sudo yum -y install gcc-c++
You need to manually switch to a higher version of gcc.
sudo yum install centos-release-scl -y
sudo yum install devtoolset-4-toolchain -y
# Switch to a higher version gcc
scl enable devtoolset-4 bash
Install latest Visual Studio Community and click C++ env.
CMake
ZLMediaKit uses CMake to build the project, so you need CMake to compile.
sudo apt install cmake
sudo yum -y install cmake
You need to manually switch to a higher version of CMake.
wget https://github.com/Kitware/CMake/releases/download/v3.17.0-rc3/cmake-3.17.0-rc3.tar.gz
tar -xvf cmake-3.17.0-rc3.tar.gz
cd cmake-3.17.0-rc3
./configure
make -j4
sudo make install
brew install cmake
- If using vs2017+, vs already includes cmake, you just need to tick it during installation.
- Otherwise, you need to download and install cmake-gui
Obtain Source Code
Use git to clone the ZLMediaKit source code and its submodules:
git clone --depth 1 https://github.com/ZLMediaKit/ZLMediaKit
cd ZLMediaKit
# Init submodules (Required)
git submodule update --init
Warning
Do NOT download the source code with zip directly from GitHub. ZLMediaKit is relaying on multiple third-party project codes and manages them with git submodules.
3rd party Dependencies
ZLMediaKit depends on some optional third-party libraries. During the building of ZLMediaKit, cmake can search for these libraries in the system path and enable relevant features based on their installation status.
openssl
You need to install the openssl library before compiling to use related features.
- Playing rtmp with flash player
- https/rtsps/webrtc related features
ffmpeg
ZLMediaKit can support multiple protocols for pulling streams by forking ffmpeg as a subprocess. FFmpeg does not need to be installed during compilation.
sdl, avcodec, avutil
These three libraries are used by the test_player test program of ZLMediaKit. You usually do not need to install these three libraries.
Except openssl, others are optional:
sudo apt install libssl-dev
sudo apt install libsdl-dev
sudo apt install libavcodec-dev
sudo apt install libavutil-dev
sudo apt install ffmpeg
sudo yum install libssl-dev
sudo yum install libsdl-dev
sudo yum install libavcodec-dev
sudo yum install libavutil-dev
sudo yum install ffmpeg
Refer to blog post。
sudo brew install libssl-dev
sudo brew install libsdl-dev
sudo brew install libavcodec-dev
sudo brew install libavutil-dev
sudo brew install ffmpeg
Building and Compiling ZLMediaKit
webrtc
由于功能复杂,默认情况下不开启编译 webrtc,可参考 编译与使用 webrtc
Because of complex, the webrtc compilation is not enabled by default. Please refer to compilation and usage of webrtc.
cd ZLMediaKit
mkdir build
cd build
cmake ..
make -j4
cd ZLMediaKit
mkdir build
cd build
# Point DOPENSSL_ROOT_DIR to your openssl path
cmake .. -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2j/
make -j4
If you are using VS2017 or above, you can directly open the project folder from the VS navbar with
File
->Open
->Folder
->Select ZLMediaKit code root directory and open
.Otherwise, you should:
- Use cmake-gui to open the project and generate the vs project file.
- Find the project file (ZLMediaKit.sln) and double-click it to open with vs2017.
- Choose to compile the Release version.
- Locate the target file and run the test case.
For further details, refer to Windows compilation.
Open the Android directory in Android Studio.
Generate XCode project and then compile the C API static library.
cd ZLMediaKit
mkdir -p build
cd build
# Generate the Xcode project, the project file is in the build directory
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED
Run ZLMediaKit
The ZLMediaKit project mainly generates three types of binary target files, which are located in release directory.
MediaServer Process
This is the main process of ZLMediaKit as a server. This process can be used directly as a streaming media server for testing without any development.
If you need more complex business logic, you can implement it through Web HOOK and RESTful API. At the same time, you can control its parameters through the configuration file.
cd ZLMediaKit/release/linux/Debug
# Learn startup parameters with -h
./MediaServer -h
# Start in daemon mode
./MediaServer -d &
cd ZLMediaKit/release/mac/Debug
# Learn startup parameters with -h
./MediaServer -h
# Start in daemon mode
./MediaServer -d &
cd ZLMediaKit/release/windows/Debug
# Learn startup parameters with -h
./MediaServer -h
# Start in daemon mode
./MediaServer -d &
C API SDK
ZLMediaKit also provides a C language-based API SDK library for further development.
The header file is located at ZLMediaKit/api/include
with detailed comments, could be generally sufficient for further development.
Lib files:
ZLMediaKit/release/linux/Debug/libmk_api.so
ZLMediaKit/release/linux/mac/libmk_api.dylib
ZLMediaKit/release/windows/Debug/mk_api.dll
ZLMediaKit/release/windows/Debug/mk_api.lib
test_
Test programs starting with Related codes are under ZLMediaKit/tests
directory, and you can start the test process by reading codes.
Stream Testing
Please refer to Stream Test.