【入门】ffmpeg、nginx、nginx-http-flv-module转发rtsp流、VLC查看
参考:https://blog.csdn.net/string_kai/article/details/100598268
-
使用ffmpeg将rtsp转成rtmp
-
使用nginx中的nginx-http-flv-module 模块:
- 转发到rtmp的1935端口上
- 转发到http的80端口上
-
使用VLC查看
nginx安装 nginx-http-flv-module 模块并添加到nginx
1.clone nginx-http-flv-module :
cd /usr/local/src/
git clone https://github.com/winshining/nginx-http-flv-module.git
**2.将模块编译进 NGINX:**注意/usr/local/src/nginx-1.6.2
是下载解压nginx的位置,/usr/local/webserver/nginx
是nginx安装的位置,用来运行nginx
cd /usr/local/src/nginx-1.6.2 #nginx安装位置
./configure --prefix=/usr/local/webserver/nginx --add-module=/usr/local/src/nginx-http-flv-module
make
make install
3./usr/local/webserver/nginx/conf/nginx.conf
添加rtmp
和location /live
http {
server {
# rtsp -> flv
location /live {
flv_live on;
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header 'Cache-Control' 'no-cache';
}
}
}
rtmp {
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;
drop_idle_publisher 15s;
log_interval 5s; #interval used by log module to log in access.log, it is very useful for debug
log_size 1m; #buffer size used by log module to log in access.log
server {
listen 1935; #Nginx监听的RTMP推流/拉流端口
server_name localhost; #for suffix wildcard matching of virtual host name
application live {
live on;
gop_cache off; #open GOP cache for reducing the wating time for the first picture of video
}
}
}
4.重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
注意重新载入配置文件可能不成功。我在重新载入的时候1935端口并没有开启,实际可能需要关闭nginx,再开启:
/usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
/usr/local/webserver/nginx/sbin/nginx # 运行
hint:可以通过linux查看端口占用情况
lsof -i:1935
如果1935端口开启,会有类似如下的信息:
<