nginx+rtmp实现直播服务端
目前直播系统从功能上分为两种,直播和互动。普通直播对播放延迟要求不高,推流端也能设置本地延迟推流时间。互动直播对低延时要求较高,主要应用在即时通讯和在线教育等行业,从推流端采集到拉流端播放一般延时不超过500ms,更高的延迟会让人感觉到明显的不适。今天开始搭建我的第一个互动直播系统,首先实现推拉流和服务器的流中转,有了基本环境研究推流降低延迟,比如编码,rtmp换udp,延迟足够低后对服务端进行优化。
1. 准备服务器
租了一台阿里云ecs,2核8G,公网1M带宽,足够测试使用。
打开安全组设置,在入口方向开放1935端口,1935端口是rtmp默认监听端口,必须在这里设置开放,否则在服务器中打开和监听1935端口后公网环境连接不到该端口。
2. 服务端nginx+rtmp环境
1. 安装nginx相关依赖包
yum -y install pcre-devel openssl openssl-devel
2. 创建工作目录,下载nginx和nginx-rtmp-module源码
mkdir work
cd work
wget http://nginx.org/download/nginx-1.10.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
3. 安装zip,解压源码
yum -y install unzip
tar -zxvf nginx-1.7.5.tar.gz
unzip master.zip
4. 配置,编译安装nginx
cd nginx-1.10.0
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
make install
5. 查看nginx安装信息
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -V
6. 启动,测试nginx
nginx -s stop
nginx
win10打开telnet测试,应用->程序和功能->启用或关闭windows功能:
telnet ip 端口,发现连接不上。关闭contos防火墙:
systemctl stop firewalld
nginx -s reload
再次测试,连接成功:
7. 配置rtmp服务相关
vi /usr/local/nginx/conf/nginx.conf
PS:注意是在http{}外进行添加:
rtmp {server {listen 1935;chunk_size 4096;application live {live on;record off;}}
}
完整的配置如下:
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /usr/local/nginx/hls/;}location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}rtmp {server {listen 1935;chunk_size 4096;application live {live on;record off;}}
}
把nginx-rtmp-module文件夹中的stat.xsl复制到/usr/lcoal/nginx/hls/文件夹中
监控地址:http://39.105.161.30/stat
重启nginx。
3. 推拉流测试
1. obs studio推流,设置推流地址:
点击开始推流,如果按钮显示为停止推流,则推流成功,也可在http://39.105.161.30/stat 进行监控
2. vlc播放器拉流
至此服务端和推拉流测试完成。
nginx+rtmp实现直播服务端相关推荐
- linux搭建直播步骤,Linux 下 nginx + rtmp 搭建直播服务
简单粗暴直接上步骤吧: 注 : 以下示例使用的是nginx(版本1.15.3) rtmp(版本1.2.1) 下载nginx和rtmp模块 下载nginx 解压 tar xvf nginx-1.15 ...
- Windows远程桌面实现之十一:桌面屏幕通过各种直播服务端直播(RTSP, RTMP, HTTP-FLV, HLS)
by fanxiushu 2020-01-23 转载或引用请注明原始作者. 此文还是基于xdisp_virt远程项目中的一个子功能.在把xdisp_virt移植到各种平台之后,就想着再做点什么新功能, ...
- Qt显示视频流——nginx+rtmp搭建直播服务器(二)
上次介绍的是使用ffmpeg推流,这次介绍的是使用nginx + rtmp搭建直播服务器. 环境:ubuntu 16.04 一. 安装nginx 和 rtmp模块 1. 下载安装 nginx 和 ng ...
- uniapp+nginx+rtmp开发直播app(1)
uniapp+nginx+rtmp开发直播app(1) 文章目录 uniapp+nginx+rtmp开发直播app(1) 前言 一.准备工作 1. 服务器环境搭建: Ubuntu + nginx + ...
- 基于Flask+Nginx+uWSGI实现CentOS服务端模型部署及预加载
基于Flask+Nginx+uWSGI实现CentOS服务端模型部署及预加载http://www.manongjc.com/article/37802.html
- linux nginx rtmp 死机,nginx rtmp 实时直播视频流 发布者网络不稳定导致无法直播问题...
nginx rtmp 实时直播视频流 发布者网络不稳定导致无法直播问题 直播项目使用nginx搭配rtmp扩展实现实时音视频流,最近一次直播讲师在外出差,使用酒店WiFi网络,苹果笔记本,Safari ...
- LiveQing视频点播RTMP推流直播服务支持H5无插件WebRTC超低延时视频直播
LiveQing视频点播RTMP推流直播服务支持H5无插件WebRTC超低延时视频直播 1.WebRTC超低延时视频直播 2.WebRTC延时对比 3.LiveQing播放WebRTC流 4.分屏页面 ...
- html5直播服务端搭建,直播推流服务器端搭建
环境准备 下载Nginx wget http://nginx.org/download/nginx-1.16.0.tar.gz 解压Nginx tar -zxvf nginx-1.16.0.tar.g ...
- 基于Nginx模块搭建直播服务
转载请标明出处: https://blog.csdn.net/u014214308/article/details/82698542 直播技术原理: 客户端(A:主播,推流)通过摄像头采集到视频数据, ...
最新文章
- 【原创】sharepoint webpart COPY部署的办法
- Windows 中的环境变量 Path 与 XXXX_HOME 的区别
- window 下 Atom 侧边栏字体大小设置
- 【转】c# 协变与抗变
- SpringBoot入门到精通_第5篇 _SpringBoot Actuator监控
- 时点数列序时平均数_时点数列序时平均数计算方法研究
- 没有web.xml如何使用 Maven打war包?
- 问题四十三:对ray tracing圆环图形中的细微问题进行修正
- 2019牛客多校第三场F Planting Trees(单调队列)题解
- 阶段3 1.Mybatis_12.Mybatis注解开发_3 mybatis注解开发保存和更新功能
- java 8 sdk官方下载_Java SDK下载方法
- 如何设计艺术字体,可以从这两个方面入手
- C#制作KTV点歌系统
- 二进制逆向实验——寻找flag
- 敏捷开发“松结对编程”实践之三:共同估算篇(大型研发团队,学习型团队,139团队,师徒制度,敏捷设计,估算扑克,扑克牌估算) .
- PHP教程:PHP开发快速入门_v20200418
- 开发者出海跨境收款——如何完美解决限额问题?
- (基础)详解Python实现图像分割增强的两种方法
- 生死狙击逍遥工作室九天取密下载链接
- Jade学习中一些需要注意的地方
热门文章
- Salesforce Certified Community Cloud Consultant (SU20)社区云认证考试总结
- C++类与对象:程序片段编程题/汽车类的定义,拷贝构造函数,析构函数的定义
- 改注册表实现解禁部分系统功能
- 第五节 利用Ogre 2.3实现雨,雪,爆炸,飞机喷气尾焰等粒子效果
- 电波暗室里面的吸波材料有哪些?
- A股level2行情数据接口可以获取可转债数据吗?
- 绘声叙风电课堂 锐意做追风少年
- postgresql数据库手动备份脚本
- WACV 2021 论文大盘点-姿态估计篇
- 利用Xshell连接服务器导入web安装包并解压启动