在car-eye JT1078 平台开发中可能遇到实时视频忘记关闭的情况,设备一直在推流在移动系统中是完全不可以接受的。 为止,我们需要自动监控设备的推流和拉流情况,RTMP服务器提供了基于json格式的输出,用来表达有多少个客户端连接。但客户端观看为0的时候,平台自动关闭这个设备流/
{"http-flv":{"nginx_version":"1.12.2","nginx_http_flv_version":"1.2.5","compiler":"gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ","built":"Nov 11 2018 23:58:51","pid":16265,"uptime":238184,"naccepted":27162,"bw_in":178848,"bytes_in":8709208744,"bw_out":259496,"bytes_out":6676436554,"servers":[[{"name":"live","live":{"streams":[{"name":"13826559865&channel=1","time":1847784,"bw_in":76648,"bytes_in":17433318,"bw_out":153296,"bytes_out":18198938,"bw_audio":24488,"bw_video":52152,"clients":[{"id":36315,"address":"119.123.132.126","time":21270,"dropped":0,"avsync":-67,"timestamp":1856075,"publishing":false,"active":true},{"id":36224,"address":"120.76.235.109","time":1846857,"dropped":0,"avsync":-67,"timestamp":1856075,"publishing":true,"active":true},{"id":36215,"address":"119.123.132.126","time":1921313,"flashver":"WIN 25,0,0,127","pageurl":"http://liveoss.com:8088/common/vedio_rtmp/index.jsp","swfurl":"http://vjs.zencdn.net/swf/5.4.0/video-js.swf","dropped":0,"avsync":-67,"timestamp":1856075,"publishing":false,"active":true}],"meta":{"video":{"width":352,"height":288,"frame_rate":15,"codec":"H264","profile":"Baseline","level":"2.0"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":3,"publishing":true,"active":true},{"name":"13826559865&channel=2","time":16521,"bw_in":71056,"bytes_in":136982,"bw_out":71024,"bytes_out":136949,"bw_audio":23640,"bw_video":47416,"clients":[{"id":36319,"address":"120.76.235.109","time":16361,"dropped":0,"avsync":-67,"timestamp":16478,"publishing":true,"active":true},{"id":36318,"address":"119.123.132.126","time":16766,"dropped":0,"avsync":-67,"timestamp":16478,"publishing":false,"active":true}],"meta":{"video":{"width":352,"height":288,"frame_rate":15,"codec":"H264","profile":"Baseline","level":"2.0"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":2,"publishing":true,"active":true},{"name":"13826559865&channel=3","time":8707,"bw_in":0,"bytes_in":3154217,"bw_out":0,"bytes_out":3154183,"bw_audio":0,"bw_video":0,"clients":[{"id":36326,"address":"120.76.235.109","time":7922,"dropped":0,"avsync":0,"timestamp":8088,"publishing":true,"active":true},{"id":36325,"address":"119.123.132.126","time":8976,"dropped":0,"avsync":0,"timestamp":8088,"publishing":false,"active":true}],"meta":{"video":{"width":1280,"height":720,"frame_rate":15,"codec":"H264","profile":"Main","level":"3.1"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":2,"publishing":true,"active":true},{"name":"13826559865&channel=4","time":11457,"bw_in":99712,"bytes_in":135168,"bw_out":99688,"bytes_out":135135,"bw_audio":23640,"bw_video":76072,"clients":[{"id":36324,"address":"120.76.235.109","time":11315,"dropped":0,"avsync":0,"timestamp":11535,"publishing":true,"active":true},{"id":36323,"address":"119.123.132.126","time":11715,"dropped":0,"avsync":0,"timestamp":11535,"publishing":false,"active":true}],"meta":{"video":{"width":352,"height":288,"frame_rate":15,"codec":"H264","profile":"Baseline","level":"2.0"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":2,"publishing":true,"active":true}],"nclients":9}},{"name":"hls","live":{"streams":[],"nclients":0}},{"name":"dash","live":{"streams":[],"nclients":0}}]]}}
当客户端关闭后,输出成了:
{"http-flv":{"nginx_version":"1.12.2","nginx_http_flv_version":"1.2.5","compiler":"gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ","built":"Nov 11 2018 23:58:51","pid":16265,"uptime":238245,"naccepted":27162,"bw_in":3651312,"bytes_in":8734380791,"bw_out":2241448,"bytes_out":6699562368,"servers":[[{"name":"live","live":{"streams":[{"name":"13826559865&channel=1","time":1908170,"bw_in":77784,"bytes_in":17968274,"bw_out":136824,"bytes_out":19208463,"bw_audio":24776,"bw_video":53008,"clients":[{"id":36224,"address":"120.76.235.109","time":1907243,"dropped":0,"avsync":-67,"timestamp":1916777,"publishing":true,"active":true},{"id":36215,"address":"119.123.132.126","time":1981699,"flashver":"WIN 25,0,0,127","pageurl":"http://liveoss.com:8088/common/vedio_rtmp/index.jsp","swfurl":"http://vjs.zencdn.net/swf/5.4.0/video-js.swf","dropped":0,"avsync":-67,"timestamp":1916777,"publishing":false,"active":true}],"meta":{"video":{"width":352,"height":288,"frame_rate":15,"codec":"H264","profile":"Baseline","level":"2.0"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":2,"publishing":true,"active":true},{"name":"13826559865&channel=2","time":76907,"bw_in":72064,"bytes_in":632811,"bw_out":27128,"bytes_out":576120,"bw_audio":24488,"bw_video":47568,"clients":[{"id":36319,"address":"120.76.235.109","time":76747,"dropped":0,"avsync":0,"timestamp":77113,"publishing":true,"active":true}],"meta":{"video":{"width":352,"height":288,"frame_rate":15,"codec":"H264","profile":"Baseline","level":"2.0"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":1,"publishing":true,"active":true},{"name":"13826559865&channel=3","time":69093,"bw_in":3388720,"bytes_in":26514758,"bw_out":2000688,"bytes_out":23988175,"bw_audio":24488,"bw_video":3364224,"clients":[{"id":36326,"address":"120.76.235.109","time":68308,"dropped":0,"avsync":0,"timestamp":68790,"publishing":true,"active":true}],"meta":{"video":{"width":1280,"height":720,"frame_rate":15,"codec":"H264","profile":"Main","level":"3.1"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":1,"publishing":true,"active":true},{"name":"13826559865&channel=4","time":71843,"bw_in":101608,"bytes_in":832485,"bw_out":93896,"bytes_out":752979,"bw_audio":24488,"bw_video":77112,"clients":[{"id":36324,"address":"120.76.235.109","time":71701,"dropped":0,"avsync":0,"timestamp":72237,"publishing":true,"active":true}],"meta":{"video":{"width":352,"height":288,"frame_rate":15,"codec":"H264","profile":"Baseline","level":"2.0"}, "audio": {"codec":"AAC","profile":"LC","channels":"1","sample_rate":8000}},"nclients":1,"publishing":true,"active":true}],"nclients":5}},{"name":"hls","live":{"streams":[],"nclients":0}},{"name":"dash","live":{"streams":[],"nclients":0}}]]}}
其中客户端nclients变成1代表这个通道已经没有客户端进行连接。此时需要设置超时后进行自动关闭。
相关功能在car-eye 车辆管理平台已经实现:
https://github.com/Car-eye-team/Car-eye-JTT808-1078-platform