linux下使用nginx-http-flv-module转发码流,web使用flv.js直播码流。
摘要:
1、linux下 rtsp / rtmp 转 rtmp / http-flv 流;
2、html上使用flv.js直播。
安装环境
有两种方式(自安装环境,使用docker包(推荐)):
一、自己安装nginx + nginx-http-flv-module
1、搭建nginx + nginx-http-flv-module模块
1)新建安装目录
mkdir installnginx cd installnginx
2)下载安装需要内容(可以按照需要修改版本到最新版)
wget http://nginx.org/download/nginx-1.13.4.tar.gz wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz wget http://www.zlib.net/zlib-1.2.11.tar.gz wget https://astuteinternet.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz git clone https://github.com/winshining/nginx-http-flv-module.git
3)解压
tar -zxvf 每个包.tar.gz
解压后含有:
4)安装
cd nginx-1.13.4 ./configure --prefix=/home/looham/nginx --add-module=../nginx-http-flv-module --with-pcre=../pcre-8.38 --with-openssl=../openssl-1.0.2l --with-zlib=../zlib-1.2.11 make && make install
5)遇到的错误说明
1:nginx-http-flv-module包括nginx-rtmp-module全部功能,不需要下载两个包,链接两个包编不过。
2:错误:“src/os/unix/ngx_user.c:26:7: error: ‘struct crypt_data’ has no member named ‘current_salt’”
在源码中找到这个文件所在行,把这个‘struct crypt_data’注释掉就解决了。
3:[-Werror=unused-but-set-variable]
修改 obj/Makefile 删除里面的 -Werror
二、直接使用docker包(推荐):
docker : nginx-http-flv-module
方式一(Pull仓库镜像):
docker pull mycujoo/nginx-http-flv-module docker images docker run -d -p 1965:1965 -p 8181 --name http-flv mycujoo/nginx-http-flv-module:latest docker exec -it http-flv sh
方式二(本地镜像):
备用地址: https://pan.baidu.com/s/1oqOMpRkURl9NmHL5Oudrng 提取码: wqdb
docker load -i nginx-http-flv-module.tar docker images docker run -d -p 1965:1965 -p 8181 --name http-flv mycujoo/nginx-http-flv-module:latest docker exec -it http-flv sh
记录一下:load镜像之后修改/etc/profile的环境变量发现无法生效,可以重新加载镜像直接修改env(加装python)
docker run -it --name http-flv -p 8181:8181 -p 1965:1965 -v /home/looham:/home --env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/python2.7/bin -d mycujoo/nginx-http-flv-module
服务运行
一、修改nginx配置文件:
daemon off; error_log /var/log/nginx/error.log warn; events { worker_connections 1024; } rtmp{ server { listen 1965; application live { live on; } } } http { server { listen 8181; server_name localhost; 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'; } } }
(添加头同时解决视频流跨域问题)
重启nginx
查看端口 netstat -aptn
二、FFmpeg 转流
1、安装FFmpeg(使用docker环境跳过该步骤)
wget https://ffmpeg.org/releases/ffmpeg-4.2.3.tar.bz2 tar jxf ffmpeg-4.2.3.tar.bz2 ./configure --enable-shared --prefix=/home/looham/ffmpeg --disable-yasm make make install
–prefix表示程序安装的目录,这里设为/home/looham/ffmpeg。
–enable-shared表示生成动态链接库,可以供以后编程使用,同时生成的可执行程序也依赖这些动态库。
–disable-yasm表示禁用yasm。
如果不禁用yasm 就会报错
ffmpeg -i "rtsp/rtmp源地址" copy -acodec copy -f flv rtmp://localhost:1965/live/mystream
FFmpeg安装问题见文章底部连接
显示结果
一、VLC显示rtmp流
rtmp://localhost:1965/live/mystream
二、flv.js播放
1、先使用VLC检查http-flv流是否正常
http://localhost:8181/live?port=1965&app=live&stream=mystream
再使用flv.js提供的DEMO测试
http://bilibili.github.io/flv.js/demo/
感谢
RzzZ的博客:记录RTSP通过FFmpeg+nginx发布成rtmp和http-flv
https://blog.csdn.net/qq_22633333/article/details/96288603
我是小超斌的博客:Linux下安装ffmpeg
https://blog.csdn.net/qq_39436605/article/details/82755588
- 基于nginx-rtmp-module模块实现的基于HTTP协议的FLV直播模块(nginx-http-flv-module)
- 在windows 7 64位 环境下使用nginx的nginx-http-flv-module搭建flv视频流播放(全过程)
- 分布式直播系统(六)【基于nginx-rtmp-module实现的最简洁高效http-flv服务】
- 使用NGiNX_HTTP_Push_Module实现简单的服务器推送
- 使用Nginx-rtmp-module搭建hls直播
- Nginx的 NginxHttpMemcModule的使用
- 【nginx】使用HTTP核心模块配置一个静态WEB服务器
- 使用rewrite 让php 实现类似asp.net 的IHttpModule 进行带参数js文件的参数获取
- [linux] Nginx编译安装错误error: the HTTP rewrite module requires the PCRE library
- nginx https配置详解,linxu环境nginx下http升级到https——linux安装web服务器17
- nginx 在window编译 HTTP-FLV直播模块
- Nginx之http_image_filter_module模块使用
- Nginx性能统计模块http_stub_status_module使用
- Nginx的 http_image_filter_module 模块使用说明
- nginx http_gzip_static_module 扩展压缩模块的简单使用
- 使用windos电脑模拟搭建集群(四)web环境 linux+nginx+jdk+tomcat
- nginx自定义负载均衡_端口转发——webhttp配置nginx.conf
- Nginx-http-flv-module
- javascript attachEvent和addEventListener 使用方法--http://www.diybl.com/course/1_web/javascript/jsjs/20071226/94592.html
- Linux下web性能测试工具http_load介绍及使用教程