当前位置:首页 > 技术分析 > 正文内容

windows 下编译 python_rtmpstream

ruisui884个月前 (02-03)技术分析26

最近在研究数字人,看了大咖的项目(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


大功告成!!!

扫描二维码推送至手机访问。

版权声明:本文由ruisui88发布,如需转载请注明出处。

本文链接:http://www.ruisui88.com/post/744.html

标签: spec.ts
分享给朋友:

“windows 下编译 python_rtmpstream” 的相关文章

VIM配置整理

一、基本配色set number set showcmd set incsearch set expandtab set showcmd set history=400 set autoread set ffs=unix,mac,dos set hlsearch set shiftwidth=2 s...

「云原生」Containerd ctr,crictl 和 nerdctl 命令介绍与实战操作

一、概述作为接替Docker运行时的Containerd在早在Kubernetes1.7时就能直接与Kubelet集成使用,只是大部分时候我们因熟悉Docker,在部署集群时采用了默认的dockershim。在V1.24起的版本的kubelet就彻底移除了dockershim,改为默认使用Conta...

15款测试html5响应式的在线工具

手机、平板灯手持设备的增多,网站要顺应变化,就必须要做响应式开发,响应式网站最大的特点在于可以在不同设备下呈现不同的布局,是基于html5+css3技术,目前越来越多的网站开始采用了响应式设计,而下面15款工具可以方便测试你的html5响应式效果。Responsinatorhttp://www.re...

再来一波黑科技工具,低调使用

静读天下静读天下是一个特别优秀的电子书阅读器。它上面有多个在线书库,像古登堡计划,很多种优秀的书杂志,都可以下载来阅读。它还能智能识别章节功能,还支持外置的语音阅读功能。它支持多种文本格式,比如说txt,pdf,epub,mobi等等。为了便于阅读它还有10 种配色方式,还有夜间模式。不过免费版有广...

Vue真是太好了 壹万多字的Vue知识点 超详细!

1??、Vue和其他两大框架的区别Angular 学习成本太高React 代码可读性差Vue 学习成本较低 很容易上手VUE官方: https://cn.vuejs.org/v2/guide/comparison.html?2??、Vue是什么Vue是一套用于构建用户界面的渐进式框架 "前端...

vue 异步更新那点事儿 #web前端

异步更新那点事儿。wue & vueuse官方团队成员。看一下群友投稿的问题。什么问题?就是它这边有一个组件,这个组件里面有个userID,然后这个userID通过props传给了子组件,子组件是userinfo,它里面是用来渲染用户信息的。渲染用户信息的同时,userinfo这个组件又暴露...