windows编译ZLMediaKit流媒体服务webrtc
环境说明
ZLMediaKit编译需要的软件
visual studio | 2022 |
---|---|
cmake | 3.29.0-rc2 |
OpenSSL | 1.1.1w(不想踩坑的话安装这个版本) |
libsrtp | 2.6.0 |
ZLMediaKit编译后运行需要
libsrtp | 编译后且配置环境变量 |
---|---|
ZLMediaKit | 编译后文件 |
visual studio
cmake
visual stuido 20222,自带cmake
测试是否成功
C:\Users\XXX>cmake
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
OpenSSL
可以到OpenSSL安装window编译版本, 记得要下载是exe或msi文件,不要light的文件!!!!!
按步骤安装,安装地址为:C:\Program Files\OpenSSL-Win64
配置环境变量, 一定要配置正确!!!
测试
C:\Users\XXX>openssl -v
OpenSSL 3.2.1 30 Jan 2024 (Library: OpenSSL 3.2.1 30 Jan 2024)
可以不重启电脑,但必须关闭已经打开cmd窗口,否则会显示'openssl' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
libsrtp
libsrtp下载后解压,解压路径地址为: D:\XXX\soft\libsrtp-2.6.0
有两种编译方式:
第一种: visual stuido和cmake结合使用
-
首先在D:\XXX\soft\libsrtp-2.6.0\libsrtp-2.6.0新建build和install两个文件夹
-
打开cmake软件
-
完成后出现红色配置,勾选上BUILD_SHARED_LIBS、ENABLE_OPENSSL、以及CMAKE_INSTALL_PREFIX的路径,然后点生成。注意这里有个问题Could NOT find OpenSSL
-
如果3顺利的话,完成后的结果(换回1.1.1的测试结果),然后点open project
-
会打开vs
-
生成后会出现一些错误(但无影响)
-
install文件夹生成的目录
install目录│文件列表: ├ include │ └ srtp2 │ │ auth.h │ │ cipher.h │ │ crypto_types.h │ └ srtp.h └ lib │ srtp2.dll │ srtp2.lib └ cmake └ libSRTP │ libSRTPConfig.cmake │ libSRTPConfigVersion.cmake │ libSRTPTargets-debug.cmake └ libSRTPTargets.cmake
-
配置环境变量到path
D:\XXX\soft\libsrtp-2.6.0\libsrtp-2.6.0\install D:\XXX\soft\libsrtp-2.6.0\libsrtp-2.6.0\install\lib
编译ZLMediaKit
在使用VS打开ZLMediaKit项目时,如果未开启webrtc, 会出现
[CMake] -- set_file_group D:/XXX/project/ZLMediaKit/src 205
1> [CMake] -- srt 功能已开启
1> [CMake] CMake Warning at webrtc/CMakeLists.txt:28 (message):
1> [CMake] srtp 未找到, WebRTC 相关功能打开失败
要开启webrtc,需要保证以下正确
-
开启了webrtc
-
libsrtp编译正确且配置环境变量
开启成功的话, 会出现下面,然后安装ZLMediaKit
> [CMake] -- Enable wepoll
1> [CMake] -- set_file_group D:/XXX/project/ZLMediaKit/3rdpart/ZLToolKit/src 80
1> [CMake] -- set_file_group D:/XXX/project/ZLMediaKit/src 205
1> [CMake] -- srt 功能已开启
1> [CMake] -- found library: D:/XXX/soft/libsrtp-2.6.0/libsrtp-2.6.0/install/lib/srtp2.lib
1> [CMake] -- SCTP LIBRARIES: SCTP_LIBRARIES-NOTFOUND
1> [CMake] -- SCTP INCLUDE DIRS: SCTP_INCLUDE_DIRS-NOTFOUND
1> [CMake] -- WebRTC 功能已开启
如果不行先把out和release文件夹删除,再重新打开vs,然后安装ZLMediaKit
测试webrtc
打开编译目录,双击MediaServer.exe
先推流,用obs推流
chrome浏览器打开
点确定
点开始
问题
-
MediaServer.exe打开后,由于找不到 srtp2.dll,无法继续执行代码。重新安装程序可能会解决此问题
检查srtp2.dll的环境变量是否正确,如:D:\XXX\soft\libsrtp-2.6.0\libsrtp-2.6.0\install\lib
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
OPENSSL_INCLUDE_DIR) (Required is at least version "1.1.0") C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake 230
开始以为是安装openssl步骤有问题,改为第一个选项,结果还是这样的接口
然后看了报错
try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR
添加了环境变量
```
OPENSSL_ROOT_DIR C:\Program Files\OpenSSL-Win64
OPENSSL_CRYPTO_LIBRARY C:\Program Files\OpenSSL-Win64\lib
OPENSSL_INCLUDE_DIR C:\Program Files\OpenSSL-Win64\include
```
完成后重启,清除缓存生成依然没有效果
解决方式
-
换版本OpenSSL: Win64OpenSSL-1_1_1w.msi, 省很多事
C:\Users\XXX>openssl version OpenSSL 1.1.1w 11 Sep 2023
安装完成它的lib目录结构为:
lib目录│文件列表: │ capi.lib │ dasync.lib │ ec_internal_test.lib │ libapps.lib │ libcrypto.def │ libcrypto.lib │ libcrypto_static.lib │ libssl.def │ libssl.lib │ libssl_static.lib │ libtestutil.lib │ openssl.lib │ ossltest.lib │ padlock.lib │ uitest.lib └ VC │ libcrypto64MD.lib │ libcrypto64MDd.lib │ libcrypto64MT.lib │ libcrypto64MTd.lib │ libssl64MD.lib │ libssl64MDd.lib │ libssl64MT.lib │ libssl64MTd.lib └ static │ libcrypto64MD.lib │ libcrypto64MDd.lib │ libcrypto64MT.lib │ libcrypto64MTd.lib │ libssl64MD.lib │ libssl64MDd.lib │ libssl64MT.lib └ libssl64MTd.lib