Compile and run ZLMediaKit on Windows

Summary

This article describes how to compile and run ZLMediaKIt on Windows .

lab environment

操作系统:Windows 10 (22H2 19045.2251)
开发工具:Visual Studio 2022

background knowledge

Compiling ZLMediaKit on Windows is slightly more difficult than compiling ZLMediaKit on Ubuntu .

To experience the lowest latency WebRTC function of ZLMediaKit, you need to pre-compile the following open source libraries:

FFmpeg: 用于拉流、转码、编码、推流。
OpenSSL: 加密库、TLS库。
libsrtp:SRTP(安全实时传输协议),用于WebRTC音视频数据的安全传输。
usrsctp: 一个采用C语言开发的SCTP协议栈,用于WebRTC数据通道的安全传输。

FFmpeg compilation

Method 1: Download the precompiled development package directly from the FFmpeg official website.

Method 2: Refer to "Compiling FFmpeg on Windows"

OpenSSL compilation

It is recommended to use vcpkg to install the OpenSSL 3.1.1 development package. The command is as follows:

vcpkg install openssl --triplet x64-windows

Set the environment variable CMAKE_TOOLCHAIN_FILE to the vcpkg.cmake file path. The example is as follows:

rem 请将环境变量值替换成你的vcpkg的实际安装路径。
环境变量名:CMAKE_TOOLCHAIN_FILE
环境变量值:G:\vcpkg\scripts\buildsystems\vcpkg.cmake

libsrtp compile

Run cmd.exe and perform the following operations in its command line interface:

#获取源码
git clone https://github.com/cisco/libsrtp.git

#进入libsrtp的源码仓库目录,用git命令查看标签,创建分支:
cd libsrtp
git tag
git checkout v2.5.0

#创建构建目录,用cmake构建。
mkdir build_x64
cd build_x64
cmake -S .. -B . -A x64 -DBUILD_SHARED_LIBS=on -DENABLE_OPENSSL=on
rem 如下命令会构建所有项目(project),包括测试项目。
cmake --build . --config Debug --target ALL_BUILD
rem 如果你只想构建srtp2项目,可以将上一行命令替换为如下命令:
cmake --build . --config Debug --target srtp2

#安装编译结果
#注意:将YOU_SRTP_INTALL_DIR替换为实际的安装目录。
cmake --install . --config Debug --prefix YOU_SRTP_INTALL_DIR

#修改PATH环境变量
#为了让cmake的find_package命令能找到已安装的librtcp开发包,
#请将libsrtp开发包的实际安装目录添加到PATH环境变量中。

usrsctp compile

Find a source code warehouse to store the folder, run cmd.exe, and perform the following operations:

git clone https://github.com/sctplab/usrsctp.git
cd usrsctp
git tag
git checkout 0.9.5.0
mkdir build_x64
cd build_x64
rem 注意:用你本地工作路径替换“--install-prefix=”参数的值。
cmake -S .. -B . -A x64 --install-prefix=%YOUR_WORK_DIR%\usrsctp\output -Dsctp_werror=off
rem 用VS 2022打开生成的解决方案,修改usrsctp项目的Debug配置的运行库选项,
rem 改为与ZLMediaKit的MediaServer项目的配置一致,比如:/MTd。
rem 编译usrsctp项目和INSTALL项目。
rem 将output目录的全路径添加到PATH环境变量中,
rem 或者将安装包内容复制到任何cmake能查找到的目录。

Get ZLMediaKit source code

ZLMediaKit officially recommends using git to clone the ZLMediaKit code. The example is as follows:

#国内用户推荐从同步镜像网站gitee下载 
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd ZLMediaKit
#千万不要忘记执行这句命令
git submodule update --init

Configure and build a Visual Studio solution

Run the cmake-gui program, select the ZLMediaKit source code directory and output directory, click the Configure button first, and then click the Generate button. The example is as follows:

Compile and run ZLMediaKit

打开ZLMediaKit\release\windows\Debug\Debug目录下的config.ini,修改secret密钥。
打开上一节的生成目录(例如:build_x64),双击打开ZLMediaKit.sln解决方案。
将MediaServer设为启动项目,按F5自动编译和运行。

Summarize

On Windows, compiling the dependent libraries of ZLMediaKit is relatively troublesome, and there are many compilation methods. It requires more hands-on practice and troubleshooting when encountering problems. Once you have prepared the dependency libraries of ZLMediaKit, you will have a relaxed feeling of "a new village has a bright future" when you use a powerful IDE such as Visual Studio 2022 to compile and debug the ZLMediaKit source code.

Guess you like

Origin blog.csdn.net/bigwave2000/article/details/132295190
Recommended