Nginx+rtmp+ffmpeg 搭建推流服务器

时间:2023-03-09 04:31:05
Nginx+rtmp+ffmpeg 搭建推流服务器

1. 安装nginx服务器

1.1 clone

$ brew tap denji/homebrew-nginx

1.2 安装

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

安装过程过程中可能会报错

➜  ~ brew install nginx-full --with-rtmp-module
==> Installing nginx-full from denji/nginx
Error: Xcode alone is not sufficient on High Sierra.
Install the Command Line Tools:
xcode-select --install
$ xcode-select --install 

Nginx+rtmp+ffmpeg 搭建推流服务器

另一个报错信息,重新执行命令 brew install nginx-full --with-rtmp-module吧

curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
Error: An exception occurred within a child process:
DownloadError: Failed to download resource "rtmp-nginx-module--patch"
Download failed: https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/compare/v1.1.7.10...504b9ee.diff

1.3 启动/停止

$ sudo nginx
$ sudo nginx -s stop

1.4 查看配置信息

$ brew info nginx-full
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
Stop process:
$ nginx -s stop
Waiting on exit process
$ nginx -s quit 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

2. rtsp

2.1 对nginx添加对rtmp的支持 编辑文档

$ sudo vim /usr/local/etc/nginx/nginx.conf

在文旦最后面加入对rtsp的支持

# 在http节点后面加上rtmp配置:
rtmp {
server {
listen 1557;
application gllive {
live on;
record off;
}
}
}

保存之后重启服务

$ sudo nginx -s reload

2.2 使用ffmpeg进行推流

$ ffmpeg -re -i 560.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1557/gllive/room