Monica视频监控处理程序
xc
2021-04-29 bf17d1c5c8270cb8dbd28ea246336509c05c9f44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package com.hbbh.adapter;
 
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.hbbh.adapter.utils.HttpClientUtil;
import org.junit.jupiter.api.Test;
 
import java.util.List;
import java.util.Map;
/*
 
@Deprecated
public class HttpClientUtilTest {
 
 
    */
/**
     * GET /api/instance/create?path=E:\store\live&name=live&info=%5BMonibuca%5D%0A%23%20%E6%98%AF%E5%90%A6%E7%AD%89%E5%BE%85%E6%B5%81%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%BAtrue%E5%88%99%E8%AE%A2%E9%98%85%E4%B8%80%E4%B8%AA%E5%B0%9A%E6%9C%AA%E5%8F%91%E5%B8%83%E7%9A%84%E6%B5%81%E4%BC%9A%E8%BF%9B%E5%85%A5%E7%AD%89%E5%BE%85%E5%8F%91%E5%B8%83%E7%9A%84%E7%8A%B6%E6%80%81%EF%BC%8C%E5%90%A6%E5%88%99%E8%BF%94%E5%9B%9E%E8%AE%A2%E9%98%85%E5%A4%B1%E8%B4%A5%0AEnableWaitStream%20%3D%20true%0AEnableAudio%20%3D%20true%0AEnableVideo%20%3D%20true%0A%23%20%E7%BC%93%E5%86%B2%E7%8E%AF%E5%A4%A7%E5%B0%8F%E9%BB%98%E8%AE%A4%E6%98%AF2%E7%9A%8410%E6%AC%A1%E6%96%B9%0ARingSize%20%3D%2010%0A%23%20%E5%8F%91%E5%B8%83%E6%B5%81%E9%BB%98%E8%AE%A4%E8%BF%87%E6%9C%9F%E6%97%B6%E9%97%B4%201%E5%88%86%E9%92%9F%0APublishTimeout%20%3D%2060000000000%0A%5BRTSP%5D%0A%23%20%E7%AB%AF%E5%8F%A3%E6%8E%A5%E6%94%B6%E6%8E%A8%E6%B5%81%0AListenAddr%20%3D%20%22%3A554%22%0A%23%20%E5%BC%80%E5%90%AF%E8%87%AA%E5%8A%A8%E6%8B%89%E6%B5%81%E5%90%8E%EF%BC%8C%E4%B8%80%E6%97%A6%E6%9C%89%E8%AE%A2%E9%98%85%E6%B5%81%EF%BC%8C%E5%B0%B1%E4%BC%9A%E4%BB%8ERemoteAddr%E8%BF%9B%E8%A1%8C%E6%8B%89%E6%B5%81%0AAutoPull%20%3D%20false%0AReconnect%20%3D%20true%0A%23%20%E8%BF%9C%E7%A8%8B%E5%9C%B0%E5%9D%80%E9%85%8D%E5%90%88AutoPull%E9%85%8D%E7%BD%AE%E8%B5%B7%E4%BD%9C%E7%94%A8%0ARemoteAddr%20%3D%20%22rtsp%3A%2F%2Fadmin%3Aadmin%40192.168.1.212%3A554%2Fcam%2Frealmonitor%3Fchannel%3D1%26subtype%3D1%22%0A%23%20%E5%8F%91%E5%B8%83%E6%B5%81%E7%9A%84%E5%90%8D%E7%A7%B0%E9%85%8D%E5%90%88AutoPull%E9%85%8D%E7%BD%AE%E8%B5%B7%E4%BD%9C%E7%94%A8%20%E8%BF%9C%E7%A8%8B%E6%8B%89%E6%B5%81%E5%90%8E%E5%9C%A8%E6%9C%AC%E5%9C%B0%E8%B5%B7%E7%9A%84%E6%B5%81%E5%90%8D%E7%A7%B0%0AStreamPath%20%3D%20%22live%2Frtsp%22%0A%23%5B%5BRTSP.AutoPullList%5D%5D%0A%23URL%20%3D%20%22rtsp%3A%2F%2Fadmin%3Aadmin%40192.168.1.212%3A554%2Fcam%2Frealmonitor%3Fchannel%3D1%26subtype%3D1%22%0A%23StreamPath%20%3D%20%22live%2Frtsp2%22&clear=true HTTP/1.1
     * Host: 192.168.1.109:3000
     * Connection: keep-alive
     * Pragma: no-cache
     * Cache-Control: no-cache
     * Accept: text/event-stream
     * User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36
     * Referer: http://192.168.1.109:3000/
     * Accept-Encoding: gzip, deflate
     * Accept-Language: zh-CN,zh;q=0.9
     * <p>
     * path: E:\store\live
     * name: live
     * info: [Monibuca]
     * # 是否等待流,如果为true则订阅一个尚未发布的流会进入等待发布的状态,否则返回订阅失败
     * EnableWaitStream = true
     * EnableAudio = true
     * EnableVideo = true
     * # 缓冲环大小默认是2的10次方
     * RingSize = 10
     * # 发布流默认过期时间 1分钟
     * PublishTimeout = 60000000000
     * [RTSP]
     * # 端口接收推流
     * ListenAddr = ":554"
     * # 开启自动拉流后,一旦有订阅流,就会从RemoteAddr进行拉流
     * AutoPull = false
     * Reconnect = true
     * # 远程地址配合AutoPull配置起作用
     * RemoteAddr = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=1&subtype=1"
     * # 发布流的名称配合AutoPull配置起作用 远程拉流后在本地起的流名称
     * StreamPath = "live/rtsp"
     * #[[RTSP.AutoPullList]]
     * #URL = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=1&subtype=1"
     * #StreamPath = "live/rtsp2"
     * clear: true
     *//*
 
    private String info = "[Monibuca]\n" +
            "# 是否等待流,如果为true则订阅一个尚未发布的流会进入等待发布的状态,否则返回订阅失败\n" +
            "EnableWaitStream = true\n" +
            "EnableAudio = true\n" +
            "EnableVideo = true\n" +
            "# 缓冲环大小默认是2的10次方\n" +
            "RingSize = 10\n" +
            "# 发布流默认过期时间 1分钟\n" +
            "PublishTimeout = 60000000000\n" +
            "[RTMP]\n" +
            "ListenAddr = \":1935\"\n" +
            "[GateWay]\n" +
            "ListenAddr = \":8081\"\n" +
            "[Jessica]\n" +
            "ListenAddr = \":8080\"\n" +
            "[LogRotate]\n" +
            "# 日志存储目录相对或绝对\n" +
            "Path = \"logs\"\n" +
            "# 日志是否按大小分割,0表示不按大小分割,非零代表按该大小字节进行分割\n" +
            "Size = 0\n" +
            "Days = 1\n" +
            "[Cluster]\n" +
            "# 监听端口代表该服务器为源服务器\n" +
            "ListenAddr = \":2019\"\n" +
            "# 源服务器地址,用于向源服务器进行推或拉流\n" +
            "OriginServer = \"\"\n" +
            "# 推送模式,true表示如果此服务器有发布流,就会推送到源服务器,否则表示拉模式,即如果此服务器有订阅流则从源服务器拉流\n" +
            "Push = true\n" +
            "[HLS]\n" +
            "# 是否开启写磁盘,开启后侦测到发布流就会开始写TS文件\n" +
            "EnableWrite = false\n" +
            "# 是否打开内存模式,在内存中保留TS数据,方便直接读取\n" +
            "EnableMemory = false\n" +
            "# 分片大小 单位秒\n" +
            "Fragment = 10\n" +
            "# 窗口数里,代表一个m3u8文件里面有几个ts\n" +
            "Window = 2\n" +
            "# ts文件存放目录,m3u8会存放在上一级\n" +
            "Path = \"resource\"\n" +
            "[HDL]\n" +
            "ListenAddr = \":2020\"\n" +
            "[TS]\n" +
            "# 是否自动发布,开启后一旦有订阅流就会读取ts文件进行发布,方便测试\n" +
            "AutoPublish = false\n" +
            "# ts存放目录\n" +
            "Path  = \"resource\"\n" +
            "[Record]\n" +
            "Path = \"resource\"\n" +
            "# 是否自动发布,开启后一旦有订阅流就会读取flv文件进行发布,方便测试\n" +
            "AutoPublish = false\n" +
            "# 自动录制功能\n" +
            "AutoRecord  = false\n" +
            "[RTSP]\n" +
            "ListenAddr = \":554\"\n" +
            "AutoPull = true\n" +
            "Reconnect = true\n" +
            "RemoteAddr = \"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov\"\n" +
            "StreamPath = \"live/rtsp\"\n" +
            "#[[RTSP.AutoPullList]]\n" +
            "#URL = \"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov\"\n" +
            "#StreamPath = \"live/rtsp2\"\n" +
            "[WebRTC]\n" +
            "# 公网IP地址\n" +
            "PublicIP = [\"127.0.0.1\"]\n" +
            "# 端口范围不配置的话是自动分配\n" +
            "# PortMin = 30000\n" +
            "# PortMax = 40000\n" +
            "[GB28181]\n" +
            "Serial = \"34020000002000000001\"\n" +
            "Realm = \"3402000000\"\n" +
            "Expires = 3600\n" +
            "AutoInvite = false\n" +
            "ListenAddr = \"192.168.1.120:5060\"";
 
    @Test
    void init() {
        String result = createInstance();
        System.out.println(result);
        */
/*if (result.contains("success")) {
            startInstance();
        } else {
            //创建实例失败
            System.out.println("创建实例失败");
        }*//*
 
    }
 
    */
/**
     * 创建实例
     * GET
     *//*
 
    private String createInstance() {
        String url = "http://127.0.0.1:3000/api/instance/create";
        Map<String, String> params = Maps.newLinkedHashMap();
        params.put("path", "/Users/xucheng/Downloads/store/live");
        params.put("name", "live");
        params.put("info", info);
        params.put("clear", "true");
        String result = HttpClientUtil.doGet(url, params);
        return result;
    }
 
    */
/**
     * [{
     * "Name": "history",
     * "Path": "/Users/xucheng/Downloads/store/history",
     * "config": {
     * "Monibuca": {
     * "EnableWaitStream": true,
     * "EnableAudio": true,
     * "EnableVideo": true,
     * "RingSize": 10,
     * "PublishTimeout": 60000000000
     * },
     * "RTMP": {
     * "ListenAddr": ":1933"
     * },
     * "GateWay": {
     * "ListenAddr": ":8071"
     * },
     * "Jessica": {
     * "ListenAddr": ":8072"
     * },
     * "LogRotate": {
     * "Path": "logs",
     * "Size": 0,
     * "Days": 1
     * },
     * "Cluster": {
     * "ListenAddr": ":2011",
     * "OriginServer": "",
     * "Push": true
     * },
     * "HLS": {
     * "EnableWrite": false,
     * "EnableMemory": false,
     * "Fragment": 10,
     * "Window": 2,
     * "Path": "resource"
     * },
     * "HDL": {
     * "ListenAddr": ":2012"
     * },
     * "TS": {
     * "AutoPublish": false,
     * "Path": "resource"
     * },
     * "Record": {
     * "Path": "resource",
     * "AutoPublish": false,
     * "AutoRecord": false
     * },
     * "RTSP": {
     * "ListenAddr": ":551",
     * "AutoPull": true,
     * "Reconnect": true,
     * "RemoteAddr": "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov",
     * "StreamPath": "live/rtsp"
     * },
     * "WebRTC": {
     * "PublicIP": ["127.0.0.1"]
     * },
     * "GB28181": {
     * "Serial": "34020000002000000001",
     * "Realm": "3402000000",
     * "Expires": 3600,
     * "AutoInvite": false,
     * "ListenAddr": "192.168.1.120:5062"
     * }*     },
     * "pid": "46533",
     * "status": "offline"
     * }, {
     * "Name": "live",
     * "Path": "/Users/xucheng/Downloads/store/live",
     * "config": {
     * "Monibuca": {
     * "EnableWaitStream": true,
     * "EnableAudio": true,
     * "EnableVideo": true,
     * "RingSize": 10,
     * "PublishTimeout": 60000000000
     * }        ,
     * "RTMP": {
     * "ListenAddr": ":1935"
     * },
     * "GateWay": {
     * "ListenAddr": ":8081"
     * },
     * "Jessica": {
     * "ListenAddr": ":8080"
     * },
     * "LogRotate": {
     * "Path": "logs",
     * "Size": 0,
     * "Days": 1
     * },
     * "Cluster": {
     * "ListenAddr": ":2019",
     * "OriginServer": "",
     * "Push": true
     * },
     * "HLS": {
     * "EnableWrite": false,
     * "EnableMemory": false,
     * "Fragment": 10,
     * "Window": 2,
     * "Path": "resource"
     * },
     * "HDL": {
     * "ListenAddr": ":2020"
     * },
     * "TS": {
     * "AutoPublish": false,
     * "Path": "resource"
     * },
     * "Record": {
     * "Path": "resource",
     * "AutoPublish": false,
     * "AutoRecord": false
     * },
     * "RTSP": {
     * "ListenAddr": ":554",
     * "AutoPull": true,
     * "Reconnect": true,
     * "RemoteAddr": "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov",
     * "StreamPath": "live/rtsp"
     * },
     * "WebRTC": {
     * "PublicIP": ["127.0.0.1"]
     * },
     * "GB28181": {
     * "Serial": "34020000002000000001",
     * "Realm": "3402000000",
     * "Expires": 3600,
     * "AutoInvite": false,
     * "ListenAddr": "192.168.1.120:5060"
     * }
     * },
     * "pid": "17003",
     * "status": "offline"
     * }]
     *
     * @return
     *//*
 
    private String findList() {
        String url = "http://localhost:3000/api/instance/list";
        String result = HttpClientUtil.doGet(url);
        return result;
    }
 
    @Test
    public void findListTest() throws Exception {
        String list = findList();
        List<Map> maps = JSON.parseObject(list, List.class);
        for (Map map : maps) {
            String name = map.get("Name") + "";//实例名称
            String path = map.get("Path") + "";//实例存放路径
            String status = map.get("status") + "";// offline 不在线 online 在线
            System.out.println(status);
        }
 
    }
 
    @Test
    public void test01() throws Exception {
        startInstance();
    }
 
    */
/**
     * 启动实例
     * POST
     * http://localhost:3000/api/instance/start?name=live
     *//*
 
    private void startInstance() {
        String url = "http://localhost:3000/api/instance/start?name=live";
        String result = HttpClientUtil.doPost(url);
        System.out.println(result);
    }
 
    */
/**
     * 放入rtsp链接
     * GET
     * http://localhost:8081/rtsp/pull?
     * target=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov&
     * streamPath=live/test
     * <p>
     * <p>
     * return :http://localhost:2020/live/test1.flv
     *//*
 
    private void pullRTSPURL() {
        String url = "http://localhost:8081/rtsp/pull";
        Map<String, String> params = Maps.newLinkedHashMap();
 */
/*       params.put("target","rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
        params.put("streamPath","live/test");
        HttpClientUtil.doGet(url,params);
 
        params.clear();
        params.put("target","rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
        params.put("streamPath","live/test1");
*//*
 
 
        for (int i = 0; i < 10; i++) {
            params.put("target", "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
            params.put("streamPath", "live/test" + i);
            String result = HttpClientUtil.doGet(url, params);
            if (result.contains("0")) {
            } else {
                System.out.println("第" + i + "次创建失败");
            }
 
            params.clear();
        }
 
    }
 
    @Test
    public void pullRTSP() {
        String url = "http://localhost:8081/rtsp/pull";
        Map<String, String> params = Maps.newLinkedHashMap();
 
        params.put("target", "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
        params.put("streamPath", "live/test");
        String result = HttpClientUtil.doGet(url, params);
        System.out.println(result);
    }
}*/