Windows上nginx-openresty添加rtmp模块的方法

网上查找nginx-openresty添加rtmp模块的方法基本都是在Linux上的。但由于项目需要在Windows上使用nginx,无奈只好自己去找资料,在Windows上编译nginx-openresty同时加入rtmp模块。
一个基本的思路就是在Windows使用shell工具进行configure生成makefile然后使用mingw或cl进行编译生成。
其实openresty官方已经给出了在Windows编译生成的方法,我们只需要参考在Linux添加rtmp模块的方式,准备好nginx-rtmp-module源码,在configure时加入添加rtmp模块的语句即可。
一、准备相关文件
1、下载openresty的最新源码
在openresty官网就可以下载最新的源码。网址是https://openresty.org/en/download.html
2、下载nginx-rtmp-module源码
到github上找到nginx-rtmp-module并下载。网址是https://github.com/arut/nginx-rtmp-module
3、下载msys2
到msys2官网下载msys2的安装包。网址是https://www.msys2.org
4、下载依赖库
(1)打开openresty源码的目录,有个util文件夹,其下面的build-win32.sh,使用记事本打开就可以看到,依赖库如下:
PCRE=pcre-8.44
ZLIB=zlib-1.2.11
OPENSSL=openssl-1.1.1g
(2)有3个依赖库。接着下面还列出了依赖库的下载地址,依赖库如下(注意想要根据build-win32.sh中的地址下载,下面列出的是本文所用版本openresty-1.19.3.1的依赖库):
#wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
#wget http://zlib.net/zlib-1.2.11.tar.gz
#wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
(3)所以目前的版本需要:
①openssl-1.1.1g.tar.gz
②zlib-1.2.11.tar.gz
③pcre/pcre-8.44.tar.gz
5、下载依赖工具
下载strawberryperl安装包。网址是https://strawberryperl.com/
二、搭建编译环境
1、安装msys2
直接打开msys2安装包安装msys2。
2、设置包管理国内镜像
这一步不是必须的,不设置镜像只是后续操作下载速度会很慢。
(1)找到msys2的安装目录,继续转到etc\pacman.d目录下,用记事本打开下列文件:
①编辑mirrorlist.mingw32文件
首行添加:Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
②编辑mirrorlist.mingw64文件
首行添加:Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
③编辑mirrorlist.msys文件
首行添加:Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
(2)回到msys2的安装目录打开msys2.exe执行 pacman -Sy 刷新软件包数据。
3、安装mingw
在msys2的安装目录打开msys2.exe执行如下语句:
(1)编译64位安装
pacman -S mingw-w64-x86_64-toolchain
(2)编译32位安装
pacman -S mingw-w64-i686-toolchain
出现提示直接回车完整安装即可。
4、安装必要的工具
在msys2的安装目录打开msys2.exe执行如下语句:
(1)pacman -S make
(2)pacman -S patch
三、开始编译
1、放置源码
(1)将openresty源码解压放至msys2的安装目录下。
(2)将openssl-1.1.1g.tar.gz、zlib-1.2.11.tar.gz、pcre/pcre-8.44.tar.gz放至msys2的安装目录下。
(3)将nginx-rtmp-module源码解压放至msys2的安装目录下,文件夹名称为nginx-rtmp-module。
2、configure加入添加rtmp模块语句
使用记事本打开openresty源码目录下的utl文件夹中的build-win32.sh文件,在.configure的末尾加入–add-module=…/nginx-rtmp-module\。如下倒数第二行所示:

./configure \
    --with-cc=gcc \
    --with-ipv6 \
    --prefix= \
    --with-cc-opt='-DFD_SETSIZE=1024' \
    --sbin-path=nginx.exe \
    --with-pcre-jit \
    --without-http_rds_json_module \
    --without-http_rds_csv_module \
    --without-lua_rds_parser \
    --with-ipv6 \
    --with-stream \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module \
    --with-http_v2_module \
    --without-mail_pop3_module \
    --without-mail_imap_module \
    --without-mail_smtp_module \
    --with-http_stub_status_module \
    --with-http_realip_module \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_secure_link_module \
    --with-http_random_index_module \
    --with-http_gzip_static_module \
    --with-http_sub_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_gunzip_module \
    --with-select_module \
    --with-luajit-xcflags="-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT" \
    --with-pcre=objs/lib/$PCRE \
    --with-zlib=objs/lib/$ZLIB \
    --with-openssl=objs/lib/$OPENSSL \
    --add-module=../nginx-rtmp-module\
    -j$JOBS || exit 1

3、使用mingw编译
(1)在msys2的安装目录打开mingw64.exe或mingw32exe(需要编译64位打开前者,32位打开后者),cd到openresty源码目录,执行:
util/build-win32.sh
(2)等待生成成功
(3)编译失败
①编译nginx-rtmp-module时报错重定义int8_t
找到nginx-rtmp-module下的ngx_rtmp.h注释掉:typedef __int8 int8_t;回到(1)
四、打包
1、安装依赖工具
(1)安装下载好的strawberryperl安装包
(2)在msys2的安装目录打开mingw64.exe或mingw32exe(与三3(1)相同)执行:
①pacman -S dos2unix
②pacman -S zip
2、执行打包shell
在msys2的安装目录打开mingw64.exe或mingw32exe(与三3(1)相同),cd到openresty源码目录,执行:
util/package-win32.sh
执行完成后可以看到openresty源码目录下openrestyxxx-win64.zip或openrestyxxx-win32.zip文件,这就是最终打包的文件。
五、验证
1、添加rtmp配置
在生成的conf目录中打开nginx.conf,在底部添加:

rtmp {
    server {
        listen 1935;
        application live{
            live on;
        }
    }
}

2、推拉流测试
(1)使用ffmpeg.exe 输入命令:

ffmpeg -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv  rtmp://127.0.0.1/live/123

(2)使用ffplay.exe输入命令

ffplay rtmp://127.0.0.1/live/123 -x 640 -y 360

六、附录
1、openresty在Windows编译生成的官方说明
https://github.com/openresty/openresty/blob/master/doc/README-windows.md
2、添加rtmp模块的方法
https://github.com/arut/nginx-rtmp-module
七、附件
按上述步骤生成好的包
https://download.csdn.net/download/u013113678/32909871

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodeOfCC

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值