forked from forks/ffprobe-wasm
Update Frames component to use ffprobe-worker.
This commit is contained in:
@@ -1,36 +1,72 @@
|
||||
onmessage = (e) => {
|
||||
const file = e.data[0];
|
||||
const type = e.data[0];
|
||||
const file = e.data[1];
|
||||
|
||||
// Mount FS for files.
|
||||
if (!FS.analyzePath('/work').exists) {
|
||||
FS.mkdir('/work');
|
||||
}
|
||||
FS.mount(WORKERFS, { files: [file] }, '/work');
|
||||
let data;
|
||||
|
||||
// Call the wasm module.
|
||||
const info = Module.get_file_info('/work/' + file.name);
|
||||
switch (type) {
|
||||
case 'get_file_info':
|
||||
// Mount FS for files.
|
||||
if (!FS.analyzePath('/work').exists) {
|
||||
FS.mkdir('/work');
|
||||
}
|
||||
FS.mount(WORKERFS, { files: [file] }, '/work');
|
||||
|
||||
// Remap streams into collection.
|
||||
const s = [];
|
||||
for (let i = 0; i < info.streams.size(); i++) {
|
||||
s.push(info.streams.get(i));
|
||||
// Call the wasm module.
|
||||
const info = Module.get_file_info('/work/' + file.name);
|
||||
|
||||
// Remap streams into collection.
|
||||
const s = [];
|
||||
for (let i = 0; i < info.streams.size(); i++) {
|
||||
s.push(info.streams.get(i));
|
||||
}
|
||||
|
||||
const versions = {
|
||||
libavutil: Module.avutil_version(),
|
||||
libavcodec: Module.avcodec_version(),
|
||||
libavformat: Module.avformat_version(),
|
||||
};
|
||||
|
||||
// Send back data response.
|
||||
data = {
|
||||
...info,
|
||||
streams: s,
|
||||
versions,
|
||||
}
|
||||
postMessage(data);
|
||||
|
||||
// Cleanup mount.
|
||||
FS.unmount('/work');
|
||||
break;
|
||||
|
||||
case 'get_frames':
|
||||
if (!FS.analyzePath('/work').exists) {
|
||||
FS.mkdir('/work');
|
||||
}
|
||||
FS.mount(WORKERFS, { files: [file] }, '/work');
|
||||
|
||||
const offset = e.data[2];
|
||||
const frames = Module.get_frames('/work/' + file.name, offset);
|
||||
|
||||
// Remap frames into collection.
|
||||
const f = [];
|
||||
for (let i = 0; i < frames.frames.size(); i++) {
|
||||
f.push(frames.frames.get(i));
|
||||
}
|
||||
|
||||
data = {
|
||||
...frames,
|
||||
frames: f,
|
||||
}
|
||||
postMessage(data);
|
||||
|
||||
// Cleanup mount.
|
||||
FS.unmount('/work');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const versions = {
|
||||
libavutil: Module.avutil_version(),
|
||||
libavcodec: Module.avcodec_version(),
|
||||
libavformat: Module.avformat_version(),
|
||||
};
|
||||
|
||||
// Send back data response.
|
||||
const data = {
|
||||
...info,
|
||||
streams: s,
|
||||
versions,
|
||||
}
|
||||
postMessage(data);
|
||||
|
||||
// Cleanup mount.
|
||||
FS.unmount('/work');
|
||||
}
|
||||
self.importScripts('ffprobe-wasm.js'); // Load ffprobe into worker context.
|
||||
Reference in New Issue
Block a user