diff --git a/www/public/ffprobe-worker.js b/www/public/ffprobe-worker.js index 8afc5a1..33c32e4 100644 --- a/www/public/ffprobe-worker.js +++ b/www/public/ffprobe-worker.js @@ -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. \ No newline at end of file diff --git a/www/src/components/File.vue b/www/src/components/File.vue index bcd57a1..2a8b3e5 100644 --- a/www/src/components/File.vue +++ b/www/src/components/File.vue @@ -28,7 +28,7 @@ - + @@ -39,8 +39,6 @@ import Overview from './Overview.vue'; import Frames from './Frames.vue'; -const worker = new Worker('ffprobe-worker.js'); - export default { name: 'File', components: { @@ -57,7 +55,7 @@ export default { } }, created() { - worker.onmessage = (e) => { + this.$worker.onmessage = (e) => { this.info = e.data; } }, @@ -68,7 +66,7 @@ export default { this.showProgress = true; const file = event.dataTransfer ? event.dataTransfer.files[0] : event.target.files[0]; - worker.postMessage([ file ]); + this.$worker.postMessage([ 'get_file_info', file ]); } } } diff --git a/www/src/components/Frames.vue b/www/src/components/Frames.vue index 7680b7f..2ef72c7 100644 --- a/www/src/components/Frames.vue +++ b/www/src/components/Frames.vue @@ -1,35 +1,39 @@ Frames - Total: {{ data.nb_frames }} + Loading... + + Total: {{ data.nb_frames }} - + - - - {{ String.fromCharCode(data.value) }} - - + + + {{ String.fromCharCode(data.value) }} + + - + +
Total: {{ data.nb_frames }}