The next-generation file converter. Open source, fully local* and free forever.
feat: optimize ffmpeg via running in parallel (#17)
nullptrb495d874b627
diff --git a/src/lib/converters/ffmpeg.svelte.ts b/src/lib/converters/ffmpeg.svelte.tsindex 7977af7..da5bc50 100644--- a/src/lib/converters/ffmpeg.svelte.ts+++ b/src/lib/converters/ffmpeg.svelte.ts@@ -37,6 +37,7 @@ export class FFmpegConverter extends Converter {coreURL: `${baseURL}/ffmpeg-core.js`,wasmURL: `${baseURL}/ffmpeg-core.wasm`,});+ // this is just to cache the wasm and js for when we actually use it. we're not using this ffmpeg instancethis.ready = true;})();}@@ -46,21 +47,29 @@ export class FFmpegConverter extends Converter {to: string,): Promise<IFile> {if (!to.startsWith(".")) to = `.${to}`;+ const ffmpeg = new FFmpeg();+ const baseURL =+ "https://cdn.jsdelivr.net/npm/@ffmpeg/[email protected]/dist/esm";+ await ffmpeg.load({+ coreURL: `${baseURL}/ffmpeg-core.js`,+ wasmURL: `${baseURL}/ffmpeg-core.wasm`,+ });const buf = new Uint8Array(input.buffer);- await this.ffmpeg.writeFile("input", buf);+ await ffmpeg.writeFile("input", buf);log(["converters", this.name],`wrote ${input.name} to ffmpeg virtual fs`,);- await this.ffmpeg.exec(["-i", "input", "output" + to]);+ await ffmpeg.exec(["-i", "input", "output" + to]);log(["converters", this.name], `executed ffmpeg command`);- const output = (await this.ffmpeg.readFile(+ const output = (await ffmpeg.readFile("output" + to,)) as unknown as Uint8Array;log(["converters", this.name],`read ${input.name.split(".").slice(0, -1).join(".") + to} from ffmpeg virtual fs`,);+ ffmpeg.terminate();return {...input,buffer: output.buffer,