1. 程式人生 > >搭建基於RTMP的本地Nginx伺服器報錯homebrew/nginx was deprecated. This tap is now empty as all its form

搭建基於RTMP的本地Nginx伺服器報錯homebrew/nginx was deprecated. This tap is now empty as all its form

最近搭建基於RTMP的本地Nginx伺服器,沒想到第一步克隆就報錯:homebrew/nginx was deprecated. This tap is now empty as all its formulae were migrated.具體如下:

第一步使用:

 1> 將Nginx Clone到本地
$ brew tap homebrew/nginx

報錯如下:

出現的原因是homebrew/nginx的git路徑變了(貌似是2018年3月更新)

查詢得到把克隆到本地的命令更改後可解決,更改為:

brew tap denji/homebrew-nginx

克隆成功,然後執行第二步:

3> 安裝Nginx
$ brew install nginx-full --with-rtmp-module

結果如下:

根據提示需要執行:

brew unlink nginx

執行成功,總和上面的步驟為:

// 克隆到本地
brew tap homebrew/nginx
// unlink
brew unlink nginx
// 安裝
brew install nginx-full --with-rtmp-module
// 啟動 
nginx

 配置檔案的路徑(/usr/local/etc/nginx/nginx.conf)

1>配置Nginx,支援http協議拉流

location /hls {
        #Serve HLS config
        types {
            application/vnd.apple.mpegurl    m3u8;
            video/mp2t ts;
        }
        root /usr/local/var/www;
        add_header Cache-Control    no-cache;
    }
2>配置Nginx,支援rtmp協議推流
rtmp {
    server {
        listen 1935;
        application rtmplive {
            live on;
            max_connections 1024;
        }
        application hls{
            live on;
            hls on;
            hls_path /usr/local/var/www/hls;
            hls_fragment 1s;
        }
    }
}
3>重啟
nginx -s reload

推流測試

  • 推流至RTMP到伺服器
    • 生成地址: rtmp://localhost:1935/rtmplive/demo
      ffmpeg -re -i story.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/rtmplive/demo
  • 推流至HLS到伺服器
    • 生成地址: http://localhost:8080/hls/test.m3u8
      ffmpeg -re -i /Users/apple/Desktop/ffmepg/story.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/hls/demo