nginx-rtmp流媒体服务器搭建

下载安装 Nginx 和 nginx-rtmp 编译依赖工具

1
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
1
2
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

下载 Nginx 和 nginx-rtmp源码

1
2
wget http://nginx.org/download/nginx-1.15.3.tar.gz
git clone https://github.com/arut/nginx-rtmp-module

添加 nginx-rtmp 模块编译到 Nginx

1
2
3
4
5
tar -zxvf nginx-1.15.3.tar.gz
cd nginx-1.15.3
./configure --prefix=/data/server/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module
make
make install

安装 Nginx Init 脚本,启动和停止 Nginx 服务

1
2
3
4
5
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
sudo service nginx start
sudo service nginx stop

直接启动和停止 Nginx 服务

1
2
3
4
5
6
7
8
9
10
11
/data/server/nginx/sbin/nginx  //启动Nginx
/data/server/nginx/sbin/nginx -s reload //修改配置后重新加载生效 /data/server/nginx/sbin/nginx -s reopen //重新打开日志文件

/data/server/nginx/sbin/nginx -s stop //快速停止Nginx
/data/server/nginx/sbin/nginx -s quit //完整有序的停止Nginx

# killall nginx //杀死全部Nginx进程
# ps -ef | grep nginx 或 ps aux | grep Nginx
# kill -QUIT 主进程号 //从容停止Nginx
# kill -TERM 主进程号 //快速停止Nginx
# kill -9 主进程号 //强制停止Nginx

安装 FFmpeg

1
2
3
./configure --disable-yasm --prefix=/usr/local/ffmpeg
make
make install
1
2
3
4
5
6
7
8
9
10
11
12
# ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/ffmpeg
# ffmpeg -version
ffmpeg version 2.8.8 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --disable-yasm --prefix=/usr/local/ffmpeg
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101

配置 nginx-rtmp 服务器

打开 /data/server/nginx/conf/nginx.conf,在末尾添加如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
rtmp {
server {
listen 88;
chunk_size 4096;

application live {
live on;
record off;
exec /usr/local/ffmpeg/bin/ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name;
}
application live360p {
live on;
record off;
}
}
}

保存配置文件,然后重新启动 Nginx 服务

注意:如果使用了防火墙,请允许端口 tcp 1935

客户端使用 rtmp协议进行视频实时采集

推流

推流地址:rtmp://www.yezhou.me:8888/live/yezhou

Field 1: rtmp://your.vultr.ip/live/

Field 2: stream-key-your-set

拉流

使用网页Flash播放器:http://www.yezhou.me/live/

使用ffplay播放RTMP直播流:ffplay rtmp://www.yezhou.me:8888/live/yezhou

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :