Nginx+rtmp模块实现直播推流

服务器环境:CentOS8+宝塔7.5.1
服务器配置: 1C 1G [email protected] 腾讯云轻量应用服务器东京地区(联通电信NTT 移动KDDI)
Step 1 安装宝塔
安装过程就不细讲了,如果需要跳登录可以参考这里→https://lty.pw/bt_skip_login
Step 2 配置Nginx环境及安装Nginx
SSH中输入以下命令,配置环境
yum install -y gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* autoconf git
然后我们把模块下载到服务器
cd /www/server
git clone https://github.com/arut/nginx-rtmp-module.git
进入面板,点击软件商店,安装Nginx,选择编译安装,出现”nginx.sh”saved字样后停止安装


然后修改宝塔的Nginx安装脚本
vi /www/server/panel/install/nginx.sh
在下图所示处(200行左右)加入--add-module=/www/server/nginx-rtmp-module 记得前后都要有空格

给修改完的脚本上个权限 chmod +x /www/server/panel/install/nginx.sh
安装Nginx /www/server/panel/install/nginx.sh install 1.18
建议安装的时候挂个screen 网络波动可能会导致掉线
安装完以后进入宝塔,按照正常流程创建一个网站,记住这里的根目录,然后进入根目录,创建一个名字叫live的文件夹,记住路径
编辑nginx文件,在下图所示处加入,编辑完毕后记得重启Nginx服务

rtmp {

server {

listen 6666; #监听的端口,随意更换,更换后记得方形对应端口

chunk_size 4000;

application hls {
live on;
hls on;
hls_path /www/wwwroot/XXXXX; #这里是live文件夹路径
hls_fragment 5s;
}
}
}
然后在腾讯云防火墙放行刚才的端口 TCP

推流服务到这里就搭建好了,推流地址rtmp://服务器地址:服务器端口/hls
观看地址: http://域名/live/推流密钥.m3u8 (推流密钥在推流客户端设置)
这里用OBS来试一下推流效果
OBS端:

客户端:(浏览器就行 不支持的可以参考套个播放器)

注:视频推流服务 本地上行带宽及服务器上行带宽越大越好 延迟越低越好(推荐腾讯云香港 带宽大 延迟低)

点赞
  1. 九命猫king说道:
    Google Chrome Windows 10
    [[email protected] ~]# yum install -y gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* autoconf git Repository epel is listed more than once in the configuration 上次元数据过期检查:0:00:57 前,执行于 2021年03月08日 星期一 16时40分35秒。 Package ncurses-6.1-7.20180224.el8.x86_64 is already installed. Package ncurses-devel-6.1-7.20180224.el8.x86_64 is already installed. Package make-1:4.2.1-9.el8.x86_64 is already installed. Package openssl-1:1.1.1g-12.el8_3.x86_64 is already installed. Package openssl-devel-1:1.1.1g-12.el8_3.x86_64 is already installed. Package gcc-8.2.1-3.5.el8.x86_64 is already installed. Package libxml2-2.9.7-8.el8.x86_64 is already installed. Package libxml2-devel-2.9.7-8.el8.x86_64 is already installed. Package libcurl-devel-7.61.1-14.el8_3.1.x86_64 is already installed. Package libjpeg-turbo-1.5.3-10.el8.x86_64 is already installed. Package libjpeg-turbo-devel-1.5.3-10.el8.x86_64 is already installed. Package libpng-2:1.6.34-5.el8.x86_64 is already installed. Package libpng-devel-2:1.6.34-5.el8.x86_64 is already installed. Package freetype-2.9.1-4.el8_3.1.x86_64 is already installed. Package freetype-devel-2.9.1-4.el8_3.1.x86_64 is already installed. 错误: 问题: conflicting requests - nothing provides gcc-toolset-10-perftools needed by gcc-toolset-10-10.0-0.el8.x86_64 - nothing provides gcc-toolset-10-toolchain needed by gcc-toolset-10-10.0-0.el8.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages) [[email protected] ~]# 咋回事,这是
    1. LittleBlueCat LittleBlueCat说道:
      Google Chrome Windows 10
      这几天有点忙才看见 我没报过这个错误 感觉是源的问题

发表评论

电子邮件地址不会被公开。必填项已用 * 标注