-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample-live-images.html
296 lines (252 loc) · 8.48 KB
/
sample-live-images.html
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
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>VXG API sample / Extract Images from Live stream</title>
<!-- frameworks -->
<script src="frw/jquery.min.js"></script>
<script src="frw/jquery-ui.min.js"></script>
<script src="frw/jquery.formatDateTime.js"></script>
<script src="frw/datetimepicker.full.min.js"></script>
<link rel="stylesheet" type="text/css" href="frw/bootstrap.min.css">
<script src="frw/bootstrap.min.js"></script>
<style>
#tokenContainer {
width: 700px;
}
#showForm {
text-decoration: underline;
}
#showForm:hover {
cursor: pointer;
}
.btn {
color: white;
background-color: #a0cf4d;
}
</style>
</head>
<body onLoad="Load()">
<div class="container">
<h1>Extract Images from Live video</h1>
<div class="form-inline" role="form">
<h3>Select a camera</h3>
<div class="form-group ">
<div class="input-group ">
<input id="tokenContainer" type="text" class="form-control" placeholder="Enter access token" value="">
</div>
</div>
<h3>Set interval</h3>
<div class="form-group ">
<div class="input-group">
<input id="period" type="number" class="form-control" aria-describedby="basic-addon3"
placeholder="Period" value="1.0">
<div class="input-group-append">
<span class="input-group-text">in seconds</span>
</div>
</div>
</div>
</div>
<div>
<div style="padding-top:20px; padding-bottom:20px;">
<button id="check" class="btn btn-default">Check image generation</button>
<button id="start" class="btn btn-default">Start image generation</button>
<button id="stop" class="btn btn-defaultx">Stop image generation</button>
</div>
<div class="time-form hidden" >
<h3>Select time interval to show (in UTC)</h3>
<div class="form-inline" role="form">
<div class="form-group ">
<div class="input-group ">
<input id="from" type="text" class="form-control" aria-describedby="basic-addon1"
placeholder="Start time">
<div class="input-group-append">
<span class="input-group-text">in UTC</span>
</div>
</div>
</div>
</div>
<div class="form-inline" role="form">
<div class="form-group ">
<div class="input-group ">
<input id="to" type="text" class="form-control" aria-describedby="basic-addon2"
placeholder="End time">
<div class="input-group-append">
<span class="input-group-text">in UTC</span>
</div>
</div>
</div>
</div>
</div>
<p><span id="showForm" style="display: hide;"> Show images for the last minute</span></p>
<div>
<button id="getImages" class="btn btn-default">Show images</button>
<div id="result" style="padding-top:20px;></div>
<!-- div class="lds-ellipsis" style="display: none"><div></div><div></div><div></div><div></div></div -->
</div>
</div>
</div>
<script>
////////////////////////////////////////////////////////////
//
// This section shows how to use VXG REST API.
//
////////////////////////////////////////////////////////////
var taskId;
var access_token;
$( "#check" ).click(function() {
access_token = $('#tokenContainer').val();
// initializes HTTP header
$.ajaxSetup({
headers: {
'Authorization': 'Acc ' + access_token
}
});
return $.ajax({
method: 'GET',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/images/generation/live/',
contentType: "application/json",
dataType: 'json',
}).then(function (data) {
$( "#result" ).html("Live image generation interval: " + data.image_generation_period);
$('#period').val(data.image_generation_period);
});
});
$( "#start" ).click(function() {
access_token = $('#tokenContainer').val();
// initializes HTTP header
$.ajaxSetup({
headers: {
'Authorization': 'Acc ' + access_token
}
});
let period = $('#period').val();
let requestData = {
image_generation_period: period,
};
return $.ajax({
method: 'PUT',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/images/generation/live/',
data: JSON.stringify(requestData),
contentType: "application/json",
dataType: 'json',
}).then(function (data) {
$( "#result" ).html("Live image generation started");
});
});
$( "#stop" ).click(function() {
access_token = $('#tokenContainer').val();
// initializes HTTP header
$.ajaxSetup({
headers: {
'Authorization': 'Acc ' + access_token
}
});
let requestData = {
image_generation_period: null,
};
return $.ajax({
method: 'PUT',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/images/generation/live/',
data: JSON.stringify(requestData),
contentType: "application/json",
dataType: 'json',
}).then(function (data) {
$( "#result" ).html("Live image generation stopped");
});
});
$( "#getImages" ).click(function() {
// initializes HTTP header
access_token = $('#tokenContainer').val();
$.ajaxSetup({
headers: {
'Authorization': 'Acc ' + access_token
}
});
// change time to NOW
Load();
let start = new Date($('#from').val());
let end = new Date($('#to').val());
let requestData = {
limit: 100,
order_by: '-time',
};
// time conversion
let ts = new Date();
if (start != null) {
ts.setTime(start.getTime());
requestData.start = convertTimeToStr(ts);
}
if (end != null) {
ts.setTime(end.getTime());
requestData.end = convertTimeToStr(ts);
}
// executes HTTP GET request '/storage/images/'
return $.ajax({
method: 'GET',
url: 'https://web.skyvr.videoexpertsgroup.com/' + 'api/v4/storage/images/',
data: requestData,
dataType: 'json',
}).then(function (data) {
console.log(data.objects);
//alert("Images objects were loaded. Total images: " + data.objects.length + '. Check the browsers console for details.');
var count = 0;
var res = ''; $( "#result" ).html('')
$.each(data.objects, function(i, item){
if (item.url.indexOf("_livig_") >=0 )
{
res+='<div><a target="_blank" href='+item.url+'>'+count+' ' + item.time+' ' + item.height +'x' + item.width + ' </a></div>';
count++;
}
})
res+='<div> Total images: '+count+'</div>';
if (count == 0) res+='<div> It can take upto 30 seconds to start a task</div>';
$( "#result" ).html( res );
}).fail(function () {
}).always(function () {
});
});
////////////////////////////////////////////////////////////
//
// This section is handling UI and data/time conversions.
//
////////////////////////////////////////////////////////////
Date.prototype.getFromFormat = function (format) {
let yyyy = this.getUTCFullYear().toString();
format = format.replace(/yyyy/g, yyyy)
let mm = (this.getUTCMonth() + 1).toString();
format = format.replace(/mm/g, (mm[1] ? mm : "0" + mm[0]));
let dd = this.getUTCDate().toString();
format = format.replace(/dd/g, (dd[1] ? dd : "0" + dd[0]));
let hh = this.getUTCHours().toString();
format = format.replace(/hh/g, (hh[1] ? hh : "0" + hh[0]));
let ii = this.getUTCMinutes().toString();
format = format.replace(/ii/g, (ii[1] ? ii : "0" + ii[0]));
let ss = this.getUTCSeconds().toString();
format = format.replace(/ss/g, (ss[1] ? ss : "0" + ss[0]));
return format;
};
function Load() {
let f1 = new Date();
let e1 = new Date(f1.getTime() - 1 * 60 * 1000); // - 1 hour
document.getElementById('from').value = e1.getFromFormat('mm/dd/yyyy hh:ii:ss');
document.getElementById('to').value = f1.getFromFormat('mm/dd/yyyy hh:ii:ss');
}
function convertTimeToStr(t) {
let d = new Date();
d.setTime(t);
let str = d.getFullYear() + "-"
+ ("00" + (d.getMonth() + 1)).slice(-2) + "-"
+ ("00" + d.getDate()).slice(-2) + "T"
+ ("00" + d.getHours()).slice(-2) + ":"
+ ("00" + d.getMinutes()).slice(-2) + ":"
+ ("00" + d.getSeconds()).slice(-2);
return str;
}
$('#showForm').on('click', function () {
$('.time-form').toggleClass('hidden')
})
</script>
</body>
</html>