-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
142 lines (117 loc) · 3.96 KB
/
app.js
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
Stream = require('node-rtsp-stream')
const onvif = require('node-onvif')
const Recorder = require('node-rtsp-recorder').Recorder
const express = require("express")
const app = express()
const path = require('path')
// Find all local network devices.
stream = new Stream({
name: 'name',
streamUrl: 'rtsp://172.16.8.38:5554/back',
wsPort: 9001,
ffmpegOptions: { // options ffmpeg flags
'-stats': '', // an option with no neccessary value uses a blank string
'-r': 30 // options with required values specify the value after the key
},
})
// stream = new Stream({
// name: 'name',
// streamUrl: 'rtsp://admin:[email protected]:554/cam/realmonitor?channel=2&subtype=0',
// wsPort: 9002,
// ffmpegOptions: { // options ffmpeg flags
// '-stats': '', // an option with no neccessary value uses a blank string
// '-r': 30 // options with required values specify the value after the key
// },
// })
//recoder video
//recoder and sync to google drive
// var rec = new Recorder({
// url: 'rtsp://192.168.1.5:5554/front',
// timeLimit: 86400, // time in seconds for each segmented video file - 86400s = a day
// folder: '/run/user/1000/gvfs/google-drive:host=gmail.com,user=lambiengcode/1TqmLimLgYD_D-Tt88YVTMJfUQviE1kU7', //custom your file path to store video
// name: 'cam1',
// directoryPathFormat: 'MMM-D-YYYY',
// fileNameFormat: 'M-D-Y-HH-mm-ss',
// })
// rec.startRecording()
//link: 'rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0'
var rec1 = new Recorder({
url: 'rtsp://172.16.8.38:5554/front',
timeLimit: 86400, // time in seconds for each segmented video file - 86400s = a day
folder: './Storage', //custom your file path to store video
name: 'cam1',
directoryPathFormat: 'MMM-D-YYYY',
fileNameFormat: 'M-D-Y-HH-mm-ss',
})
// var rec2 = new Recorder({
// url: 'rtsp://admin:[email protected]:554/cam/realmonitor?channel=2&subtype=0',
// timeLimit: 86400, // time in seconds for each segmented video file - 86400s = a day
// folder: './Storage', //custom your file path to store video
// name: 'cam2',
// directoryPathFormat: 'MMM-D-YYYY',
// fileNameFormat: 'M-D-Y-HH-mm-ss',
// })
rec1.startRecording()
//rec2.startRecording()
//scan ip camera
process.camera = [];
onvif.startProbe().then((device_info_list) => {
console.log(device_info_list.length + ' devices were found.');
// Show the device name and the URL of the end point.
const arr = [];
device_info_list.forEach((info, x) => {
if (x <= 5) {
arr.push(info.xaddrs[0])
}
});
//forEach to Build Each Camera
process.camera = arr;
arr.forEach((onCam, i) => {
let device = new onvif.OnvifDevice({
xaddr: onCam,
user: 'admin',
pass: 'phamduong1986'
});
// Initialize the OnvifDevice object
device.init().then(() => {
// Get the UDP stream URL
let url = device.getUdpStreamUrl();
stream = new Stream({
name: 'name',
streamUrl: url,
wsPort: 9000 + i
})
var rec = new Recorder({
url: url,
timeLimit: 86400, // time in seconds for each segmented video file
folder: './Storage', //custom your file path to store video
name: 'cam${i}',
directoryPathFormat: 'MMM-D-YYYY',
fileNameFormat: 'M-D-h-mm-ss',
})
rec.startRecording();
console.log("URL :" + url);
}).catch((error) => {
console.error(error);
});
})
}).catch((error) => {
console.error(error);
});
app.use(express.static(path.join(__dirname, 'public')));
app.get("/", (req, res) => {
console.log(process.camera)
res.write(`<html>
<body>
<canvas id="canvas"></canvas>
</body>
<script type="text/javascript" src="./jsmpeg.min.js"></script>
<script type="text/javascript">
player = new JSMpeg.Player('ws://localhost:9002', {
canvas: document.getElementById('canvas') // Canvas should be a canvas DOM element
})
</script>
</html>`)
res.end();
})
app.listen(3000)