-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplayer.html
More file actions
310 lines (274 loc) · 14.5 KB
/
player.html
File metadata and controls
310 lines (274 loc) · 14.5 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="static/css/style.css" rel="stylesheet">
<script src="static/js/fabric.min.js" type="text/javascript"></script>
<script src="static/js/whammy.js" type="text/javascript"></script>
<script src="static/js/reim.js" type="text/javascript"></script>
</head>
<body>
<!------------------- Navigation ------------------------>
<nav class="navbar navbar-dark fixed-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">Dashboard</a>
<ul class="navbar-nav px-3">
<li class="nav-item text-nowrap">
<a class="nav-link" href="#">Sign out</a>
</li>
</ul>
</nav>
<!------------------- End of page heading -------------------->
<div class="container-fluid pt-5">
<div class="row">
<!---------------------- Sidebar menu starts ---------------------->
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
<svg class="feather feather-home" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
<polyline points="9 22 9 12 15 12 15 22"></polyline>
</svg>
Dashboard <span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-file" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path>
<polyline points="13 2 13 9 20 9"></polyline>
</svg>
My videos
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-shopping-cart" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<circle cx="9" cy="21" r="1"></circle>
<circle cx="20" cy="21" r="1"></circle>
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
</svg>
All videos
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-users" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
<circle cx="9" cy="7" r="4"></circle>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
<path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
</svg>
My Annotations
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-bar-chart-2" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<line x1="18" x2="18" y1="20" y2="10"></line>
<line x1="12" x2="12" y1="20" y2="4"></line>
<line x1="6" x2="6" y1="20" y2="14"></line>
</svg>
Reports
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-layers" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<polygon points="12 2 2 7 12 12 22 7 12 2"></polygon>
<polyline points="2 17 12 22 22 17"></polyline>
<polyline points="2 12 12 17 22 12"></polyline>
</svg>
Integrations
</a>
</li>
</ul>
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Saved reports</span>
<a class="d-flex align-items-center text-muted" href="#">
<svg class="feather feather-plus-circle" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" x2="12" y1="8" y2="16"></line>
<line x1="8" x2="16" y1="12" y2="12"></line>
</svg>
</a>
</h6>
<ul class="nav flex-column mb-2">
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-file-text" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" x2="8" y1="13" y2="13"></line>
<line x1="16" x2="8" y1="17" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
Current month
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-file-text" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" x2="8" y1="13" y2="13"></line>
<line x1="16" x2="8" y1="17" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
Last quarter
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-file-text" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" x2="8" y1="13" y2="13"></line>
<line x1="16" x2="8" y1="17" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
Social engagement
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<svg class="feather feather-file-text" fill="none" height="24" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24"
width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" x2="8" y1="13" y2="13"></line>
<line x1="16" x2="8" y1="17" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
Year-end sale
</a>
</li>
</ul>
</div>
</nav>
<!---------------------- Sidebar menu ends ------------------>
<div class="col-md-6">
<!------------------ Player --------------->
<div id="video_box">
<div id="video_overlays">
<canvas class="canvas" id="canvas"></canvas>
</div>
<div>
<video controls="true" id="video" src="video1_1.mp4"/>
</div>
</div>
</div>
<div class="col-md-4">
list all annotations from the storage
<p class="data" id="data">
</p>
<button class="btn btn-success pt-2" onclick="download_merge()">Download</button>
<a href="#" id="download_link">Download link will go here</a>
</div>
</div>
</div>
<script>
function chunk(arr, chunkSize) {
var R = [];
for (var i = 0, len = arr.length; i < len; i += chunkSize)
R.push(arr.slice(i, i + chunkSize));
return R;
}
// read the cookies and return annotations
var canvases = document.cookie.match(new RegExp('(^| )' + "canvases" + '=([^;]+)'))[2];
var timings = document.cookie.match(new RegExp('(^| )' + "timings" + '=([^;]+)'))[2];
let canvas = new fabric.Canvas('canvas');
cookie_content = timings.split(";")[0];
cookie_content_clean = cookie_content.replace("[","");
cookie_content_cleaner = cookie_content_clean.replace("]","");
array_version = cookie_content_cleaner.split(",");
chunked = chunk(array_version, 7);
let canvases_json = JSON.parse(canvases);
console.log(canvases_json);
console.log(chunked);
// listen on time change and check the same start & end time in timings
var vid = document.getElementById("video");
var canvas_layer = document.getElementById("canvas");
vid.ontimeupdate = function () {
canvas.clear();
for(let i = 0; i < chunked.length; i++){
voText = new fabric.IText(canvases_json['objects'][i]["text"], {
fontFamily: 'arial black',
left: canvases_json['objects'][i]["left"],
top: canvases_json['objects'][i]["top"],
width: canvases_json['objects'][i]["width"],
height: canvases_json['objects'][i]["height"],
});
if(vid.currentTime >= chunked[i][0] && vid.currentTime <= chunked[i][1]){
console.log(canvases_json['objects'][i]["text"]);
voText.opacity = 1;
canvas.getObjects();
canvas.add(voText);
}
else {
voText.opacity = 0;
}
}
};
canvas.selection = false;
canvas.renderAll();
canvas.calcOffset();
// ------------------------------- Merge and download ----------------------
function download_merge() {
var encoder = new Whammy.Video(15);
var canvas_video = document.createElement("canvas");
// resized to the video element's size
// canvas_video.width = vid.offsetWidth;
// canvas_video.height = vid.offsetHeight;
// original size
canvas_video.width = vid.videoWidth;
canvas_video.height = vid.videoHeight;
var context = canvas_video.getContext("2d");
vid.addEventListener("timeupdate", function () {
console.log(vid.currentTime);
// transform the fabric canvas into image
var im_can = canvas.toDataURL("image/png");
console.log(im_can);
context.drawImage(vid, 0, 0);
// context.drawImage(im_can,0,0);
context.drawImage(ReImg.fromCanvas(document.getElementById('canvas')).toPng(), 0, 0);
context.save();
canvas.setBackgroundColor("red");
encoder.add(context);
console.log(encoder);
});
vid.onended = function () {
encoder.compile(false, function (output) {
var url = (window.URL || window.URL).createObjectURL(output);
console.log(url);
document.getElementById('download_link').href = url;
});
};
}
</script>
</body>
</html>