基于hls的nginx流媒体处理的探索与实践

前言:
随着互联网的普及,网络带给人们形式多样的信,利用网络传输声音与视频信号的需求也越来越大。全球疫情催生了流媒体视频和线上游戏娱乐的需求,而随着5G、宽带、数字电视产业链的逐步形成与完善,三大产业对流媒体节目内容及制作、编解码技术的需求也到了迫不及待的阶段。流媒体的发展也到了一个全面繁荣的时期……

架构:
Nginx本身是一个非常出色的HTTP服务器,基于人的脸部特征信息进行身份识别的人脸识别技术.这两个东西通过一个nginx的模块nginx-rtmp-module,组合在一起即可以搭建一个功能相对比较完善的流媒体处理服务器。

这个流媒体服务器可以支持RTMP和HLS(Live Http Stream)

使用场景:
视频点播、视频会议、远程教育、远程医疗和在线直播系统。在视频直播、视频点播、直播时移、用户上传、离线转码、直播录制等众多功能模块,不同模块之间采用控制耦合和内容耦合,实现流媒体发服务器内核的统一与完整。

解决问题:
直播流格式不统一、对视频地址加密,防盗链、直播流的管理、组播地址转变为单播地址、高并发稳定性等

部署操作:

一、使用nginx新增nginx-rtmp-module模块

第一步:下载相应的安装报
1、首先就是先下载nginx-rtmp-module,官方github地址:https://github.com/arut/nginx-rtmp-module
在这里插入图片描述

到/opt/software目录下下载并解压

在这里插入图片描述
第二步:备份之前的文件
务必提前备份之前已经配置的nginx代理文件 ,然后下载与之前版本对应的nginx

查看当前已经安装的nginx版本信息命令:nginx -V

把******configure arguments******:后面的复制保存,一会编译使用

--prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

在这里插入图片描述

下载与上面版本一致的nginx源码,地址:http://nginx.org/en/download.html
在这里插入图片描述

到/opt/software目录下下载并解压
在这里插入图片描述
第三步:重新编译并添加nginx-rtmp-module模块
这一步一般用来生成 Makefile,在这里加了一个参数 --add-module=/nginx-rtmp-module 如果你有其他模块要一起安装,方法是一样的。

#nginx congigure
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --add-module=/opt/software/nginx-rtmp-module-master/

参数注释

  备注:
--prefix:Nginx安装目录
--user:Nginx用户
--group:Nginx用户所属组
--with-http_ssl_module:提供https支持
--with-http_flv_module:搭建flv视频服务器使用的
--with-http_stub_status_module:开启Stub Status模块,该模块会产生一个服务器状态和信息页
--with-http_gzip_static_module:开启Gzip静态模块,该模块用于发送预压缩文件
--with-pcre:perl执行文件路径

接下来就可以编译安装了
在这里插入图片描述
第四步:检验
在这里插入图片描述

二、HLS-搭建Nginx流媒体服务器

vi /usr/local/nginx/conf/nginx.conf
#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
    }
 
http {
        include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        # hls相关配置,hls支持以及状态监控页面
        location /stat {
           rtmp_stat all;
           rtmp_stat_stylesheet stat.xsl;
    }
         
        location /stat.xsl {
           root /usr/local/nginx/nginx-rtmp-module-master/;
    }
 
        location /hls {
           types {
               application/vnd.apple.mpegurl m3u8;
               video/mp2t ts;
           }
           alias /usr/local/nginx/www/hls/;
           expires -1;
           add_header Cache-Control no-cache;
           add_header Access-Control-Allow-Origin *;
        }
       #人脸识别视频中的截取的图片
        location /video/ {
           alias   /opt/s3fs/video/;
           autoindex on; # 索引
           autoindex_exact_size on; # 显示文件大小
           autoindex_localtime on; # 显示文件时间
          } 
    }
}
#添加RTMP的配置
rtmp {
    server {
        listen       1935;
        chunk_size   4096;
        # RTMP 直播流配置
        #application live {
        #    live on;
        #    max_connections 1024;
        #}
        # hls 直播流配置
        application hls {
            live on;
            hls on;
            hls_path /usr/local/nginx/www/hls;#视频流文件目录
            hls_fragment 10s;
            hls_continuous on;
            hls_cleanup off;
        }
    }
}

点播视频服务器RTMP的配置

rtmp {
    server {
        listen       1935;
        chunk_size   4096;
        # RTMP 直播流配置
        #application live {
        #    live on;
        #    max_connections 1024;
        #}
        # hls 直播流配置
        application hls {
            live on;
            hls on;
            hls_path /usr/local/nginx/www/hls;#视频流文件目录
            hls_fragment 10s;
            hls_continuous on;
            hls_cleanup off;
        }
    }
}
rtmp 是协议名称
server 说明内部中是服务器的相关配置
listen 监听的端口,rtmp协议的默认端口为1935
application 访问的应用路径是hls
live on 启用rtmp直播
record off 不记录数据
hls on 启用hls直播
hls_path 切片保存位置
hls_fragment 每个切片的长度
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值