windows 下编译 python_rtmpstream
wptr33 2025-05-24 17:33 14 浏览
最近在研究数字人,看了大咖的项目(
https://github.com/lipku/metahuman-stream),尝试编译此项目的依赖项目python_rtmpstream(
https://github.com/lipku/python_rtmpstream)。由于python_rtmpstream主要针对linux下,没有Windows的版本,因此编译出现较多的波折,但最终编译成功,特此记录。
一、编译环境说明
1、OS:Windows 10 专业版, 64 位操作系统, 基于 x64 的处理器
2、conda:安装的是
Anaconda3-2024.02-1-Windows-x86_64.exe
3、C++ Build tool:下载的是 vs_BuildTools.exe,安装后在C:\Program Files (x86)\Microsoft Visual Studio\2022,安装完成后设置环境变量 Path,增加如下两个路径:
(1)C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64
(2)C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin。这个是setup.py里需要cmake来编译C++代码,如果不设置,会报:error: [WinError 2] 系统找不到指定的文件。
4、SRS:流媒体服务器,安装的是
SRS-Windows-x86_64-5.0-r2-setup.exe,在运行 test_stream.py需要运行流媒体服务器。
二、建立项目环境
conda create -n nerfstream python=3.10
conda activate nerfstream
注意要做 cmd 下使用conda, 不要在 powershell 下使用
三、安装项目依赖
1、下载代码
git clone https://github.com/lipku/python_rtmpstream
cd python_rtmpstream
git submodule update --init
2、安装依赖
pip install wheel
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda install ffmpeg
四、修改CMakeLists.txt
注意:路径改为自己 conda nerfstream环境的路径,如果路径不正确,会报The following variables are used in this project, but they are set to NOTFOUND
五、修改streamer.cpp 和 streamer.hpp
1、streamer.cpp
解决如下三个问题
unistd.h、sys\time.h 文件找不到文件
gettimeofday在Windows下不适用
后跟初始值设定项列表的带圆括号类型是一个非标准的显式类型转换语法
(1)头文件增加如下,以便适配Windows环境
原来是
#include <string>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
改为
#include <string>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <inttypes.h>
#include <stdint.h>
#include <time.h>
#else
#include <unistd.h>
#include <sys/time.h>
#endif
(2)修改timems 函数
原来
static int64_t timems()
{
struct timespec now;
clock_gettime(CLOCK_BOOTTIME,&now);
return (now.tv_sec*1000 + now.tv_nsec/1000/1000);
}
改为
static int64_t timems()
{
#ifdef _WIN32
// Windows 平台特定实现
struct timespec ts;
if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
{
fputs("timespec_get failed!", stderr);
return 0;
}
return (ts.tv_sec*1000 + ts.tv_nsec/1000/1000);
#else
// POSIX 平台特定实现
struct timespec now;
clock_gettime(CLOCK_BOOTTIME,&now);
return (now.tv_sec*1000 + now.tv_nsec/1000/1000);
#endif
}
3、后跟初始值设定项列表的带圆括号类型是一个非标准的显式类型转换语法错误
codec_ctx->time_base = (AVRational){ 1, samplerate };
改为
codec_ctx->time_base = AVRational{ 1, samplerate };
2、streamer.hpp
解决posix_memalign 标识符问题
(1)头文件增加 #include <malloc.h>
(2)修改posix_memalign
将 int ret = posix_memalign(reinterpret_cast<void**>(&data), align_frame_buffer, sz);
改为
void* ptr = _aligned_malloc(sz,align_frame_buffer);
int ret = *(static_cast<int*>(ptr));
上述方法不正确,由于posix_memalign是Linux下的函数,windows下用_aligned_malloc分配内存,但它们还是有区别,用_aligned_malloc,在运行 test_stream.py时会报:bad dst image pointers 错误。
先改为如下:
在class Picture里增加如下代码,代替Linux下的posix_memalign方法
#ifdef _WIN32
static int check_align(size_t align)
{
for (size_t i = sizeof(void *); i != 0; i *= 2)
if (align == i)
return 0;
return EINVAL;
}
int posix_memalign(void **ptr, size_t align, size_t size)
{
if (check_align(align))
return EINVAL;
int saved_errno = errno;
void *p = _aligned_malloc(size, align);
if (p == NULL)
{
errno = saved_errno;
return ENOMEM;
}
*ptr = p;
return 0;
}
#endif
六、项目编译
pip install .
按上述步骤编译就能成功
七、测试
1、修改test_stream.py,如下两个地方,注意视频文件需要复制到测试目录
2、启动 SRS
在windows桌面中点击如下图标即可
3、运行 test_stream.py
python test_stream.py
大功告成!!!
相关推荐
- redis的八种使用场景
-
前言:redis是我们工作开发中,经常要打交道的,下面对redis的使用场景做总结介绍也是对redis举报的功能做梳理。缓存Redis最常见的用途是作为缓存,用于加速应用程序的响应速度。...
- 基于Redis的3种分布式ID生成策略
-
在分布式系统设计中,全局唯一ID是一个基础而关键的组件。随着业务规模扩大和系统架构向微服务演进,传统的单机自增ID已无法满足需求。高并发、高可用的分布式ID生成方案成为构建可靠分布式系统的必要条件。R...
- 基于OpenWrt系统路由器的模式切换与网页设计
-
摘要:目前商用WiFi路由器已应用到多个领域,商家通过给用户提供一个稳定免费WiFi热点达到吸引客户、提升服务的目标。传统路由器自带的Luci界面提供了工厂模式的Web界面,用户可通过该界面配置路...
- 这篇文章教你看明白 nginx-ingress 控制器
-
主机nginx一般nginx做主机反向代理(网关)有以下配置...
- 如何用redis实现注册中心
-
一句话总结使用Redis实现注册中心:服务注册...
- 爱可可老师24小时热门分享(2020.5.10)
-
No1.看自己以前写的代码是种什么体验?No2.DooM-chip!国外网友SylvainLefebvre自制的无CPU、无操作码、无指令计数器...No3.我认为CS学位可以更好,如...
- Apportable:拯救程序员,IOS一秒变安卓
-
摘要:还在为了跨平台使用cocos2d-x吗,拯救objc程序员的奇葩来了,ApportableSDK:FreeAndroidsupportforcocos2d-iPhone。App...
- JAVA实现超买超卖方案汇总,那个最适合你,一篇文章彻底讲透
-
以下是几种Java实现超买超卖问题的核心解决方案及代码示例,针对高并发场景下的库存扣减问题:方案一:Redis原子操作+Lua脚本(推荐)//使用Redis+Lua保证原子性publicbo...
- 3月26日更新 快速施法自动施法可独立设置
-
2016年3月26日DOTA2有一个79.6MB的更新主要是针对自动施法和快速施法的调整本来内容不多不少朋友都有自动施法和快速施法的困扰英文更新日志一些视觉BUG修复就不翻译了主要翻译自动施...
- Redis 是如何提供服务的
-
在刚刚接触Redis的时候,最想要知道的是一个’setnameJhon’命令到达Redis服务器的时候,它是如何返回’OK’的?里面命令处理的流程如何,具体细节怎么样?你一定有问过自己...
- lua _G、_VERSION使用
-
到这里我们已经把lua基础库中的函数介绍完了,除了函数外基础库中还有两个常量,一个是_G,另一个是_VERSION。_G是基础库本身,指向自己,这个变量很有意思,可以无限引用自己,最后得到的还是自己,...
- China's top diplomat to chair third China-Pacific Island countries foreign ministers' meeting
-
BEIJING,May21(Xinhua)--ChineseForeignMinisterWangYi,alsoamemberofthePoliticalBureau...
- 移动工作交流工具Lua推出Insights数据分析产品
-
Lua是一个适用于各种职业人士的移动交流平台,它在今天推出了一项叫做Insights的全新功能。Insights是一个数据平台,客户可以在上面实时看到员工之间的交流情况,并分析这些情况对公司发展的影响...
- Redis 7新武器:用Redis Stack实现向量搜索的极限压测
-
当传统关系型数据库还在为向量相似度搜索的性能挣扎时,Redis7的RedisStack...
- Nginx/OpenResty详解,Nginx Lua编程,重定向与内部子请求
-
重定向与内部子请求Nginx的rewrite指令不仅可以在Nginx内部的server、location之间进行跳转,还可以进行外部链接的重定向。通过ngx_lua模块的Lua函数除了能实现Nginx...
- 一周热门
-
-
C# 13 和 .NET 9 全知道 :13 使用 ASP.NET Core 构建网站 (1)
-
因果推断Matching方式实现代码 因果推断模型
-
git pull命令使用实例 git pull--rebase
-
git pull 和git fetch 命令分别有什么作用?二者有什么区别?
-
面试官:git pull是哪两个指令的组合?
-
git 执行pull错误如何撤销 git pull fail
-
git fetch 和git pull 的异同 git中fetch和pull的区别
-
git pull 之后本地代码被覆盖 解决方案
-
还可以这样玩?Git基本原理及各种骚操作,涨知识了
-
git命令之pull git.pull
-
- 最近发表
- 标签列表
-
- git pull (33)
- git fetch (35)
- mysql insert (35)
- mysql distinct (37)
- concat_ws (36)
- java continue (36)
- jenkins官网 (37)
- mysql 子查询 (37)
- python元组 (33)
- mybatis 分页 (35)
- vba split (37)
- redis watch (34)
- python list sort (37)
- nvarchar2 (34)
- mysql not null (36)
- hmset (35)
- python telnet (35)
- python readlines() 方法 (36)
- munmap (35)
- docker network create (35)
- redis 集合 (37)
- python sftp (37)
- setpriority (34)
- c语言 switch (34)
- git commit (34)