如何搭建局域网推流服务器? 一 搭建服务器所需
1. nginx
2. nginx--rtmp-module
3. Homebrew
二 开始安装
1. 首先需要安装 Homebrew, 打开终端,用以下命令进行安装
2.安装nginx 如果执行出错 请在命令最前面 加上 sudo
首先将nginx项目克隆到本地
执行安装nginx
以上步骤走完,nginx应该装好了,如果没有装好
再次执行
三 运行 nginx
终端输入 nginx 即可运行nginx, 然后打开浏览器,访问 localhost:8080 或者 127.0.0.1:8080
|
1
|
brew info nginx-full |
输出如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
==> Caveats Docroot is: /usr/local/var/www // /usr/local/etc/nginx/nginx .conf // 配置文件路径 // 8080 端口 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.0 /bin/nginx // /usr/local/Cellar/nginx-full/1 .10.0 /bin/nginx // nginx安装的完整路径 $ sudo chmod u+s /usr/local/Cellar/nginx-full/1 .10.0 /bin/nginx Reload config: // 重新加载配置文件 $ nginx -s reload Reopen Logfile: // 重新打开 nginx $ nginx -s reopen Stop process: // 停止 nginx $ nginx -s stop Waiting on exit process // 退出 nginx $ 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 |
2. 使用vim编辑器打开配置文件
1
|
vi /usr/local/etc/nginx/nginx .conf |
滚到最底部,加入如下代码
1
2
3
4
5
6
7
8
9
10
|
# 在http节点后面加上rtmp配置: rtmp { server { listen 5920; // 端口 默认的是 1935 application rtmplive { // rtmplive app 名 live on; // 打开直播 record off; // 是否录制 } } } |
3.从新加载配置文件
1
|
/usr/local/Cellar/nginx-full/1 .10.0 /bin/nginx -s reload |
五 安装 ffmpeg
1
|
brew install ffmpeg |
ffmpeg推流
1
2
3
4
5
|
// /Users/yuanmc/Desktop/AOA .mp4 视频文件地址 // rtmp: //localhost :5920 /rtmplive/room 推流拉流地址 // acc 音频格式 // flv 视频格式 ffmpeg -re -i /Users/yuanmc/Desktop/AOA .mp4 -vcodec libx264 -acodec aac -f flv rtmp: //localhost :5920 /rtmplive/room |
1
|
rtmp: //localhost :5920 /rtmplive/room |
已经开始推流啦
使用VLC播放