Nginx+RTMP服務(wù)器環(huán)境搭建

最近在看直播方面的博客和資料,想記錄一下這幾天的過(guò)程,方便以后查閱

一、安裝Homebrew

打開(kāi)終端, 查看是否已經(jīng)安裝了Homebrew, 直接終端輸入命令

man?brew

如果Mac已經(jīng)安裝了, 會(huì)顯示一些命令的幫助信息. 此時(shí)輸入Q退出即可, 直接進(jìn)入第二步

反之, 如果沒(méi)有安裝,執(zhí)行命令:

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

如果已經(jīng)安裝過(guò),而想要卸載:

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


通過(guò)brew -h,我們看看brew的常用指令:

brew search 搜索;

brew install? 安裝;

brew remove 卸載;

brew info 查看;


二、安裝Nginx

Nginx是一款輕量級(jí)的Web服務(wù)器/反向代理服務(wù)器及電子郵件(IMAP/POP3)代理服務(wù)器,并在一個(gè)BSD-like 協(xié)議下發(fā)行。

先glone nginx項(xiàng)目到本地:

brew tap denji/homebrew-nginx

執(zhí)行安裝:

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

注意后面的 --with-rtmp-module 不要遺漏,有些文章上只是 brewinstallnginx-full? ,并沒(méi)有安裝rtmp模塊

最后用brew info看看是否安裝成功和nginx的相關(guān)信息

brew info nginx-full

/usr/local/etc/nginx/nginx.conf (配置文件路徑)

/usr/local/var/www (服務(wù)器默認(rèn)路徑)

/usr/local/Cellar/? (安裝路徑)

open -t? /usr/local/etc/nginx/nginx.conf? 可以用文本編輯器打開(kāi)配置文件

nginx -s reload 重新加載配置

nginx -s reopen 重新打開(kāi)log

nginx -s stop 停止nginx

nginx -s quit 退出nginx

通過(guò)操作以上步驟,nginx和rtmp模塊就安裝好了

接著啟動(dòng)Nginx,在終端輸入:

nginx

打開(kāi)Safari輸入http://localhost:8080,如果安裝成功,會(huì)顯示welcome to nginx!


三、配置Nginx

1、支持http協(xié)議推流

在終端輸入

open -t? /usr/local/etc/nginx/nginx.conf

在http{xxx}體下面插入rtmp配置信息


插入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;

????? ? ? ? ? ? }

??????? }

}


2、支持rtmp協(xié)議拉流

在終端輸入

open -t? /usr/local/etc/nginx/nginx.conf

找到圖中位置,在locatin /{xxx}下插入配置信息

插入配置信息

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;

}


3、重啟Nginx

在終端輸入

nginx -s reload

重啟Nginx

如果在修改配置文件,重啟遇到

[error] open() "/usr/local/var/run/nginx.pid" failed

可以用下面的命令重新加載配置

nginx -c /usr/local/etc/nginx/nginx.conf


四、安裝FFmpeg

如果使用mac推流,則可以使用FFmpeg

FFmpeg是一套可以用來(lái)記錄、轉(zhuǎn)換數(shù)字音頻、視頻,并能將其轉(zhuǎn)化為流的開(kāi)源計(jì)算機(jī)程序

在終端輸入:

brew install ffmpeg

等待安裝完成后,輸入:

brew info ffmpeg

查看是否安裝成功

輸入:

ffmpeg -re -iabc.mp4-vcodec copy -acodec copy? -f flv rtmp://localhost:1935/hls/xxx(自己命名)

就可以推流了

五、最后的最后

現(xiàn)在就可以使用Mac當(dāng)做RTMP服務(wù)器實(shí)現(xiàn)直播了

最后編輯于
?著作權(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)容