文章目录
- 快速搭建基于rmtp协议的直播平台
-
- 环境
- 准备
-
- client端
- server端
- 安装
-
- server端
- 配置
-
- Server端
- 运行
-
- Server端
- Client端
- 参考
快速搭建基于rmtp协议的直播平台
环境
- client端 win10
- server端(直播) Ubuntu16.04
准备
- 先在server端将目录建好, 假设我们所有的文件都放在
中root/live
$ cd /root
$ mkdir live
$ mkdir nginx
$ mkdir video
$ cd live
client端
- CLV
server端
- nginx下载地址: nginx
- ffmepg安装教程: ffmepg
- nginx-rtmp-module下载地址: nginx-rtmp-module
$ wget http://nginx.org/download/nginx-1.8.1.tar.gz
$ wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz
安装
- client端就不用说了, exe文件一直点击安装就行
server端
- 假设我的目录文件都放在
下面root/live
- 解压
,nginx
nginx-rtmp-module
$ tar -zxvf nginx-1.8.1.tar.gz -C ./ $ tar -zxvf nginx-rtmp-module-1.2.1.tar -C ./
- 给
重新命名nginx-rtmp-module-1.2.1
nginx-rtmp-module-master
$ mv nginx-rtmp-module-1.2.1 nginx-rtmp-module-master
- 安装
nginx
$ cd nginx-1.8.1 $ ./configure --add-module=../nginx-rtmp-module-master --prefix=/root/live/nginx $ make $ make install
- 检查nginx安装成功
$ cd /root/live/nginx && ./sbin/nginx
- 浏览器访问你的服务端ip地址, 假设是
, 将出现nginx的欢迎页面1.2.3.4
nginx 默认是
端口80
配置
Server端
- 修改
的访问端口nginx
,推流
端口和拉流
配置, 端口这里假设为18080和18081, 用阿里云的朋友记得给端口开放权限location
$ cd /root/live/nginx $ vim conf/nginx.conf
看下面的配置, 需要修改的地方都加了重点
TODO
http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { # TODO from 80 -> 18080 listen 18080; server_name 0.0.0.0; #charset koi8-r; #access_log logs/host.access.log main; # TODO add location /stat location /stat{ rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } # TODO add location /stat.xsl location /stat.xsl{ root /root/live/nginx-rtmp-module-master/; } location / { root html; index index.html index.htm; } ... ...
运行
Server端
- 重启
nginx
$ cd /root/live/nginx $ ./sbin/nginx -s reload
然后还是可以通过访问1.2.3.4:18080来确定nginx成功重启
- 浏览器访问
, 会出现如下图1.2.3.4:18080/stat
rmtp+nginx+ffmpeg快速搭建直播平台快速搭建基于rmtp协议的直播平台 - 创建直播
, 需要在推流
目录下放好一个/root/live/video
文件(可以使用scp进行远程传输)audio.mp4
$ cd /root/live/video $ ffmpeg -re -i ./audio.mp4 -vcodec copy -acodec copy -f flv rtmp://1.2.3.4:18081/live/audio
是我们在nginx配置文件中配置的application,live
随便写的, 可以换成别的audio
-
的话将会出现以下信息成功
rmtp+nginx+ffmpeg快速搭建直播平台快速搭建基于rmtp协议的直播平台
-
Client端
- 这个时候我们可以打开之前下载的CLV工具了, 选择如下:
- Media->Open Network Stream
- 输入我们的
地址rtmp
rtmp://1.2.3.4:18081/live/audio
- 等待几秒, 我们的直播平台就搭建好了!
参考
[1] RTMP官方文档
[2] nginx-rtmp-module
[3] nginx官方文档
[4] 使用nginx-rtmp-module搭建RTMP直播服务器
[5] 如何从零开始搭建高性能直播平台