Mac上搭建直播服務(wù)器 Nginx+rtmp

Mac上搭建直播服務(wù)器 Nginx+rtmp

簡(jiǎn)介

Nginx 是非常優(yōu)秀的開(kāi)源服務(wù)器,用它來(lái)做hls或者rtmp流媒體服務(wù)器是非常不錯(cuò)的選擇,

1、安裝

增加對(duì) nginx 的擴(kuò)展;也就是從github上下載,home-brew對(duì)ngixn的擴(kuò)展

執(zhí)行克隆命令,github的項(xiàng)目(https://github.com/denji/homebrew-nginx)

$ brew tap denji/nginx 

注意: brew tap homebrew/nginx 報(bào)下面的錯(cuò)誤, 使用brew tap denji/nginx替代
homebrew/nginx was deprecated. This tap is now empty as all its formulae were migrated.

2、執(zhí)行安裝命令:

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

查看 nginx 安裝在哪里

$ brew info nginx-full
--HEAD
    Install HEAD version
==> Caveats
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/opt/nginx-full/bin/nginx
 $ sudo chmod u+s /usr/local/opt/nginx-full/bin/nginx
Reload config:
 $ nginx -s reload  ## 重新加載配置文件
Reopen Logfile:
 $ nginx -s reopen  ## 再次打開(kāi)配置文件
Stop process:
 $ nginx -s stop    ## 停止服務(wù)器
Waiting on exit process
 $ nginx -s quit    ## 退出服務(wù)器

To have launchd start denji/nginx/nginx-full now and restart at login:
  brew services start denji/nginx/nginx-full
Or, if you don't want/need a background service you can just run:
  nginx
  • nginx安裝所在位置 /usr/local/opt/nginx-full/bin/nginx
  • nginx配置文件所在位置 /usr/local/etc/nginx/nginx.conf
  • nginx服務(wù)器根目錄所在位置 /usr/local/var/www

啟動(dòng)nginx服務(wù)

$ nginx

在瀏覽器地址欄輸入:http://localhost:8080
出現(xiàn)Welcome to nginx ,代表nginx安裝成功了。

3、配置rtmp

打開(kāi)配置文件 /usr/local/etc/nginx/nginx.conf

http {
    ……
}

#在http節(jié)點(diǎn)下面(也就是文件的尾部)加上rtmp配置:
rtmp {
    server {
        listen 1935;
        application abcs {
            live on;
            record off;
        }
    }
}
  • rtmp 是協(xié)議名稱(chēng)
  • server 說(shuō)明內(nèi)部中是服務(wù)器相關(guān)配置
  • listen 監(jiān)聽(tīng)的端口號(hào), rtmp協(xié)議的默認(rèn)端口號(hào)是1935
  • application 訪問(wèn)的應(yīng)用路徑是 abcs
  • live on; 開(kāi)啟實(shí)時(shí)
  • record off; 不記錄數(shù)據(jù)

4、 保存文件后,重新加載nginx的配置文件

$ nginx -s reload

5、安裝ffmepg工具

$ brew install ffmpeg

安裝這個(gè)需要等一段時(shí)間, 這時(shí)你可以準(zhǔn)備一個(gè)視頻文件作為來(lái)推流,然后安裝一個(gè)支持rtmp協(xié)議的視頻播放器.Mac下可以用 VLC

6、通過(guò)ffmepg命令進(jìn)行推流

ffmpeg -re -i [你的視頻文件的絕對(duì)路徑] -vcodec copy -f flv rtmp://localhost:1935/abcs/room

// 如:ffmpeg -re -i /Users/caolongjian/Desktop/CCVideo.mp4  -vcodec copy -f flv rtmp://localhost:1935/abcs/room

這里abcs是上面的配置文件中,配置的應(yīng)用的路徑名稱(chēng);后面的room可以隨便寫(xiě)。

7、 驗(yàn)證視頻

然后電腦上打開(kāi)vlc這個(gè)播放器軟件 點(diǎn)擊File---->Open Network 在彈出來(lái)的框中選擇Network然后輸入U(xiǎn)RL:

rtmp://localhost:1935/abcs/room

參考

Mac上搭建直播服務(wù)器Nginx+rtmp
mac搭建naginx+rtmp服務(wù)器-帶你出坑


[toc]

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容