1.环境准备

Linux centos7.6
nginx-1.18.0 源码包
wget http://nginx.org/download/nginx-1.8.1.tar.gz
nginx-rtmp-module-master 模块包
https://github.com/arut/nginx-rtmp-module

1.1依赖环境安装

[root@imagesrs data]# yum install git gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel -y

2.源码包安装

2.1添加用户

[root@imagesrs data]# useradd -r -s /sbin/nologin nginx

2.2解压nginx-rtmp-module-master

[root@imagesrs nginx-1.18.0]# unzip nginx-rtmp-module-master.zip

2.3安装nginx

[root@imagesrs data]# tar -xvf nginx-1.18.0.tar.gz[root@imagesrs data]# cd nginx-1.18.0/[root@imagesrs data]# ./configure --prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_ssl_module \--add-module=/data/nginx-rtmp-module-master(模块源码包位置)创建软链接
[root@Centos7 sbin]# ln -s /usr/local/nginx/sbin/nginx  /usr/sbin/
[root@Centos7 sbin]# ls /usr/sbin/nginx 查看模块:
Nginx -V

2.4修改nginx 配置文件

[root@imagesrs conf]#cd /usr/local/nginx/conf
[root@imagesrs conf]# vim nginx.conf
user nginx;
worker_processes  1;
events {worker_connections  1024;
}
rtmp {server {listen 1935;   #端口号chunk_size 4000;application hls {live on;hls on;hls_path /usr/local/nginx/html/hls;   #切片存放位置hls_fragment 5s;      hls_playlist_length 15s;hls_continuous on; hls_cleanup on;hls_nested on;}}}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root   /usr/local/nginx/html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location /hls {types {application/vnd.apple.mpegurl m3u8;}alias /usr/local/nginx/html/hls;expires -1;add_header Cache-Control no-cache;}location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /usr/local/extend_module/nginx-rtmp-module/;}
}
}

启动nginx
[root@imagesrs conf]# nginx
重新加载:
[root@imagesrs conf]# nginx -s reload
检查配置文件:
[root@imagesrs conf]# nginx -t
查看端口号:
[root@imagesrs conf]#ss -ntl
端口号:1935   80



关于更多rtmp的参数可以参考:
https://github.com/arut/nginx-rtmp-module/wiki

3.直播服务器与推流、拉流操作

需要下载两个程序
拉流:VLC https://vlc-media-player.en.softonic.com/
直播推流:OBS https://obsproject.com/


客户端推送:

直播推流端使用rtmp协议推流,端口为1935。URL格式为:rtmp://ip:端口/hls。推流软件推荐使用开源的OBS。https://obsproject.com/
流名称要与写的观看直播的页面中的xxxx.m3u8名称一致

推流操作:

点击开始推流;
浏览器输入http:/xx.xx.xx.xx/hls/111/index.m3u8就能看直播了
111目录名根据最终生成目录决定

拉流操作:
打开VLC --> 媒体 --> 打开网络串流 --> 输入rtmp/或者hls地址
/usr/local/nginx/html/hls/111目录下生成的切片文件

浏览器查看:
HlS 地址:http://192.168.197.133/hls/111/index.m3u8
LVC 查看:正常


前端HTML 代码展示:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>PC HLS video</title><link href="http://cdn.bootcss.com/video.js/6.0.0-RC.5/alt/video-js-cdn.min.css" rel="stylesheet">
</head>
<body><h1>PC 端播放 HLS(<code>.m3u8</code>) 视频</h1>
<p>借助 video.js 和 videojs-contrib-hls</p>
<p>由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域</p><video id="hls-video" width="300" height="200" class="video-js vjs-default-skin"playsinline webkit-playsinlineautoplay controls preload="auto"x-webkit-airplay="true" x5-video-player-fullscreen="true" x5-video-player-typ="h5"><!-- 直播的视频源 --><source src="http://192.168.197.133/hls/111/index.m3u8" type="application/x-mpegURL"><!-- 点播的视频源 --><!--<source src="http://devstreaming.apple.com/videos/wwdc/2015/413eflf3lrh1tyo/413/hls_vod_mvp.m3u8" type="application/x-mpegURL">-->
</video><script src="http://cdn.bootcss.com/video.js/6.0.0-RC.5/video.js"></script>
<!-- PC 端浏览器不支持播放 hls 文件(m3u8), 需要 videojs-contrib-hls 来给我们解码 -->
<script src="http://cdn.bootcss.com/videojs-contrib-hls/5.3.3/videojs-contrib-hls.js"></script>
<script>// XMLHttpRequest cannot load http://xxx/video.m3u8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.198.98:8000' is therefore not allowed access.// 由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域var player = videojs('hls-video');player.play();
</script>
</body>

参考网址:
https://www.cnblogs.com/woaiyunwei/p/13128917.html

基于Nginx搭建RTMP-HLS视频直播服务器(推流+拉流)相关推荐

  1. php 直播服务器搭建,基于Nginx搭建RTMP/HLS视频直播服务器

    1.Nginx环境搭建(基于lnmp环境)//下载并安装lnmp环境 wget -c http://soft.vpser.net/lnmp/lnmp1.3.tar.gz && tar ...

  2. Android音视频学习系列(八) — 基于Nginx搭建(rtmp、http)直播服务器

    系列文章 Android音视频学习系列(一) - JNI从入门到精通 Android音视频学习系列(二) - 交叉编译动态库.静态库的入门 Android音视频学习系列(三) - Shell脚本入门 ...

  3. php直播平台源码基于 Nginx 搭建(rtmp、http)直播服务器

    php直播平台源码基于 Nginx 搭建(rtmp.http)直播服务器 直播协议介绍 国内常见公开的直播协议有几个:RTMP.HLS.HDL(HTTP-FLV).RTP,我们来逐一介绍. RTMP ...

  4. Windows基于Nginx搭建RTMP流媒体服务器(附带所有组件下载地址及验证方法)

    RTMP服务时常用于直播时提供拉流推流传输数据的一种服务.前段时间由于朋友想搭建一套直播时提供稳定数据传输的服务器,所以就研究了一下如何搭建及使用. 1.下载nginx 首先我们要知道一般nginx不 ...

  5. 直播系统(推流拉流) nginx+JavaCV+springboot

    nginx安装配置 1) 下载安装nginx,我下载的版本是nginx-1.7.11.3-Gryphon(提取码:xj6f),下载完成后解压 2) 下载服务器状态检查程序(提取码:i6hw),下载完成 ...

  6. 利用nginx搭建RTMP视频点播、直播、HLS服务器

    开发环境 Ubuntu 14.04 server nginx-1.8.1 nginx-rtmp-module nginx的服务器的搭建 安装nginx的依赖库 sudo apt-get update ...

  7. nginx RTMP FFmpeg 视频直播

    /***************************************************************************** nginx RTMP FFmpeg 视频直 ...

  8. 如何基于 Nginx 搭建个人直播服务器.md

    前言 最近这几年做直播和短视频领域是真的很火,而且直播的领域也很广泛,可以预见,未来的音视频技术将会作为一种基础技术应用到更广泛的场景中.它可以与 AR/VR 结合,让你在远端体验虚拟与现实,如虚拟服 ...

  9. FFmpeg入门详解之99:基于nginx的rtmp直播服务器(nginx-rtmp-module实现)

    基于nginx的rtmp直播服务器(nginx-rtmp-module实现) 首先,在搭建服务之前先了解下目前主流的几个直播协议: 1.RTMP: 实时消息传输协议,Real Time Messagi ...

  10. 使用 NGINX 搭建 RTMP 流媒体服务器实现直播功能

    使用 NGINX 搭建 RTMP 流媒体服务器实现直播功能 本文介绍了如何使用 Nginx 搭建 RTMP 流媒体服务器,并提供配置文件和前端示例,实现直播功能. 环境 操作系统: Ubuntu 18 ...

最新文章

  1. Transformer-XL解读(论文 + PyTorch源码)
  2. 古诗-豪放派和婉约派
  3. Reveal使用心法
  4. Java Word转Html
  5. httpSession的正确理解
  6. 虚拟化关键技术及解决方案
  7. Datawhale 人工智能培养方案
  8. Xcode开发技巧——调试
  9. 简单易用的安装文件制作工具NSIS的使用demo示例
  10. 服务器win2003修复,win2003服务器svchost.exe异常
  11. 合唱队形java_动态规划之合唱队形问题(最长递增子序列变形)
  12. 简单 黑苹果dsdt教程_提取DSDT和SSDT教程
  13. javascript数据类型,对象,继承及原型链
  14. ​LeetCode刷题实战371:两整数之和
  15. 使用PageInfo分页工具类
  16. 小米6指主板图示_拆解报告:小米小爱智能音箱HD
  17. 高效操作字串的String Reference类
  18. Python 使用Flask传输视频流
  19. Word--Python-docx操作蒙古文等复杂文种更换字体
  20. rust怎么传送坐标_魔兽世界太阳龙宠物怎么获得_WOW太阳龙宠物获得方法

热门文章

  1. 某代理网站免费IP地址抓取测试
  2. Python 进阶视频课 - 14. FR007 利率掉期定价和曲线拔靴
  3. flux_屏幕色温调控
  4. 全球及中国电子级硅烷(SiH4)行业动态分析及发展前景预测报告2021~2026年
  5. Java项目论文+PPT+源码等]S2SH+mysql的报刊订阅系统
  6. 公共IPV6 dns大全
  7. 解决npm只能使用管理员权限安装
  8. 李四光预测地震 中国60年内将有4次特大地震
  9. 计算机论文参考文献范文,计算机文类论文参考文献 计算机文参考文献有哪些...
  10. 解决iframe嵌套微信公众号文章图片不显示的方案