介绍

nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择,本人在网上整理了安装流程,分享给大家并且作备忘。

安装步骤

1.先安装brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如果要下载brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

2.安装Niginx

增加对 nginx 的扩展;也就是从github上下载,home-brew对ngixnx的扩展

brew tap homebrew/nginx

3.安装Nginx服务器和rtmp模块

brew install nginx-full --with-rtmp-module

这个安装,耗时相对来说比较长。通过操作以上步骤nginx和rtmp模块就安装好了,下面开始来配置nginx的rtmp模块。

查看nginx安装路径:

brew info nginx-full
  • nginx安装所在位置  /usr/local/Cellar/nginx-full/1.10.1/bin/nginx
  • nginx配置文件所在位置   /usr/local/etc/nginx/nginx.conf
  • nginx服务器根目录所在位置  /usr/local/var/www

4.启动Nginx

nginx

在浏览器地址栏输入:http://localhost:8080

关闭Nsinx:

nginx -s stop

5.配置RTMP

打开nginx.conf, 找到/usr/local/etc/nginx/nginx.conf 文件

http {
……
}
#在http节点下面(也就是文件的尾部)加上rtmp配置:
rtmp {
server {
listen 1935;
application zbcs {
live on;
record off;
}
}
}

说明:

    1. rtmp是协议名称
    2. server 说明内部中是服务器相关配置
    3. listen 监听的端口号, rtmp协议的默认端口号是1935
    4. application 访问的应用路径是 zbcs
    5. live on; 开启实时
    6. record off; 不记录数据

5.保存文件后重启Nginx

nginx -s reload

6.安装ffmpeg工具

brew install ffmpeg

7.安装支持RTMP播放的软件

VLC:http://rj.baidu.com/soft/detail/25680.html?ald

8.通过ffmpeg进行推流

ffmpeg -re -i /Users/****/Documents/Document/demo.mp4  -vcodec copy -f flv rtmp://localhost:1935/zbcs/room

这里zbcs是上面的配置文件中,配置的应用的路径名称;后面的room可以随便写

9.在vlc中播放RTMP视频

然后电脑上打开vlc这个播放器软件 点击File---->Open Network 在弹出来的框中选择Network然后输入URL:

rtmp://localhost:1935/zbcs/room

双击播放。

10.配置HLS

打开nginx.conf, 找到/usr/local/etc/nginx/nginx.conf 文件,找到http -> server,在花括号中增加:

 server {
listen 8080;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #HLS配置开始,这个配置为了`客户端`能够以http协议获取HLS的拉流
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root html;
add_header Cache-Control no-cache;
}
#HLS配置结束 #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;
}
}

找到rtmp下的server,在花括号中增加:

#在http节点下面(也就是文件的尾部)加上rtmp配置:
rtmp {
server {
listen 1935;
application zbcs {
live on;
record off;
}
#增加对HLS支持开始
application hls {
live on;
hls on;
hls_path /usr/local/var/www/hls;
hls_fragment 5s;
}
#增加对HLS支持结束
}
}

说明:

  1. live on; 开启实时
  2. hls on; 开启hls
  3. hls_path; ts文件存放路径
  4. hls_fragment 5s; 每个TS文件包含5秒的视频内容

11.保存配置文件,重新启动nginx

nginx -s reload

12.利用ffmpeg推流到Nginx

ffmpeg -re -i /Users/jiangys/Documents/Document/demo.mp4 -vcodec copy -f flv rtmp://localhost:1935/hls/movie

然后就可以在/usr/local/var/www/hls(html默认配置文件)路径下看到ts的切片文件和m3u8文件

13.播放hls

通过上面配置,可以通过rtmp和hls两种方式来播放

1)rtmp方式:

用VCL打开:

rtmp://192.168.1.100/hls/movie

2)hls方式:

用VCL或者Safari浏览器:

http://192.168.1.100:8080/hls/movie.m3u8

14.如果想把ts文件存放到指定路径下,比如"/tmp/hls"

  application hls {
live on;
hls on;
hls_path /tmp/hls;
}

那么,我们也需要在http-->server中对root 路径更改为:/tmp 。要不然,会拉不到流。

10.错误处理

1)ffmepg命令推流的时候,提示连接失败。[tcp @ 0x7ff162504b60] Connection to tcp://localhost:1935 failed (Connection refused), trying next address

出现这个错,是因为配置了nginx.conf后,需要重启nginx。输入命令重启后就没有问题了

nginx -s reload

2)安装完nginx后,在浏览器地址栏输入:http://localhost:8080 显示打不开网页

解决方式:由于安装后nginx服务器,有时需要等上几分钟才生效。如果还不生效,测试下是否能成功启动nginx服务,命令

nginx

Mac上搭建Nginx + rtmp的更多相关文章

  1. 在 Mac 上搭建 Nginx PHP Mysql 开发环境

    事实上这个过程跟Linux下安装都几乎相同,仅仅是部分命令有区别,大同小异. 网上看到非常多教程都是用 brew 之类的包管理器安装,可是 Mac 自带了 php , 难道还要再装一个第三方的?强迫症 ...

  2. Mac上搭建nginx教程

    1.安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in ...

  3. Centos7 搭建Nginx+rtmp+hls直播推流服务器

    1 准备工具 使用yum安装git [root~]# yum -y install git 下载nginx-rtmp-module,官方github地址 // 通过git clone 的方式下载到服务 ...

  4. Mac上搭建直播服务器Nginx+rtmp

    简介 nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择,本人在网上整理了安装流程,分享给大家并且作备忘. 步骤安装 1.安装Homebrow Homebrew简 ...

  5. Mac上搭建直播服务器Nginx

    Mac上搭建直播服务器Nginx 1.安装Homebrew,执行命令 Homebrew简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就 ...

  6. mac 教你如何在Mac上搭建自己的服务器——Nginx

    WHAT 本篇主要是基于Nginx在Mac上搭建自己的服务器. 我相信很多朋友肯定是第一次听到Nginx,关于它具有怎样的传奇,这儿肯定说不完也说不透. 有兴趣的朋友可以自行google或者baidu ...

  7. 三、直播整体流程 五、搭建Nginx+Rtmp直播流服务

    HTML5实现视频直播功能思路详解_html5教程技巧_脚本之家 https://m.jb51.net/html5/587215.html 三.直播整体流程 直播整体流程大致可分为: 视频采集端:可以 ...

  8. 在MAC上搭建cordova3.4.0的IOS和android开发环境

    Hello,大家好,今天给大家说说在mac上搭建cordova3.4.0的iOS和Android开发环境,首先下载cordova,地址:https://cordova.apache.org/#down ...

  9. 1、在MAC上搭建React Native开发环境

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

随机推荐

  1. cocos2d-x 帧动画

    ani = cc.Animation:create(); ...... local animate = cc.Animate:create(ani); s:runAction(animate); 发现 ...

  2. vue-router

    官方文档: 旧版:https://github.com/vuejs/vue-router/tree/1.0/docs/zh-cn 新版:http://router.vuejs.org/(2.0版本) ...

  3. 获取iis网站信息

    1.获取网站的url地址 var ht = GetWebPathAndWebName(""); var rootUrl = ht["webaddr"].ToSt ...

  4. HAOI2017前

    NOIP后想换一个看起来比较高端的博客,于是尝试用github+hexo建站,地址大概是这样的,搞了一周左右.. 最终以失败告终,一是代码高亮有bug,二是数学公式有bug,三是博文没法快速搬迁QAQ ...

  5. Thinkphp文件上传

    1.在IndexController.class.php里面写2个方法,shangchuan用来显示页面,upload是上传文件的方法. <?php namespace Home\Control ...

  6. vs2015 HTTP Error 400. The request hostname is invalid.

    <site name="> <application path="/" applicationPool="Clr4IntegratedAppP ...

  7. Linux下数据恢复软件extundelete

    extundelete软件专门解决意外删除事件的,有时候不小心 rm -rf * 就可能毁掉有用的数据.因此就出现了这个恢复工具,但这个工具也不是万能的,删除数据后一定要停止所以的写操作.以免Inod ...

  8. PHP中Exception异常

    异常的基本使用 当异常被抛出时,其后的代码不会继续执行,PHP 会尝试查找匹配的 "catch" 代码块. 如果异常没有被捕获,而且又没用使用 set_exception_hand ...

  9. ubuntu 12.04 LTS 64位兼容运行32位程序

    安装完Goagent,运行的时候出现了问题,在网络上翻看一些关于ubuntu的文档时,突然记起自己安装的是64位版,而goagent应该是32位的,于是通过sudo apt-get install i ...

  10. Windows 安装JRuby 生成 war 到 tomcat 运行

    Windows安装JRuby Rails 直接下载 JRuby,不装 Ruby. http://jruby.org/download 该安装包可以配好环境变量 %JRUBY_HOME% 等 安装 bu ...