美文网首页直播
搭建直播服务器Nginx+rtmp,如此简单(mac)

搭建直播服务器Nginx+rtmp,如此简单(mac)

作者: 蓝师傅_Android | 来源:发表于2019-08-18 11:37 被阅读0次

1. 安装Homebrew

Homebrew简称brew,是mac 下的软件包管理工具。
如果没有安装Homebrew,通过以下命令安装

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

2.安装Nginx服务器

brew tap denji/homebrew-nginx

3.安装Nginx服务器的rtmp模块

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

成功如下


运行命令查看Nginx安装目录

brew info nginx-full

4.启动Nginx

nginx

在浏览器打开
http://localhost:8080/

Nginx常用命令

  1. nginx -s reload 重新加载配置文件
  2. nginx -s reopen 再次打开日志文件
  3. nginx -s stop 停止服务器
  4. nginx -s quit 退出服务器
  5. nginx 启动Nginx

Nginx目录

  • 安装位置 /usr/local/opt/nginx-full/bin/nginx
  • 配置文件所在目录 /usr/local/etc/nginx/nginx.conf
  • 服务器根目录 /usr/local/var/www

5.配置rtmp

打开配置文件

open -e /usr/local/etc/nginx/nginx.conf

http节点下面(文件末尾),加上 rtmp配置如下


  • rtmp 表示协议名称
  • server 说明内部是服务器相关配置
  • listen 监听的端口,RTMP协议默认端口1935
  • application 访问的应用路径
  • live on 表示开启实时流直播
  • record off 表示不记录数据

保存修改后,重新加载Nginx配置文件

nginx -s reload

6 使用FFmpeg 命令推流

(FFmpeg就不多说了,不知道看前面文章)

命令如下,默认是1935端口

./ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost/test/live

test 是之前配置的,live根据需求去写。

可以看到推流是成功的,那拉流试下

7. 测试拉流

最后试下拉流,我电脑安装了Movist Pro,可以直接打开URL,其它视频软件同理,如果电脑有安装FFmpeg环境,直接用以下命令也是可以的

ffplay rtmp://192.168.43.144:1935/test/live

或者

ffplay rtmp://localhost/test/live

Movist Pro 操作如下:


输入推流地址 :rtmp://localhost/test/live

结果是成功的



如果是linux系统则参考
https://www.jianshu.com/p/5c41273aa35e?utm_campaign=haruki&utm_content=note&utm_medium=reader_share&utm_source=qq

参考:
https://www.jianshu.com/p/a0397c98d907

相关文章

网友评论

    本文标题:搭建直播服务器Nginx+rtmp,如此简单(mac)

    本文链接:https://www.haomeiwen.com/subject/tgsmlctx.html