2022
我们一起努力

vod服务器(技术分享|如何搭建直播场景下的推拉流媒体服务器)

介绍

本文使用的流媒体服务器的搭建是基于rtmp(Real Time Message Protocol)协议的,rtmp协议是应用层的协议,要依靠底层的传输层协议,比如tcp协议来保证信息传输的可靠性。

相关服务: Nginx、srs、MediaServer等三种推流服务

系统: CentOS Linux release 7.9.2009

推流工具:OBS 27.1.3

拉流工具:PotPlayer 1.7.21564

注意事项:由于内网测试 关闭防火墙与SElinux

Nginx部署

Nginx需要nginx-rtmp-module模块,yum安装没有此模块,所以本次使用源码安装

## 安装Nginx所需依赖[root@localhost ~]# yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel git## 下载所需安装包[root@localhost ~]# cd /home/artc[root@localhost artc]# mkdir Nginx #创建源码目录 后面的源码都放在这个目录[root@localhost artc]# cd Nginx[root@localhost Nginx]# git clone https://github.com/nginx/nginx.git #从github服务器上将nginx的源代码下载下来[root@localhost Nginx]# git clone https://github.com/arut/nginx-rtmp-module.git #将rtmp模块的源码下载下来

## 编译安装Nginx[root@localhost ~]# cd /home/artc/Nginx/nginx[root@localhost nginx]# ./auto/configure --prefix=/usr/local/nginx \ --with-http_v2_module \ --with-http_flv_module \ --with-http_mp4_module \ --add-module=../nginx-rtmp-module/[root@localhost nginx]# make && make install

## 更改配置文件[root@localhost nginx]# cd /usr/local/nginx/conf[root@localhost conf]# vim nginx.conf#在http模块外添加rtmp { server { listen 1915; timeout 20s; application live { live on; record off; }## 一个音视频模块 application anyrtc { live on; hls on; hls_path temp/zyh; hls_playlist_length 5s; hls_fragment 1s; } application vod { play /var/flvs; } application vod_http { play http://服务器IP/vod; }## 一个音视频模块 application hls { live on; hls on; record off; hls_path /tmp/hls; hls_playlist_length 5s; hls_fragment 1s; } }}## 启动Nginx[root@localhost nginx]# /usr/local/nginx/sbin/nginx

rtmp地址: rtmp://192.168.1.13:1915/anyrtc

OSB推流

确定———>开始推流

PotPlayer拉流

右键——>打开链接

拉取成功

SRS部署

下载地址:http://os.net/releases/download.html

## 安装依赖[root@localhost artc]# yum install -y redhat-lsb## 部署[root@localhost artc]# unzip SRS-CentOS7-x86_64-3.0.168[root@localhost artc]# cd SRS-CentOS7-x86_64-3.0.168/[root@localhost SRS-CentOS7-x86_64-3.0.168]# ./INSTALL [root@localhost SRS-CentOS7-x86_64-3.0.168]# systemctl start srs.service## 配置文件在/usr/local/srs[root@localhost SRS-CentOS7-x86_64-3.0.168]# cd /usr/local/srs/conf[root@localhost conf]# vim srs.conf# main config for srs.# @see full.conf for detail config.listen 1935; ##rtmp默认端口max_connections 1000;srs_log_tank file;srs_log_file ./objs/srs.log;daemon on;http_api { enabled on; listen 1985;}http_server { enabled on; listen 9090; ## srs管理平台端口 默认是8080 这里端口冲突改为9090 dir ./objs/nginx/html;}stats { network 0; disk sda sdb xvda xvdb;}vhost __defaultVhost__ { hls { enabled on; } http_remux { enabled on; mount [vhost]/[app]/[stream].flv; }}

rtmp地址: rtmp://192.168.1.13:1935

OSB推流

确定———>开始推流

PotPlayer拉流

vod服务器(技术分享|如何搭建直播场景下的推拉流媒体服务器)

右键——>打开链接

拉取成功

ZLMediaKit部署

下载地址: git clone –depth 1 https://gitee.com/xia-chu/ZLMediaKit

## 准备环境[root@localhost artc]# yum -y update## gcc和yasm需要高版本 小编用的是gcc4.8.5 yasm1.2.0[root@localhost artc]# yum -y update yasm gcc* [root@localhost artc]# yum -y install openssl-devel SDL-devel## 编译安装cmake 3.8.2[root@localhost ~]# cd /home/artc[root@localhost artc]# wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz[root@localhost artc]# tar zxvf cmake-3.8.2.tar.gz[root@localhost artc]# cd cmake-3.8.2[root@localhost cmake-3.8.2]# ./bootstrap[root@localhost cmake-3.8.2]# gmake[root@localhost cmake-3.8.2]# gmake install## 国内库比较快[root@localhost ~]# cd /home/artc [root@localhost artc]# git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit[root@localhost artc]# cd ZLMediaKit#千万不要忘记执行这句命令[root@localhost ZLMediaKit]# git submodule update --init## 编译安装[root@localhost ZLMediaKit]# mkdir build[root@localhost ZLMediaKit]# cmake .[root@localhost ZLMediaKit]# make -j4## ZLMediaKit服务目录[root@localhost ZLMediaKit]# cd release/linux/Debug## 配置文件[root@localhost Debug]# vim config.ini [rtmp] ##228行左右handshakeSecond=15keepAliveSecond=15modifyStamp=0port=1955 ## 默认1935 端口冲突 修改了1955sslport=0## 程序启动[root@localhost Debug]# ./MediaServer ## 前台启动[root@localhost Debug]# ./MediaServer -d & ## 后台启动## 软连接[root@localhost Debug]# ln -sf /home/ZLMediaKit/release/linux/Debug/MediaServer /usr/bin/

rtmp地址: rtmp://192.168.1.13:1955

OSB推流

确定———>开始推流

PotPlayer拉流

右键——>打开链接

拉取成功

rtsp推流地址: rtsp://192.168.1.13

ffmpeg推流

ffmpeg -re -i yace.mp4 -vcodec h264 -acodec aac -strict -2 -f rtsp -rtsp_transport tcp rtsp://192.168.1.13/anyrtc/ZLMediaKit

PotPlayer拉流

右键——>打开链接

拉取成功

赞(0)
文章名称:《vod服务器(技术分享|如何搭建直播场景下的推拉流媒体服务器)》
文章链接:https://www.fzvps.com/67350.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!