windows编译ZLMediaKit(vcpkg)

发布时间 2023-07-08 22:34:36作者: 姬无华

windows编译ZLMediaKit

转载 https://www.jianshu.com/p/f6f1c0b7e32b

编译

#下载ZLMediaKit
git clone https://gitee.com/xia-chu/ZLMediaKit.git
#切换到ZLMediaKit目录
cd ZLMediaKit
#更新子模块代码
git submodule update --init

#vcpkg安装openssl
vcpkg install --triplet=x64-windows-static openssl
#编译 libsrtp,并且打开OPENSSL, 需要 ENABLE_OPENSSL, 可编辑 d:\vcpkg\ports\libsrtp\portfile.cmake, 修改
vcpkg_configure_cmake 为如下:
vcpkg_configure_cmake(
  SOURCE_PATH ${SOURCE_PATH}
  PREFER_NINJA
  OPTIONS
    -DENABLE_OPENSSL:BOOL=ON
)
#编译libsrtp
vcpkg install --triplet=x64-windows-static libsrtp
#打开x64 Native Tools
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2019环境
#切入到powershell中
powershell
#创建build目录
mkdir build
cd build
$VCPKG_CMAKE = 'D:\vcpkg\scripts\buildsystems\vcpkg.cmake'
$VCPKG_INSTALL_PATH = 'D:\vcpkg\installed\x64-windows-static'

$CMAKE_OPTIONS = @(
    "-GCodeBlocks - Ninja"
    "-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo"
    "-DCMAKE_C_COMPILER:STRING=cl.exe"
    "-DCMAKE_CXX_COMPILER:STRING=cl.exe"
    "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=$VCPKG_CMAKE"
    "-DCMAKE_PREFIX_PATH:FILEPATH=$VCPKG_INSTALL_PATH"
    "-DVCPKG_TARGET_TRIPLET:STRING=x64-windows-static"
    "-DENABLE_WEBRTC:BOOL=ON"
)
cmake .. @CMAKE_OPTIONS
cmake --build . --target all

#在window下启动:
1 进入ZLMediaKit/release/windows/Debug目录
2 双击MediaServer启动
3 你也可以在cmd或powershell中启动,通过MediaServer -h了解启动参数

推流测试

ZLMediaKit支持rtsp/rtmp/rtp推流,一般通常使用obs/ffmpeg推流测试,其中FFmpeg推流命令支持以下:

1、使用rtsp方式推流

# h264推流
ffmpeg -re -i "/path/to/test.mp4" -vcodec h264 -acodec aac -f rtsp -rtsp_transport tcp rtsp://127.0.0.1/live/test
# h265推流
ffmpeg -re -i "/path/to/test.mp4" -vcodec h265 -acodec aac -f rtsp -rtsp_transport tcp rtsp://127.0.0.1/live/test

2、使用rtmp方式推流

#如果未安装FFmpeg,你也可以用obs推流
ffmpeg -re -i "/path/to/test.mp4" -vcodec h264 -acodec aac -f flv rtmp://127.0.0.1/live/test
# RTMP标准不支持H265,但是国内有自行扩展的,如果你想让FFmpeg支持RTMP-H265,请按照此文章编译:https://github.com/ksvc/FFmpeg/wiki/hevcpush

3、使用rtp方式推流

# h264推流
ffmpeg -re -i "/path/to/test.mp4" -vcodec h264 -acodec aac -f rtp_mpegts rtp://127.0.0.1:10000
# h265推流
ffmpeg -re -i "/path/to/test.mp4" -vcodec h265 -acodec aac -f rtp_mpegts rtp://127.0.0.1:10000

文档

https://github.com/ZLMediaKit/ZLMediaKit/wiki/