美文网首页iOS Tips苹果开发集锦iOS Developer
OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

作者: 嗷大喵 | 来源:发表于2016-04-28 01:36 被阅读2024次

参考文章:

https://github.com/Homebrew/homebrew-nginx

1.安装Homebrew,执行命令

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

2.执行命令:

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

通过操作以上步骤nginx和rtmp模块就安装好了,下面开始来配置nginx的rtmp模块

首先来看看我们的nginx安装在哪里了

brew info nginx-full

执行上面的命令后我们可以看到信息

Docroot is: /usr/local/var/www
 
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
 
nginx will load all files in /usr/local/etc/nginx/servers/.
 
- Tips -
Run port 80:
 $ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.8.1/bin/nginx
 $ sudo chmod u+s /usr/local/Cellar/nginx-full/1.8.1/bin/nginx

nginx安装所在位置
/usr/local/Cellar/nginx-full/

nginx配置文件所在位置
/usr/local/etc/nginx/nginx.conf

nginx服务器根目录所在位置
/usr/local/var/www
执行命令 ,测试下是否能成功启动nginx服务

/usr/local/Cellar/nginx-full/1.8.1/bin/nginx
在浏览器地址栏输入:http://localhost:8080 如果出现

Welcome to nginx!
代表nginx安装成功了

现在我们来修改nginx.conf这个配置文件,配置rtmp

4.用记事本工具打开nginx.conf

http {
……
}
在http节点后面加上rtmp配置:

rtmp {
    server {
        listen 1935;
        application live1 {
            live on;
            record off;
        }
    }
}

然后保存文件后,重新加载nginx的配置文件

/usr/local/Cellar/nginx-full/1.8.1/bin/nginx -s reload

现在我们可以来对推流进行测试了 看看我们的rtmp能不能推流成功

推流我们可以通过ffmepg来进行

5.安装ffmepg工具

brew install ffmpeg
安装这个需要等一段时间等待吧 然后准备一个视频文件作为来推流,然后我们在安装一个支持rtmp协议的视频播放器,Mac下可以用VLC

ffmepg 安装完成后可以开始推流了

6.通过ffmepg命令进行推流

ffmpeg -re -i /Users/Rick/Movies/Demo.mov -vcodec copy -f flv rtmp://localhost:1935/live1/room1

这个room1是可以随便定义的,只要live1和上面nginx.conf里面配置的一样就行

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

rtmp://localhost:1935/live1/room1

这样就能看到通过ffmpeg推过来的视频了

这就是一个简单的视频直播服务器的搭建

相关文章

网友评论

  • 4bc347552fb5:brew install nginx-full --with-rtmp-module 卡在
    ==> ./configure --prefix=/usr/local/Cellar/nginx-full/1.10.1 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx-full/1.10.1/bin/n
    ==> make install
    一直卡在这不动是什么问题?取消重新试了几遍都是这样
    eef8399abc3b:@狂奔的泡面 跟楼主一样,不知道楼主是否解决了?看日志不太像是被墙了,我这边最后是卡在。
    test -d '/usr/local/var/run' \
    || mkdir -p '/usr/local/var/run'
    test -d '/usr/local/var/log/nginx' \
    || mkdir -p '/usr/local/var/log/nginx'
    test -d '/usr/local/Cellar/nginx-full/1.10.1/html' \
    || cp -R html '/usr/local/Cellar/nginx-full/1.10.1'
    test -d '/usr/local/var/log/nginx' \
    || mkdir -p '/usr/local/var/log/nginx'
    嗷大喵:@狂奔的泡面 估计是被墙了
  • ed614c432aa6:请问“这个room1是可以随便定义的,只要live1和上面nginx.conf里面配置的一样就行”live1怎么配置,在哪配置
    ed614c432aa6:@junjun55 已经解决了
  • Mr_FF:楼主你好,第三步执行完,执行/usr/local/Cellar/nginx-full/的时候,文件不存在,在finder中发现,Cellar文件存在,nginx-full不存在,是没安装上吧,怎么回事啊,求解
    JanzenChen:@Mr_FF 这个我也不懂,但是知道解决办法,在finder下双击执行该文件,可以省略reload命令
  • 浅y:您好 我遇到这个问题 rtmp" directive is not allowed here in /usr/local/etc/nginx/nginx.conf:79
    这个怎么楼主遇到没
    sclcoder:@浅宇 哥们 换了配置文件 好了吗 ? 我现在也是遇到这个问题,换了配置文件还是不识别 rtmp,不知你解决了没有?求解
    浅y:@嗷大喵 谢谢 楼主
    嗷大喵:@浅宇 配置贴出来了
    https://gist.github.com/singer1026/997dcadcbcf10e730b405b617f84349f
  • xuzhenhao:你好,我安装你的配置,到ffmepg命令推流的时候,提示连接失败。[tcp @ 0x7ff162504b60] Connection to tcp://localhost:1935 failed (Connection refused), trying next address 求教
    d4073e5878b0:@xuzhenhao 刚刚试成功了,出现这个错,是因为配置了nginx.conf后,需要重启nginx。输入命令“nginx -s reload” 重启后就没有问题了。
    嗷大喵:@xuzhenhao 这个我没遇到过 ffmpeg推流不成功的话 那你尝试下用开源软件OBS 进行推流吧

本文标题:OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

本文链接:https://www.haomeiwen.com/subject/tezcrttx.html