美文网首页
Mac搭建直播服务器

Mac搭建直播服务器

作者: 偶是星爷 | 来源:发表于2016-10-25 13:55 被阅读169次

    1. 用brew安装nginx

    brew tap homebrew/nginx
    

    网上一般这个时候直接brew安装了,不过最好先update一下

    sudo chown -R $(whoami):admin /usr/local
    brew update
    

    然后再安装nginx

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

    安装完了,最好按提示提升一下ngnix权限,否则别的机器可能连不上

    sudo chown root:wheel /usr/local/Cellar/nginx-full/1.10.2/bin/nginx
    sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.2/bin/nginx
    

    2. 配置nginx

    brew info nginx-full
    可以看到nginx的配置文件路径

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

    打开/usr/local/etc/nginx/nginx.conf,在文件最后加上下面配置

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

    3. 测试

    启动ngnix后就能推流上去了

    nginx
    

    推流用ffmpeg最方便

    ffmpeg -re -i /Users/annidy/Movies/完美的星球720p.mp4 -vcodec copy -f flv rtmp://localhost:1935/fx/room
    

    room房间号无所谓,随便填。然后就可以直接用VLC播了。

    播放地址 rtmp://localhost:1935/fx/room

    4. 开启录制

    ngnix rtmp moudle的录制功能有助于调试,打开很简单,修改配置即可。

    rtmp {
        server {
            listen 1935;
            application fx {
                live on;
                record all;
                record_path /tmp;
                record_suffix -%Y-%m-%d-%H%M.flv;
            }
        }
    }
    

    重新加载一下配置文件

    nginx -s reload
    

    录制的文件存放于/tmp目录下,当然这是随便可以改的。

    相关文章

      网友评论

          本文标题:Mac搭建直播服务器

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