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里面记录了流的连接情况。

 

         我的开源:

         1、Nvidia视频硬解码、渲染、软/硬编码并写入MP4文件。项目地址:https://github.com/BreakingY/Nvidia-Video-Codec
        2、Jetson Jetpack5.x视频编解码。项目地址:https://github.com/BreakingY/jetpack-dec-enc
        3、音视频(H264/H265/AAC)封装、解封装、编解码pipeline,支持NVIDIA、昇腾DVPP硬编解码。项目地址:https://github.com/BreakingY/Media-Codec-Pipeline
        4、simple rtsp server,小而高效的rtsp服务器,支持H264、H265、AAC、PCMA;支持TCP、UDP;支持鉴权。项目地址:https://github.com/BreakingY/simple-rtsp-server

        5、simple rtsp client,rtsp客户端,支持TCP、UDP、H264、H265、AAC、PCMA,支持鉴权。项目地址:https://github.com/BreakingY/simple-rtsp-client

        6、libflv,flv muxer/demuxer,支持H264/H265、AAC。项目地址:https://github.com/BreakingY/libflv

        7、mpeg2 ts ps muxer/demuxer,支持H264/H265/MPEG1 audio/MP3/AAC/AAC_LATM/G711。项目地址:https://github.com/BreakingY/libmpeg2core

posted @   BreakingY  阅读(10)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示