mirror of https://github.com/VERT-sh/VERT.git
feat: optimize ffmpeg via running in parallel (#17)
This commit is contained in:
parent
4adb00b1fa
commit
b495d874b6
|
@ -37,6 +37,7 @@ export class FFmpegConverter extends Converter {
|
||||||
coreURL: `${baseURL}/ffmpeg-core.js`,
|
coreURL: `${baseURL}/ffmpeg-core.js`,
|
||||||
wasmURL: `${baseURL}/ffmpeg-core.wasm`,
|
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;
|
this.ready = true;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
@ -46,21 +47,29 @@ export class FFmpegConverter extends Converter {
|
||||||
to: string,
|
to: string,
|
||||||
): Promise<IFile> {
|
): Promise<IFile> {
|
||||||
if (!to.startsWith(".")) to = `.${to}`;
|
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);
|
const buf = new Uint8Array(input.buffer);
|
||||||
await this.ffmpeg.writeFile("input", buf);
|
await ffmpeg.writeFile("input", buf);
|
||||||
log(
|
log(
|
||||||
["converters", this.name],
|
["converters", this.name],
|
||||||
`wrote ${input.name} to ffmpeg virtual fs`,
|
`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`);
|
log(["converters", this.name], `executed ffmpeg command`);
|
||||||
const output = (await this.ffmpeg.readFile(
|
const output = (await ffmpeg.readFile(
|
||||||
"output" + to,
|
"output" + to,
|
||||||
)) as unknown as Uint8Array;
|
)) as unknown as Uint8Array;
|
||||||
log(
|
log(
|
||||||
["converters", this.name],
|
["converters", this.name],
|
||||||
`read ${input.name.split(".").slice(0, -1).join(".") + to} from ffmpeg virtual fs`,
|
`read ${input.name.split(".").slice(0, -1).join(".") + to} from ffmpeg virtual fs`,
|
||||||
);
|
);
|
||||||
|
ffmpeg.terminate();
|
||||||
return {
|
return {
|
||||||
...input,
|
...input,
|
||||||
buffer: output.buffer,
|
buffer: output.buffer,
|
||||||
|
|
Loading…
Reference in New Issue