-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.utils.js
More file actions
41 lines (36 loc) · 1.34 KB
/
main.utils.js
File metadata and controls
41 lines (36 loc) · 1.34 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
function loadVideoFromFileInput(video, fileInput, callback = null) {
if (fileInput.files.length) {
let file = fileInput.files[0];
let fileURL = URL.createObjectURL(file);
if (callback) {
on(video, "canplay", callback, {once:true});
}
video.src = fileURL;
}
}
function drawSpecificFrameFromVideo(video, canvas, time) {
on(video, "seeked", () => drawFrameFromVideo(video, canvas), {once:true});
video.currentTime = time;
}
function drawFrameFromVideo(video, canvas) {
let context = canvas.getContext("2d");
context.drawImage(video, 0, 0, canvas.width, canvas.height);
}
function getVideoFrameAsDataURL(video) {
let canvas = elem("canvas");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
let context = canvas.getContext("2d");
context.drawImage(video, 0, 0, canvas.width, canvas.height);
let dataURL = canvas.toDataURL();
return dataURL;
}
function updateSeekbar(seekValue = 0) {
stepLength = video.duration / (markCountInput.valueAsNumber - 1);
marksValues = range(0, video.duration, stepLength);
marksValues = marksValues.map(value => Math.round(value));
seekbar.max = video.duration;
seekbar.value = seekValue;
seekbarMarks.innerHTML = null;
marksValues.forEach(value => seekbarMarks.append(elem("option", value)));
}