视频直播本地测试服务器搭建

如何搭建局域网推流服务器?

一 搭建服务器所需

    1. nginx

    2. nginx--rtmp-module

    3. Homebrew


二 开始安装

    1. 首先需要安装 Homebrew, 打开终端,用以下命令进行安装

1
2
3
4
5
//  安装命令
ruby -e  "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
 
//  卸载命令
ruby -e  "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

    2.安装nginx 如果执行出错 请在命令最前面  加上 sudo

    首先将nginx项目克隆到本地

1
brew tap homebrew /nginx

    执行安装nginx

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

    以上步骤走完,nginx应该装好了,如果没有装好

QQ20160617-0.png

再次执行

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

三 运行 nginx

    终端输入  nginx 即可运行nginx, 然后打开浏览器,访问 localhost:8080  或者 127.0.0.1:8080 

   如果出现Welcome to nginx!
表示nginx服务器搭建成功了,而且已经安装了RTMP模块了

四 配置nginx

    1. 执行下面命令,查看配置信息

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

    VLC拉流播放,打开VLC 然后 file->open network->输入:

1
rtmp: //localhost :5920 /rtmplive/room

QQ20160617-1.png

已经开始推流啦

使用VLC播放


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值