搭建基于nginx的rtmp直播服务器

LiveServer1年前 (2024-11-05)教程文章

视频教程

https://www.bilibili.com/video/av78957794
OBS录屏推流教程:https://www.bilibili.com/video/av78808759

搭建nginx + nginx-rtmp-module
演示的系统使用CentOS-7-x86_64-Everything-1611.iso

关闭防火墙

请根据实际情况调整防火墙。为了演示方便,博主关闭防火墙。
临时停止

systemctl stop firewalld

禁用

systemctl disable firewalld

查看状态

systemctl status firewalld

安装wget

yum -y install wget

安装 gcc gcc-c++

yum -y install gcc gcc-c++

安装PCRE库

cd /usr/local/
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gztar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install

安装openssl

cd /usr/local/ 
wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz tar -zxvf openssl-1.0.1j.tar.gz 
cd openssl-1.0.1j
./config
make && make install

nginxrtmp2.jpg
如果提示You need Perl 5,则输入下面这个命令。

yum -y install Perl 5

安装zlib

cd /usr/local/
wget http://zlib.net/zlib-1.2.11.tar.gztar -zxvf zlib-1.2.11.tar.gz
./configure
make && make install

git clone

cd /usr/local/
yum -y install git
git clone https://github.com/arut/nginx-rtmp-module.git

安装nginx

cd /usr/local/
wget http://nginx.org/download/nginx-1.8.0.tar.gztar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module  --add-module=../nginx-rtmp-module  --with-openssl=<path> --with-http_ssl_module
make && make install

如果提示

./configure: error: SSL modules require the OpenSSL library.

执行

yum -y install openssl openssl-devel

如果提示

 ./configure: error: the HTTP rewrite module requires the PCRE library.

执行

yum -y install pcre-devel

我下载并安装了pcre-8.33.tar.gz 和 openssl-1.0.1j.tar.gz ,并没有出现上面的错误

nginx相关命令

启动

/usr/local/src/nginx/sbin/nginx

重启

/usr/local/src/nginx/sbin/nginx –s reload

启动后,打开浏览器,输入服务器ip地址,访问显示如下页面,则表示成功安装。
nginxrtmp3.jpg

修改conf

nginxrtmp4.jpg
使用winscp前往/usr/local/src/nginx/conf/nginx.conf
在http{前加入

rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
application yuchen {#rtmp推流请求路径 (切记路径错了会推不上流)
live on; #开启实时
hls on; #开启hls
hls_path /usr/local/src/nginx/html/yuchen; #rtmp推流请求路径,文件存放路径
hls_fragment 5s; #每个TS文件包含5秒的视频内容
}
}
}

修改完成后,使用命令重启nginx

/usr/local/src/nginx/sbin/nginx –s reload

推拉流

打开obs推流,右下角变为绿色方块则推流成功。
nginxrtmp5.jpg

在potplayer中播放http的m3u8地址。或者是使用支持rtmp协议的播放器拉流。


相关文章

Windows Nginx+RTMP流媒体服务器搭建以及测试

Windows Nginx+RTMP流媒体服务器搭建以及测试

RTMP是Real Time Messaging Protocol(实时消息传输协议)的缩写。基于TCP,是一种用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒...

Windows本地搭建rtmp推流服务

Windows本地搭建rtmp推流服务

前言开发时偶尔需要使用rtmp直播流做视频流测试,苦于网上开源的rtmp视频流都已经失效,无奈只好尝试在本地自己搭建一个rtmp的推流服务,方便测试使用一、工具准备Nginx:使用nginx-rtmp...

从零开始搭建自己的RTSP/RTMP视频服务器

从零开始搭建自己的RTSP/RTMP视频服务器

搭建RTSP视频服务器成为必要选择,特别是在处理移动端或边缘设备的视频数据时。通过此服务器,实现将采集的视频数据回传至服务端,为算法分析提供更强支持。这种架构提升了算法的实时性和准确性,同时中心化管理...

RTMP 在直播场景的应用与动手实践

RTMP 在直播场景的应用与动手实践

RTMP (Real Time Messaging Protocol)简介RTMP(Real Time Messaging Protocol)是一种设计用于实时数据通信的网络协议,主要用于在 Flas...

Nginx 自建RTMP服务 对海康 大华 直播推流

Nginx 自建RTMP服务 对海康 大华 直播推流

在前面的文章中,我们讲到了利用EasyDarwin搭建直播推流。虽然提供了可视化界面,便于统一管理等优势。但是也存在很多不足。如部分摄像头推流不支持密匙,这时我们便需要自己动手搭建推流服务器了。实验环...

海康 大华 监控设备RTMP实时推流直播

海康 大华 监控设备RTMP实时推流直播

笔者最近的业务中,需要将机房的摄像头的图像在大屏或者html页面展示出来。本文以大华摄像头为例,介绍具体的做法。使用场景设备清单大华摄像头(P20A2-WT)但笔者还是推荐海康。本地同机房主机(Lin...