CentOS 搭建 RTMP直播服务器
创始人
2024-09-25 05:46:01
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

相关内容

热门资讯

IA解析/牛牛房卡怎么获得茄子... 今 日消息,茄子娱乐房卡添加微信33549083 苹果今日发布了 iOS 16.1 正式版更新,简单...
推荐一款!牛牛房卡制作链接新九... 新九天大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:33290...
头条推荐!金花房卡代理零售新神... 您好!微信新神兽/青龙大厅大厅链接获取房卡可以通过以下几种方式购买: 1.微信渠道:(新神兽/青龙...
科技实测!牛牛房卡代理九九大厅... 九九大厅房卡更多详情添加微:33549083、 2、在商城页面中选择房卡选项。 3、根...
安卓系统功能可以添加吗,解锁无... 你有没有想过,你的安卓手机里那些功能是不是可以像变魔术一样,随心所欲地添加新的呢?没错,今天就来聊聊...
我来教你/牛牛房卡怎么获得乐乐... 微信游戏中心:乐乐大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
IA解析/牛牛房卡游戏平台加盟... 您好!微信精卫大厅大厅链接获取房卡可以通过以下几种方式购买: 1.微信渠道:(精卫大厅)大厅介绍:...
一分钟了解!牛牛房卡批发平台火... 今 日消息,火狐大厅/新超圣房卡添加微信33549083 苹果今日发布了 iOS 16.1 正式版更...
正版授权!金花微信链接市场价格... 天启联盟房卡更多详情添加微:33549083、 2、在商城页面中选择房卡选项。 3、根...
推荐一款!金花房卡出售新道游/... 推荐一款!金花房卡出售新道游/新皇豪/房卡客服新道游/新皇豪是一款非常受欢迎的游戏,咨询房/卡添加微...
我来教你/牛牛房卡制作链接神盾... 神盾大厅/新天道是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:33...
IA解析/金花房卡出售青鸟大厅... 微信游戏中心:青鸟大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
玩家攻略,怎么买斗牛房卡星空乐... 星空乐娱是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...
重大通报,微信金花房卡怎么弄九... 今 日消息,九哥联盟房卡添加微信33549083 苹果今日发布了 iOS 16.1 正式版更新,简单...
我来教你/金花房卡怎么购买荣耀... 荣耀乐娱房卡更多详情添加微:33549083、 2、在商城页面中选择房卡选项。 3、根...
ia攻略/牛牛房卡怎么购买天蝎... ia攻略/牛牛房卡怎么购买天蝎大厅/微信链接房卡价格一览表天蝎大厅是一款非常受欢迎的游戏,咨询房/卡...
重大通报,金花微信链接市场价格... 微信游戏中心:海航大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
正版授权!金花房卡专卖店老神兽... 老神兽/海贝大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:33...
重大通报,金花房卡怎么购买新八... 今 日消息,新八戒房卡添加微信33549083 苹果今日发布了 iOS 16.1 正式版更新,简单介...
玩家攻略,金花房卡官网生肖系列... 玩家攻略,金花房卡官网生肖系列/新大圣/房卡链接怎么弄的生肖系列/新大圣是一款非常受欢迎的游戏,咨询...