赞
踩
点击下载《Linux环境傻瓜式nginx+rtmp+ffmpeg套餐安装详解(获取拉流人数)》
点击下载《Java 使用javaCV、ffmpeg拉流H265 RTSP转推H264 RTMP可获取流访问人数(源代码)》
进入下载地址:https://github.com/arut/nginx-rtmp-module,并下载压缩包,如下图所示:
1、下载完成后,在windows系统下解压,然后将解压后的文件夹上传到linux系统下,我把它放在/root/soft-install/nginx,如下图:
1、下载地址:http://nginx.org/en/download.html,选择需要的版本下载即可,如下图:
2、这里我下载的是nginx-1.16.1,下载后上传到Linux系统目录,我把它放在/root/soft-install/nginx,如下图:
3、在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel,运行命令:yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel,结果如下图所示:
4、进入/root/soft-install/nginx目录,并解压,依次执行命令为:
cd /root/soft-install/nginx
tar -xvf nginx-1.16.1.tar.gz
5、编译安装nginx,并指定上面下载的rtmp模块路径,命令为:
(1)安装依赖包,依次执行以下两条命令:
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
如果出现:Cannot prepare internal mirrorlist: No URLs in mirrorlist
则依次执行以下两条命令:
sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
(2)编译安装nginx,并指定上面下载的rtmp模块路径,执行命令:
./configure --add-module=../nginx-rtmp-module-master --with-http_ssl_module --with-http_ssl_module --with-http_xslt_module --with-http_flv_module --with-debug --with-http_gzip_static_module
执行成功如下图所示:
6、运行cd conf,进入nginx配置文件目录,修改nginx.conf文件,共需要添加两处配置,
(1)第一步在文件末尾加上下面配置信息:
- #文件末尾追加
-
- rtmp {
-
- server {
-
- listen 1935; #监听的端口
-
- chunk_size 4000;
-
- # rtmp推流请求路径
-
- application hls {
-
- live on;
-
- hls on;
-
- hls_path /usr/tmp/hls;
-
- hls_fragment 10s;
-
- }
-
- }
-
- }
(2)在http->server节点下增加推流目录的访问权限配置:
- location /hls {
- alias /usr/tmp/hls; #该目录对应rtmp 配置中的hls_path即可
- autoindex on; # 开启目录文件列表
- autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes
- autoindex_localtime on; # 显示的文件时间为文件的服务器时间
- charset utf-8,gbk; # 避免中文乱码
- }
7、执行命令:cd .. && make && make install,执行成功如下图所示:
8、执行命令:cd /usr/local/nginx跳转至nginx的安装目录,然后执行命令:./sbin/nginx -t测试配置文件是否有问题,如下图所示:
9、执行命令:./sbin/nginx,启动nginx,执行该命令无错误显示的话默认是没有任何信息显示的,如下图:
10、在浏览器中输入linux的ip地址检查nginx启动页面是否可访问,正常访问成功如下图所示:
1、执行命令:ps -ef | grep nginx,查看nginx是否成功运行了,如下图所示:
2、运行命令:lsof -i:80(或者netstat -lnt | grep 80)检查nginx是否已启动监听端口(nginx默认端口为80,如果你自己想改成其他的,则检查端口时相应的更改),正常情况如下图所示:
3、执行命令:firewall-cmd --add-port=80/tcp --permanent将80端口加入防火墙(nginx默认端口为80,如果你自己想改成其他的,则添加端口时相应的更改),然后执行命令:systemctl restart firewalld重启防火墙,如下图所示:
4、查看nginx的端口方法,执行命令:cd /usr/local/nginx/conf/,打开nginx.conf,nginx端口配置位置如下图所示:
5、按照以上步骤做完,你的nginx应该也已经启动了,如果没有启动,那就全部重新来过。
1、在nginx配置中增加如下配置:放在http->server节点下
- location /stat {
- rtmp_stat all;
- allow 127.0.0.1;
- }
-
- location /nclients {
- proxy_pass http://127.0.0.1/stat;
- xslt_stylesheet /usr/local/nginx/html/nclients.xsl app='$arg_app' name='$arg_name';
- #add_header Refresh "3; $request_uri";
- }
2、在/usr/local/nginx/html/目录下新建文件nclients.xsl,并录入以下内容:
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html"/>
- <xsl:param name="app"/>
- <xsl:param name="name"/>
- <xsl:template match="/">
- <xsl:value-of select="count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])"/>
- </xsl:template>
- </xsl:stylesheet>
3、重启nginx。
4、在ffmpeg安装成功后,并进行推流,然后再网页中输入地址:
说明:
application下的name(即hls)指的是应用名称,对应nginx配置的rtmp中的hls
stream下的name(即3a0f53c551d946b6b48b9a54c2509b07)指的是推流名称
client节点信息即当前拉流的客户端信息
5、完整的nginx配置文件nginx.conf内容如下:
-
- #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;
- }
-
-
- http {
- include mime.types;
- default_type application/octet-stream;
-
- sendfile on;
- #tcp_nopush on;
-
- #keepalive_timeout 0;
- keepalive_timeout 65;
-
- #gzip on;
-
- server {
- listen 80;
- server_name localhost;
-
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
-
- location / {
- root html;
- index index.html index.htm;
- }
-
- location /hls {
- alias html/hls;
- index index.html index.htm;
-
- if ($request_method = 'OPTIONS') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- #
- # Custom headers and headers various browsers *should* be OK with but aren't
- #
- add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
- #
- # Tell client that this pre-flight info is valid for 20 days
- #
- add_header 'Access-Control-Max-Age' 1728000;
- add_header 'Content-Type' 'text/plain; charset=utf-8';
- add_header 'Content-Length' 0;
- return 200;
- }
- if ($request_method = 'POST') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
- add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
- }
- if ($request_method = 'GET') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
- add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
- }
- }
-
- location /stat {
- rtmp_stat all;
- allow 127.0.0.1;
- }
-
- location /nclients {
- proxy_pass http://127.0.0.1/stat;
- xslt_stylesheet /usr/local/nginx/html/nclients.xsl app='$arg_app' name='$arg_name';
- #add_header Refresh "3; $request_uri";
- }
-
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- server
- {
- listen 9999;
- add_header Access-Control-Allow-Origin *;
- #HLS配置开始,这个配置为了客户端能够以http协议获取HLS的拉流
- location /hls {
- add_header Access-Control-Allow-Origin *;
- types {
- application/vnd.apple.mpegurl m3u8;
- video/mp2t ts;
- }
- alias html/hls; #跟上面的hls_path路径对应
- expires -1;
-
- if ($request_method = 'OPTIONS') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- #
- # Custom headers and headers various browsers *should* be OK with but aren't
- #
- add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
- #
- # Tell client that this pre-flight info is valid for 20 days
- #
- add_header 'Access-Control-Max-Age' 1728000;
- add_header 'Content-Type' 'text/plain; charset=utf-8';
- add_header 'Content-Length' 0;
- return 200;
- }
- if ($request_method = 'POST') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
- add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
- }
- if ($request_method = 'GET') {
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
- add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
- }
- }
- }
- }
-
- rtmp {
- server {
- listen 1935; #监听的端口
- chunk_size 4000;
- # rtmp推流请求路径
- application hls {
- live on;
- hls on;
- hls_path /usr/local/nginx/html/hls;
- hls_fragment 10s;
- hls_playlist_length 300;
- }
- }
- }
1、打开官网地址,进入下载页:https://ffmpeg.org/download.html#build-linux,如下图所示:
2、点击跳转后,点击最新版本进行下载(这里下载的是免安装版,一般情况已够用),如下图所示:
3、官网下载贼慢,慢慢等吧。
4、下载完,将下载后的文件上传到linux目录下,执行解压命令:
tar -xvf ffmpeg-release-amd64-static.tar.xz,如下图所示:
5、解压完后,进入到解压后的目录,可以看到已经有ffmpeg执行文件了,如下图所示:
6、执行推流命令,试试看推流效果吧,ffmpeg命令请自行上网查,我推送的为ffmpeg目录下的一个mp4文件,命令为:./ffmpeg -i 1.mp4 -f flv rtmp://192.168.2.246:1935/hls/001,执行结果如下图所示:
7、使用vlc播放器打开推流地址进行查看推流视频,如下图所示:
点击下载《Linux环境傻瓜式nginx+rtmp+ffmpeg套餐安装详解(获取拉流人数)》
点击下载《Java 使用javaCV、ffmpeg拉流H265 RTSP转推H264 RTMP可获取流访问人数(源代码)》
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。