armlinux 搭建nginx + rtmp服务器

1综合篇点我
2uboot移植点我
3uboot lcd驱动点我
4kernel移植点我
5kernel lcd驱动点我
6摄像头驱动点我
7ubuntu base移植点我
8挂载网络文件系统点我
9qt移植点我
10搭建qt交叉编译点我
11wifi移植点我
12搭建nginx + rtmp服务器点我

常见的视频监控和视频直播就是使用 RTMP 和 RTSP 流媒体协议等。
RTSP (Real-Time Stream Protocol)由 Real Networks 和 Netscape 共同提出的,基于文本的多媒体播放控制协议。 RTSP 定义流格式,流数据经由 RTP 传输; RTSP 实时效果非常好,适合视频聊天,视频监控等方向。
RTMP(Real Time Message Protocol) 由 Adobe 公司提出,用来解决多媒体数据传输流的
多路复用(Multiplexing)和分包(packetizing)的问题,优势在于低延迟,稳定性高,支持所有摄像头格式,浏览器加载 flash 插件就可以直接播放。
RTSP 和 RTMP 的区别:
RTSP 虽然实时性最好,但是实现复杂,适合视频聊天和视频监控; RTMP 强在浏览器支持好,加载 flash 插件后就能直接播放,所以非常火,相反在浏览器里播放 rtsp 就很困难了。
本文使用RTMP的方式实现视屏监控

1 准备工作

  1. 下载nginx源码:wget http://nginx.org/download/nginx-1.20.2.tar.gz
  2. 下载依赖库libpcre.a源码:wget http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-8.39.tar.gz
  3. 下载依赖库libz.a源码: wget https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
  4. 下载rtmp模块源码:GitHub - arut/nginx-rtmp-module: NGINX-based Media Streaming Server
    前三个库源码下载完成后,都进行解压。

2 编译

pcre库和libz库都不用单独编译,在编译nginx时添加模块时一起编译。

2.1 编译nginx-1.20.2

进入nginx-1.20.2

song@song-machine:/home/work/third-party$ cd nginx-1.20.2/

创建安装目录

sudo mkdir arm-nginx

配置

./configure --with-cc=arm-linux-gnueabihf-gcc --with-cpp=arm-linux-gnueabihf-g++ --prefix=/opt/arm-nginx --add-module=/home/work/third-party/nginx-rtmp-module-master --with-http_ssl_module --with-debug --with-pcre=/home/work/third-party/pcre-8.39 --with-zlib=/home/work/third-party/zlib-1.2.11 --with-openssl=/home/work/third-party/openssl-1.1.1d --without-http_upstream_zone_module --without-stream_upstream_zone_module

// --prefix=/opt/arm-nginx  指定安装目录,最后install时生成的程序放在这个目录下,要和开发存放的路径相同
// --add-module=/home/work/third-party/nginx-rtmp-module-master  编译rtmp模块,这个目录是上面下载源码后解压的目录
// --with-pcre=/home/work/third-party/pcre-8.39 编译pcre模块,这个目录是上面下载源码后解压的目录
// --with-zlib=/home/work/third-party/zlib-1.2.11 编译zlib模块,这个目录是上面下载源码后解压的目录
// --with-openssl=/home/work/third-party/openssl-1.1.1d 编译opessl模块

在这里插入图片描述
解决办法:

gedit auto/cc/name

ngx_feature_run=yes

改为

ngx_feature_run=no

重新执行

./configure --with-cc=arm-linux-gnueabihf-gcc --with-cpp=arm-linux-gnueabihf-g++ --prefix=/opt/arm-nginx --add-module=/home/work/third-party/nginx-rtmp-module-master --with-http_ssl_module --with-debug --with-pcre=/home/work/third-party/pcre-8.39 --with-zlib=/home/work/third-party/zlib-1.2.11 --with-openssl=/home/work/third-party/openssl-1.1.1d --without-http_upstream_zone_module --without-stream_upstream_zone_module

在这里插入图片描述
解决办法:

gedit auto/types/sizeof

(1)ngx_test="$CC 改为 ngx_test="gcc

(2)ngx_size=$NGX_AUTOTEST 改为 ngx_size=4

重新执行

./configure --with-cc=arm-linux-gnueabihf-gcc --with-cpp=arm-linux-gnueabihf-g++ --prefix=/opt/arm-nginx --add-module=/home/work/third-party/nginx-rtmp-module-master --with-http_ssl_module --with-debug --with-pcre=/home/work/third-party/pcre-8.39 --with-zlib=/home/work/third-party/zlib-1.2.11 --with-openssl=/home/work/third-party/openssl-1.1.1d --without-http_upstream_zone_module --without-stream_upstream_zone_module

编译

sudo make

在这里插入图片描述
解决办法:
打开options

gedit auto/options

PCRE_CONF_OPT

修改为

PCRE_CONF_OPT=--host=arm-linux-gnueabihf-gcc //修改为自己的工具链

报错
在这里插入图片描述
解决办法:

gedit auto/lib/openssl/make

&& ./config --prefix=$ngx_prefix no-shared no-threads $OPENSSL_OPT

改为

&& ./Configure --prefix=$ngx_prefix no-shared no-threads --cross-compile-prefix=arm-linux-gnueabihf- linux-generic32 \\

注意将./config改为./Configure
在这里插入图片描述

gedit objs/ngx_auto_config.h
添加

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

安装

sudo make build

安装结果
在这里插入图片描述

3 拷贝到armlinux的网络文件系统中

sudo cp /opt/arm-nginx/ ../../imx6ull/rootfs/ubuntu-base-armhf/opt/ -r

将nginx添加到环境变量中

vim /etc/profile

添加

export PATH=$PATH:/opt/arm-nginx/sbin

重新加载环境变量

source /etc/profile

4 运行nginx

直接执行nginx命令
在这里插入图片描述
查看本地ip
在这里插入图片描述

可以看到开发板wifi的ip是192.168.0.100
在win10 浏览器输入192.168.0.100:80
出现下面结果代表移植成功
在这里插入图片描述

5 添加rtmp配置

将下面内容添加到/opt/arm-nginx/conf/nginx.conf中

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

在这里插入图片描述

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值