mirror of https://github.com/VERT-sh/VERT.git
feat: optimize ffmpeg via running in parallel
This commit is contained in:
parent
4adb00b1fa
commit
ce549b24e2
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue