QT with ZLMediaKit (流媒体服务器)
For QT
撸个开源的 流媒体服务项目
ZLMediaKit
主项目还依赖另一个项目的网络库 ZLToolKit
所以也要下载, 转为QT项目
- 把
ZLToolKit项目的src 改个名 core , 加到项目 - add exist directory
./ZLToolKit/
./core/
./jsoncpp/
/server/- 头文件查找路径
INCLUDEPATH +=\
$$PWD/ZLToolKit/ \
$$PWD/core/ \
$$PWD/jsoncpp/ \其中 ./server/main.cpp 为服务端主入口代码
踩坑
-
主项目(ZLMediaKit)的api目录, 不能引入, 貌似是个lib库项目..
-
server/Process.cpp:56: error:
cannot initialize a variable of type 'LPTSTR' (aka 'wchar_t *') with an rvalue of type 'char *'-
char* 和 wchar_t*(宽字符) 转换问题
LPTSTR lpDir = const_cast<char*>(cmd .data());修改:
const char* c = cmd .data();
int len = MultiByteToWideChar(CP_ACP, 0, c, strlen(c), NULL, 0);
wchar_t lpDir[len + 1];
MultiByteToWideChar(CP_ACP, 0, c, strlen(c), lpDir, len);
lpDir[len] = '\0';- error: undefined reference to `_imp__WSAStartup@8’
原因是socket库的编译链接问题; 在项目的pro文件中添加
LIBS += -lpthread libwsock32 libws2_32
3.1. undefined reference to `GetAdaptersInfo@8’
E:\Cpp_Project\ZLMedia\ZLToolKit\Network\sockutil.cpp:361: error: undefined reference to GetAdaptersInfo@8’`
还是 gcc 编译链接不到库, 依赖头文件在qt是 mingw730_32的iphlpapi.h, 但是lib目录没有Iphlpapi.lib..
还还是socket库问题
最终这个库是Windows SDK 我** (前身是名称Platform SDK)开发包
Windows SDK(Platform SDK)是由微软公司出品的一个软件开发包, 向在微软的Windows操作系统和.NET框架上开发软件和网站的程序员提供头文件, 库文件, 示例代码, 开发文档和开发工具;
Windows 10 SDK 下载页 Microsoft Windows SDK for Windows 7 and .NET Framework 4 下载页
win 10 下了一大堆
Windows SDK Desktop Libs x64-x86_en-us.msi 安装之完成后,库文件载在 ./Program Files (x86)目录下(搜索IPHlpApi)
附加到QT LIBS += $$PWD/lib/IPHlpApi.Lib 编译…
OK!!!
归档
错误
-
编译UFT8无BOM源文件, 会报各种语法错误, 最后转成有bom的源文件
-
LINK: fatal error LNK1146 没有用选项”/LIBPATH:“指定的参数 总是链接错误
解决: 引入格式有严格的限制
INCLUDEPATH += $${PWD}/ffmpeg-4.1.1-win32-dev/include
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib/" -lavformat
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lavcodec
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lavdevice
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lavfilter
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lavutil
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lpostproc
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lswresample
LIBS += -L"F:/cpp_project/rtsp_server/rtsp_server/ffmpeg-4.1.1-win32-dev/lib" -lswscale- NMAKE: fatal error U1056: cannot find command processor
看编译输出
NMAKE: fatal error U1056: cannot find command processor
Stop.
14:04:02: The process "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe" exited with code 2.
Error while building/deploying project rtsp_server (kit: Desktop Qt 5.11.2 MSVC2015 32bit)
When executing step "Make"
The command processor was not in the path specified in the COMSPEC or PATH environment variables.
NMAKE uses COMMAND.COM or CMD.EXE as a command processor when executing commands. It looks for the command processor first in the path set in COMSPEC. If COMSPEC does not exist, NMAKE searches the directories specified in PATH.
COMSPEC 这个变量指向命令处理器? 什么鬼?
QT -> project -> build -> build environment
解决:
添加个环境变量
COMSPEC= C:\WINDOWS\system32\cmd.exe
- NMAKE: fatal error U1077
关键 :-1: error: LNK1104: cannot open file ‘C:\WINDOWS\lnk{xxx}.tmp’
貌似生成一堆临时文件在C:\WINDOWS,与上面指向的路径有关?
解决: 以管理员运行
- LINK: fatal error LNK1158: cannot run ‘rc.exe’
这个程序可以在 win sdk里面找到
解决:
从C:\Program Files (x86)\Windows Kits\8.1\bin\x86 复制 rcdll.dll和 rc.exe
到编译器目录安装目录bin C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
finall 可以愉快的使用 crtdbg了 !!!
补充:
解决 COMSPEC 环境变量问题, qt 在 build environment 不清理系统环境, 即可…
For Visual Studio 2019
- 下载源码
# 国内用户推荐从同步镜像网站gitee下载
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd ZLMediaKit
# 千万不要忘记执行这句命令(依赖的模块)
git submodule update --init
- CMake Gui生成 Visual Studio 项目
Where is the source code > F:/git_project/ZLMediaKit//选下载的路径
Where to build the binaries> F:/ZLMediaKit-vs //作为Visual Studio项目的文件夹注意: Visual Studio 项目其源码是引用自
Where is the source code的路径的
Configure > Visual Studio 2019
Generate > OK!
流地址测试
推流地址: rtmp://127.0.0.1/live/obs/
路径: /live/obs/
rtmp://192.168.20.130:1935/live/bxx
其他播放协议
- RTSP
rtsp://127.0.0.1/live/obs/
- HLS
http://127.0.0.1:9880/live/obs/hls.m3u8
- HTTP-TS/WS-TS
http://127.0.0.1:9880/live/obs.live.ts
ws://127.0.0.1:9880/live/obs.live.ts
- HTTP-fMP4 /WS-fMP4
http://127.0.0.1:9880/live/obs.live.mp4
ws://127.0.0.1:9880/live/obs.live.mp4
http://192.168.20.130:1935/live/bxx.live.mp4