-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
72 lines (57 loc) · 1.91 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mpeg2-ts-demux-wasm</title>
</head>
<body>
hi! open <b>DevTools</b>
<script type="module">
const loadWASM = (url) => {
return WebAssembly.instantiateStreaming(fetch(url));
};
const loadSegment = (url) => {
return fetch(url)
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer));
};
const start = async () => {
const wasm = await loadWASM('/mpeg2-ts-demux.wasm');
const segments = [
'/assets/segment_449kb_5sec.m2t',
];
segments.forEach(async (segment) => {
const segmentBytes = await loadSegment(segment);
console.log(`%csegment: "${segment}"`, 'color: orange; font-weight: bold;');
console.time('wasm execution time');
wasm.instance.exports.malloc(segmentBytes.byteLength);
const segmentBuffer = new Uint8ClampedArray(
wasm.instance.exports.memory.buffer,
wasm.instance.exports.s_offset.value,
);
segmentBuffer.set(segmentBytes);
wasm.instance.exports.demux();
console.timeEnd('wasm execution time');
console.info(
'elementary stream (h.264 / adts):',
new Uint8ClampedArray(
wasm.instance.exports.memory.buffer,
wasm.instance.exports.es_offset.value,
wasm.instance.exports.es_len.value,
),
);
console.info(
'metadata:',
new Uint8ClampedArray(
wasm.instance.exports.memory.buffer,
wasm.instance.exports.m_offset.value,
wasm.instance.exports.m_len.value,
),
);
});
};
start();
</script>
</body>
</html>