-
Notifications
You must be signed in to change notification settings - Fork 344
/
Copy pathmse-avif-viewer.js
58 lines (49 loc) · 1.57 KB
/
mse-avif-viewer.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
var file = {};
file.mp4boxfile = null;
file.objectToLoad = null;
file.objectIsFile = false;
file.fancytree = null;
file.avifFragmentedFile = null;
Log.setLogLevel(Log.debug);
function mseViewAVIFItem(fileobj, loadbutton, success) {
loadbutton.button("enable");
if (success) {
console.log("success");
file.avifFragmentedFile = file.mp4boxfile.itemToFragmentedTrackFile();
//initializeMSE();
document.getElementById('v').src = window.URL.createObjectURL(new Blob([file.avifFragmentedFile.getBuffer()], {type:'video/mp4; codecs="av01.0.13M.08"'}));
} else {
console.log("failure");
}
}
window.onload = function () {
createLoadBar($('#menubar'), "File", "file", file, mseViewAVIFItem);
if (window.location.search) {
file.objectToLoad = window.location.search.substring(1);
load();
}
}
function onUpdateEnd(e) {
var sb = this;
// No-op
}
function onSourceClose(e) {
document.getElementById('dropArea').innerHtml = 'MediaSource closed!';
}
function onSourceOpen(e) {
var ms = e.target;
sb = ms.addSourceBuffer('video/mp4; codecs="'+file.avifFragmentedFile.getCodecs()+'"');
sb.ms = ms;
sb.addEventListener('updateend', onUpdateEnd.bind(sb));
file.avifFragmentedFile.save("test.mp4");
sb.appendBuffer(file.avifFragmentedFile.getBuffer());
}
function initializeMSE() {
var video = document.getElementById('v');
mediaSource = new MediaSource();
mediaSource.video = video;
video.ms = mediaSource;
mediaSource.addEventListener("sourceopen", onSourceOpen);
mediaSource.addEventListener("sourceclose", onSourceClose);
video.src = window.URL.createObjectURL(mediaSource);
}