Skip to main content

Tutorial

ZLMediaKitAbout 4 min

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)
Debian-based (including Ubuntu)
sudo apt install build-essential

CMake

ZLMediaKit uses CMake to build the project, so you need CMake to compile.

Debian-based (including Ubuntu)
sudo apt install cmake

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.

Debian-based (including Ubuntu)

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

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.

Linux
cd ZLMediaKit
mkdir build
cd build
cmake ..
make -j4

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.

Linux
cd ZLMediaKit/release/linux/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:

Linux
ZLMediaKit/release/linux/Debug/libmk_api.so

Test programs starting with test_

Related codes are under ZLMediaKit/tests directory, and you can start the test process by reading codes.

Stream Testing

Please refer to Stream Test.