RTMP全称是Real Time Messaging Protocol(实时消息传输协议),rmtp是一种通讯协议。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。现在更流行于直播平台服务器的推流处理!
install搭建
建立源码编译的目录
mkdirnginx−src
m
k
d
i
r
n
g
i
n
x
−
s
r
c
cd nginx-src
下载源码仓库
nginx源码
$ git clone https://github.com/nginx/nginx.git
nginx的rtmp模块源码
$ git clone https://github.com/arut/nginx-rtmp-module.git
nginx的依赖pcre源码
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar−xzvfpcre−8.39.tar.gz
t
a
r
−
x
z
v
f
p
c
r
e
−
8.39.
t
a
r
.
g
z
cd nginx$ git checkout release-1.9.9
准备编译安装
将configure的命令封装成脚本
$ vim cfg.sh
cfg.sh文件的内容
auto/configure –prefix=/usr/local/nginx \
–with-pcre=../pcre-8.39 \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_flv_module \
–with-http_mp4_module \
–add-module=../nginx-rtmp-module/
chmoda+xcfg.sh
c
h
m
o
d
a
+
x
c
f
g
.
s
h
./cfg.sh
make
m
a
k
e
make install
启动nginx服务器
/usr/local/nginx/sbin/nginx
配置nginx
在nginx的配置文件nginx.conf最后添加如下信息
RMTP的服务器配置信息
rtmp {
server {
listen 2016; #推流的监听端口
publish_time_fix on;
# 推流其一
application live {
live on; #stream on live allow
allow publish all; # control access privilege
allow play all; # control access privilege
}
#推流其二
application hls_alic {
live on;
hls on;
hls_path /home/alic/www/hls;
hls_fragment 5s;
}
}
}
重新加载nginx的配置
$ /usr/local/nginx/sbin/nginx -s reload
简单的测试demo
安装ffmpag
add−apt−repositoryppa:kirillshkrogalev/ffmpeg−next
a
d
d
−
a
p
t
−
r
e
p
o
s
i
t
o
r
y
p
p
a
:
k
i
r
i
l
l
s
h
k
r
o
g
a
l
e
v
/
f
f
m
p
e
g
−
n
e
x
t
apt-get update
$ apt-get install ffmpeg
使用ffmpeg向服务器推送一个视频
ffmpeg -re -i /home/alic/Desktop/demo/film.mp4 -c copy -f flv rtmp://localhost:2016/live/film
or
推荐 可用于浏览器播放
ffmpeg -re -i /home/alic/Desktop/demo/film.mp4 -c copy -f flv rtmp://localhost:2016/hls_alic/film
参考:https://blog.youkuaiyun.com/jiabailong/article/details/76087611