百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

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

off999 2025-02-13 13:53 30 浏览 0 评论

介绍

本文使用的流媒体服务器的搭建是基于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://ossrs.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拉流

右键——>打开链接

拉取成功

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=15
keepAliveSecond=15
modifyStamp=0
port=1955                   ## 默认1935   端口冲突 修改了1955
sslport=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拉流

右键——>打开链接

拉取成功

相关推荐

阿里云国际站ECS:阿里云ECS如何提高网站的访问速度?

TG:@yunlaoda360引言:速度即体验,速度即业务在当今数字化的世界中,网站的访问速度已成为决定用户体验、用户留存乃至业务转化率的关键因素。页面加载每延迟一秒,都可能导致用户流失和收入损失。对...

高流量大并发Linux TCP性能调优_linux 高并发网络编程

其实主要是手里面的跑openvpn服务器。因为并没有明文禁p2p(哎……想想那么多流量好像不跑点p2p也跑不完),所以造成有的时候如果有比较多人跑BT的话,会造成VPN速度急剧下降。本文所面对的情况为...

性能测试100集(12)性能指标资源使用率

在性能测试中,资源使用率是评估系统硬件效率的关键指标,主要包括以下四类:#性能测试##性能压测策略##软件测试#1.CPU使用率定义:CPU处理任务的时间占比,计算公式为1-空闲时间/总...

Linux 服务器常见的性能调优_linux高性能服务端编程

一、Linux服务器性能调优第一步——先搞懂“看什么”很多人刚接触Linux性能调优时,总想着直接改配置,其实第一步该是“看清楚问题”。就像医生看病要先听诊,调优前得先知道服务器“哪里...

Nginx性能优化实战:手把手教你提升10倍性能!

关注△mikechen△,十余年BAT架构经验倾囊相授!Nginx是大型架构而核心,下面我重点详解Nginx性能@mikechen文章来源:mikechen.cc1.worker_processe...

高并发场景下,Spring Cloud Gateway如何抗住百万QPS?

关注△mikechen△,十余年BAT架构经验倾囊相授!大家好,我是mikechen。高并发场景下网关作为流量的入口非常重要,下面我重点详解SpringCloudGateway如何抗住百万性能@m...

Kubernetes 高并发处理实战(可落地案例 + 源码)

目标场景:对外提供HTTPAPI的微服务在短时间内收到大量请求(例如每秒数千至数万RPS),要求系统可弹性扩容、限流降级、缓存减压、稳定运行并能自动恢复。总体思路(多层防护):边缘层:云LB...

高并发场景下,Nginx如何扛住千万级请求?

Nginx是大型架构的必备中间件,下面我重点详解Nginx如何实现高并发@mikechen文章来源:mikechen.cc事件驱动模型Nginx采用事件驱动模型,这是Nginx高并发性能的基石。传统...

Spring Boot+Vue全栈开发实战,中文版高清PDF资源

SpringBoot+Vue全栈开发实战,中文高清PDF资源,需要的可以私我:)SpringBoot致力于简化开发配置并为企业级开发提供一系列非业务性功能,而Vue则采用数据驱动视图的方式将程序...

Docker-基础操作_docker基础实战教程二

一、镜像1、从仓库获取镜像搜索镜像:dockersearchimage_name搜索结果过滤:是否官方:dockersearch--filter="is-offical=true...

你有空吗?跟我一起搭个服务器好不好?

来人人都是产品经理【起点学院】,BAT实战派产品总监手把手系统带你学产品、学运营。昨天闲的没事的时候,随手翻了翻写过的文章,发现一个很严重的问题。就是大多数时间我都在滔滔不绝的讲理论,却很少有涉及动手...

部署你自己的 SaaS_saas如何部署

部署你自己的VPNOpenVPN——功能齐全的开源VPN解决方案。(DigitalOcean教程)dockovpn.io—无状态OpenVPNdockerized服务器,不需要持久存储。...

Docker Compose_dockercompose安装

DockerCompose概述DockerCompose是一个用来定义和管理多容器应用的工具,通过一个docker-compose.yml文件,用YAML格式描述服务、网络、卷等内容,...

京东T7架构师推出的电子版SpringBoot,从构建小系统到架构大系统

前言:Java的各种开发框架发展了很多年,影响了一代又一代的程序员,现在无论是程序员,还是架构师,使用这些开发框架都面临着两方面的挑战。一方面是要快速开发出系统,这就要求使用的开发框架尽量简单,无论...

Kubernetes (k8s) 入门学习指南_k8s kubeproxy

Kubernetes(k8s)入门学习指南一、什么是Kubernetes?为什么需要它?Kubernetes(k8s)是一个开源的容器编排系统,用于自动化部署、扩展和管理容器化应用程序。它...

取消回复欢迎 发表评论: