CentOS 搭建 RTMP直播服务器
创始人
2024-09-25 05:19:34
0

nginx-rtmp-module 是一个用于 Nginx 的第三方模块,它扩展了 Nginx 服务器的功能,使其能够处理实时流媒体数据,特别是支持 RTMP (Real-Time Messaging Protocol) 协议。RTMP 是 Adobe Systems 开发的一种协议,常用于实时音视频通信,尤其是在直播场景中。

这里推荐另一种开源的直播系统owncast,网址: https://owncast.online/

一、安装Nginx

1、下载Nginx

cd /usr/local/src wget http://nginx.org/download/nginx-1.13.6.tar.gz

2、解压

tar -zxvf nginx-1.13.6.tar.gz

3、安装编译需要的工具

yum -y install gcc gcc-c++ openssl openssl-devel zlib zlib-devel pcre pcre-devel

4、编译Nginx

cd nginx-1.13.6  # 编译 ./configure --prefix=/usr/local/nginx \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_sub_module \ --with-http_gzip_static_module

5、安装

make && make install
二、安装Nginx RTMP模块 

1、下载

cd /usr/local/src wget https://github.com/arut/nginx-rtmp-module/archive/refs/tags/v1.2.2.tar.gz

2、解压

tar -zxvf v1.2.2.tar.gz

3、编译

cd nginx-1.13.6  # 编译 ./configure --add-module=/usr/local/src/nginx-rtmp-module-1.2.2 \ --with-http_ssl_module

4、安装

make && make install
三、配置

1、Nginx配置RTMP和HLS

vim /usr/local/nginx/conf/nginx.conf   # 修改如下  rtmp_auto_push on; rtmp {     server {         listen 1935;        # 监听端口 1935,用于 RTMP 数据流传输         chunk_size 4000;    # 数据传输分块大小           application live {             live on;            # 开启 RTMP 直播功能             hls on;             # 开启 HLS 功能             hls_fragment 2s;    # 每个 HLS 分片的时长为 2 秒。             hls_playlist_length 6s;                # HLS 播放列表长度为 6 秒             hls_path /usr/local/nginx/html/hls;    # HLS 分片文件存储路径           }     } }   worker_processes  1; events {     worker_connections  1024; }   http {     include       mime.types;     default_type  application/octet-stream;     sendfile        on;     keepalive_timeout  65;       server {         listen       80;         server_name  localhost;           location / {             root   html;             index  index.html index.htm;         } 		 		location /stat {             rtmp_stat all;             # Use this stylesheet to view XML as web page             # in browser             rtmp_stat_stylesheet stat.xsl;         }          location /stat.xsl {             # XML stylesheet to view RTMP stats.             # Copy stat.xsl wherever you want             # and put the full directory path here             root /usr/local/src/nginx-rtmp-module-1.2.2;         }           location /hls {             # Serve HLS fragments             types {                 application/vnd.apple.mpegurl m3u8;                 video/mp2t ts;             }             root /usr/local/nginx/html;             add_header Cache-Control no-cache;         }    } }

2、为Nginx配置启动

vim /lib/systemd/system/nginx.service  # 查看 [Unit] Description=nginx  After=network.target      [Service]  Type=forking  ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx reload ExecStop=/usr/local/nginx/sbin/nginx quit PrivateTmp=true      [Install]  WantedBy=multi-user.target

3、启动Nginx

systemctl start nginx
四、直播演示

1、用OBS推流,打开设置,直播

服务器:rtmp://ip:1935/live(live目录是Nginx中定义好的)

推流码:demo(自定义)

2、在OBS中添加采集来源,点击开启直播

3、客户端下载 VLC软件,拉流实现观看直播

下载地址:https://www.videolan.org/

打开虚拟机端 VLC 客户端,媒体 > 打开网络串流

(1)RTMP协议:rtmp://ip/live/demo

(2)HLS协议:http://ip/hls/demo.m3u8 

知识点:

  1. HLS可以在手机H5页面、微信公众号上播放,延迟10秒以上
  2. RTMP依赖Flash Player才能播放,延迟3秒左右

4、数据统计:ip://stat

相关内容

热门资讯

攻略辅助!德州私人局怎么透视,... 攻略辅助!德州私人局怎么透视,wejoker辅助软件视频,解迷教程(竟然有挂)该软件可以轻松地帮助玩...
必知教程!微乐小程序黑科技,7... 必知教程!微乐小程序黑科技,789大菠萝可以控制吗,积累教程(真的有挂)1、上手简单,内置详细流程视...
步骤辅助!竞技联盟破解版最新版... 步骤辅助!竞技联盟破解版最新版,hhpoker免费透视脚本,推荐教程(发现有挂)1、让任何用户在无需...
分享给玩家!创思维激k辅助工具... 分享给玩家!创思维激k辅助工具,约局吧辅助器,讲义教程(有挂总结)该软件可以轻松地帮助玩家将创思维激...
妙招辅助!德扑之心免费透视,w... 妙招辅助!德扑之心免费透视,wepoker怎么开辅助,辅助教程(有挂工具)1、玩家可以在德扑之心免费...
玩家必备教程!皮皮游戏辅助平台... 玩家必备教程!皮皮游戏辅助平台,朱雀开心罗松怎么开挂,资料教程(有挂透视)1、皮皮游戏辅助平台脚本辅...
总结辅助!hhpoker是正品... 总结辅助!hhpoker是正品吗,aapoker透视怎么用,解谜教程(有挂实锤)1)aapoker透...
今日重大通报!微信广东雀神挂件... 今日重大通报!微信广东雀神挂件辅助,随意玩辅助器,指南教程(有挂教学)1.微信广东雀神挂件辅助 选牌...
资料辅助!wepoker有辅助... 资料辅助!wepoker有辅助工具吗,wepoker软件安装包,教你教程(竟然有挂)小薇(辅助器软件...
实测分享!广西友乐免费辅助,新... 实测分享!广西友乐免费辅助,新荣耀辅助软件,指南书教程(有挂规律)1、玩家可以在广西友乐免费辅助透视...