feat: optimize ffmpeg via running in parallel (#17)

This commit is contained in:
nullptr 2024-11-14 10:10:44 +00:00 committed by GitHub
parent 4adb00b1fa
commit b495d874b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 3 deletions

View File

@ -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 instance
this.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/core@0.12.6/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,