iOS 直播视频iOS直播技术视频直播

MAC 搭建RTMP服务器nginx 和 srs

2016-07-20  本文已影响1956人  youngyunxing

方案一: nginx

brew tap homebrew/nginx

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

通过以上步骤nginx和rtmp模块就安装好了,下面配置rtmp模块

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.10.1/bin/nginx
 $ sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.1/bin/nginx
Reload config:
 $ nginx -s reload
Reopen Logfile:
 $ nginx -s reopen
Stop process:
 $ nginx -s stop
Waiting on exit process
 $ nginx -s quit

To have launchd start homebrew/nginx/nginx-full now and restart at login:
  brew services start homebrew/nginx/nginx-full
Or, if you don't want/need a background service you can just run:
  nginx

对我们有用的信息如下:

  1. niginx 服务器所在根目录:
/usr/local/var/www

  1. niginx安装所在文件夹
/usr/local/Cellar/nginx-full/
     
  1. nginx配置文件路径
/usr/local/etc/nginx/nginx.conf

  1. 版本信息:1.10.1
niginx

或者

/usr/local/Cellar/nginx-full/1.10.1/bin/nginx

然后在浏览器地址栏输入:http://localhost:8080
如果出现Welcome to nginx!证明nginx安装成功,可以下一步了,否则卸了重来

cd /usr/local/etc/nginx

open .

用xcode打开nginx.conf文件
在末尾空白处( }之后空白,也就是118行之后)添加如下代码

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

live 表示 app名字,1935表示端口,那么推流和播放地址就是:

rtmp://本机ip(局域网地址):1935/live/xxx

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

注意:1.10.1表示版本,自己根据上面的打印信息适当修改

nginx -s stop 

或者

/usr/local/Cellar/nginx-full/1.10.1/bin/nginx -s stop

方案二:SRS

MAC下编译SRS源代码

先克隆到本地,代码有点大,耐心等待

git clone https://github.com/ossrs/srs.git
cd srs/trunk
# 指定Mac编译,并关闭其他option
./configure --osx --without-ssl --without-hls --without-hds --without-dvr --without-nginx --without-http-callback --without-http-server --without-stream-caster --without-http-api --without-ffmpeg --without-transcode --without-ingest --without-stat --without-librtmp
make

不出意外就成功了

运行SRS服务器

修改srs.conf

由于Mac系统的限制,运行SRS的话需要把./conf/srs.conf中的并发数修改下,我修改成250:
srs.conf中的这一行需要修改下:max_connections 250;

Paste_Image.png

开启成功效果如下:


Paste_Image.png
上一篇下一篇

猜你喜欢

热点阅读