nginx-rtmp流媒体服务器搭建

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

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

下载 Nginx 和 nginx-rtmp源码

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

添加 nginx-rtmp 模块编译到 Nginx

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 服务

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 服务

/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

./configure --disable-yasm --prefix=/usr/local/ffmpeg
make
make install
# 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,在末尾添加如下

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

上一篇 编译WebRTC for Android
下一篇 高中数学基础:集合与函数
目录
文章列表
1 设计模式(20)适配器模式
设计模式(20)适配器模式
2
Spring Cloud Gateway自定义过滤器进行限流
Spring Cloud Gateway自定义过滤器进行限流
3
Laravel使用Bcrypt加密方式存储及校验密码
Laravel使用Bcrypt加密方式存储及校验密码
4
Spring Boot之Web综合开发
Spring Boot之Web综合开发
5
React Native实战之运行官方项目f8app(适配IOS_Mac)
React Native实战之运行官方项目f8app(适配IOS_Mac)
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。