Ubuntu安装nginx-http-flv,并获取统计信息

1、依赖安装

复制代码
sudo apt-get install build-essential
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install libssl-dev
sudo apt-get install zlib1g
sudo apt-get install zlib1g-dev

2、源码下载

NGINX 的版本应该大于或者等于 1.2.6,与其他版本的兼容性未知。nginx下载地址:http://nginx.org/download/。nginx-http-flv使用最新版本就可以,这里使用的nginx版本是1.14.2。

复制代码
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf  nginx-1.14.2.tar.gz
git clone https://github.com/winshining/nginx-http-flv-module.git

3、编译安装

复制代码
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=../nginx-http-flv-module
make -j
make install

4、修改配置文件

修改/usr/local/nginx/conf/nginx.conf添加rtmp服务:

复制代码
rtmp {
	server {
		listen 1935;
		chunk_size 4000;
		application rtmp-live {
			live on;
	   }  
	}

}

修改http服务:

复制代码
http {
    ...
    server {
        listen       80;
        ...
		#开启flv
		location /live {
			flv_live on;
			chunked_transfer_encoding on;
		}
		#获取统计信息
		location /stat {
			rtmp_stat all;

			# Use this stylesheet to view XML as web page
			# in browser
			rtmp_stat_format json;
		}
		#control
		location /control {
			rtmp_control all;
		}
		...
    }
}

5、启动

执行

复制代码
/usr/local/nginx/sbin/nginx

6、测试

复制代码
ffmpeg -re -i test.mp4 -vcodec copy -acodec copy -f flv rtmp://127.0.0.1:1935/rtmp-live/test

rtmp仅支持H264/AAC,如果媒体不是H264/AAC,请使用下面的命令

复制代码
ffmpeg -i test.mp4 -vcodec libx264 -acodec fdk-aac -f flv rtmp://127.0.0.1:1935/rtmp-live/test

使用VLC播放视频:

rtmp播放地址:rtmp://127.0.0.1:1935/rtmp-live/test

http-flv播放地址:http://127.0.0.1:80/live?app=rtmp-live&stream=test

7、获取rtmp服务器统计信息

复制代码
curl 127.0.0.1:80/stat

返回json格式的数据,记录了rtmp server的连接情况:

复制代码
{
    "http-flv": {
        "nginx_version": "1.14.2",
        "nginx_http_flv_version": "1.2.11",
        "compiler": "gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) ",
        "built": "Mar 26 2024 13:37:56",
        "pid": 10099,
        "uptime": 2748,
        "naccepted": 13,
        "bw_in": 2160784,
        "bytes_in": 92153201,
        "bw_out": 0,
        "bytes_out": 20844554,
        "servers": [{
                "port": 1935,
                "server_index": 0,
                "applications": [{
                        "name": "rtmp-live",
                        "live": {
                            "streams": [{
                                    "name": "test",
                                    "time": 52043,
                                    "bw_in": 2142224,
                                    "bytes_in": 12709114,
                                    "bw_out": 0,
                                    "bytes_out": 0,
                                    "bw_audio": 0,
                                    "bw_video": 2142224,
                                    "clients": [{
                                            "id": 35,
                                            "address": "127.0.0.1",
                                            "time": 52267,
                                            "flashver": "FMLE/3.0 (compatible; Lavf58.20.100)",
                                            "dropped": 0,
                                            "avsync": -52051,
                                            "timestamp": 52051,
                                            "publishing": true,
                                            "active": true
                                        }
                                    ],
                                    "records": [],
                                    "meta": {
                                        "video": {
                                            "width": 1920,
                                            "height": 1080,
                                            "frame_rate": 24.828,
                                            "codec": "H264",
                                            "profile": "High",
                                            "level": 4.2
                                        },
                                        "audio": {}
                                    },
                                    "nclients": 1,
                                    "publishing": true,
                                    "active": true
                                }
                            ],
                            "nclients": 1
                        },
                        "recorders": {
                            "count": 0,
                            "lists": []
                        }
                    }
                ]
            }
        ]
    }
}

applications里面记录了流的连接情况。

相关推荐
国际云,接待14 分钟前
云服务器的运用自如
服务器·架构·云计算·腾讯云·量子计算
LunarCod2 小时前
Ubuntu使用Docker搭建SonarQube企业版(含破解方法)
linux·运维·服务器·ubuntu·docker·开源·sonarqube
noravinsc3 小时前
国产化中间件 替换 nginx
运维·nginx·中间件
惜.己3 小时前
Linux常用命令(十四)
linux·运维·服务器
BillKu4 小时前
服务器多JAR程序运行与管理指南
运维·服务器·jar
QQ2740287564 小时前
BlockMesh Ai项目 监控节点部署教程
运维·服务器·web3
ZHOU_WUYI4 小时前
使用 Docker 部署 React + Nginx 应用教程
nginx·react.js·docker
小疆智控5 小时前
数字化工厂升级引擎:Modbus TCP转Profinet网关助力打造柔性生产系统
服务器·网络·tcp/ip
南棱笑笑生5 小时前
20250512给NanoPi NEO core开发板在Ubuntu core20.04系统更新boot.img
linux·运维·ubuntu
XMYX-05 小时前
Linux du 命令终极指南:从基础到精通
linux·服务器