提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
一、前言
FFmpeg是一款多媒体视频处理工具,有非常强大的功能包括:视频采集、视频推流、视频格式转换、视频抓图、给视频加水印等功能。
最近有项目需求需要把监控摄像机的RTSP流放在浏览器上播放,也是研究了以下,最後也是用nginx+ffmpeg大概实现了一下,特此记录一下。
1. 安装nginx
注意:已安装好nginx, nginx -V 查看是否有 nginx-http-flv-module-master模块,如果没有需要重新编译安装,或重新部署新的nginx
官网下载地址:http://nginx.org/en/download.html
解压:tar -zxvf "对应版本".tar.gz
安装依赖:yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
下载 nginx rtmp 服务 https://github.com/winshining/nginx-http-flv-module.git
上传服务器 解压好 如:unzip nginx-http-flv-module-master.zip
编译安装: add-module部分是nginx-http-flv-module-master.zip解压的位置
./configure --prefix=/opt/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_random_index_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-pcre \
--add-module=/data/nginx-http-flv-module-master
执行 make && make install 命令
make && make install
进入到
cd /opt/nginx/sbin
以下操作命令:
./nginx 启动
./nginx -s stop 关闭
./nginx -s reload 重启
nginx 配置文件:这一部分主要是在nginx配置文件中添加RTMP服务
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
# 添加RTMP服务
rtmp {
server { #此为rtmp推流开启的端口
listen 1935; # 推流使用的端口,默认1935端口在推流时可以省略,改为其他端接口需要自行指定
chunk_size 4000;
application live {
live on; #开启直播
gop_cache on;
}
}
#一个rtsp流对应一个端口,需要实现多个推流可以定义多个server改变不同的端口
}
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 {
listen 8081;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /stat.xsl {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /live {
flv_live on;
ch