This commit is contained in:
Abhinav 2022-11-14 16:52:12 +05:30
parent e900cc5e2c
commit 3b25426d74

View file

@ -15,7 +15,7 @@ const FFMPEG_EXECUTION_WAIT_TIME = 30 * 1000;
export class WasmFFmpeg { export class WasmFFmpeg {
private ffmpeg: FFmpeg; private ffmpeg: FFmpeg;
private ready: Promise<void> = null; private ready: Promise<void> = null;
private ffmpegTaskQueue = new QueueProcessor<any>(1); private ffmpegTaskQueue = new QueueProcessor<File>(1);
constructor() { constructor() {
this.ffmpeg = createFFmpeg({ this.ffmpeg = createFFmpeg({
@ -69,7 +69,7 @@ export class WasmFFmpeg {
); );
tempOutputFilePath = `${generateTempName(10)}-${outputFileName}`; tempOutputFilePath = `${generateTempName(10)}-${outputFileName}`;
cmd.map((cmdPart) => { cmd = cmd.map((cmdPart) => {
if (cmdPart === FFMPEG_PLACEHOLDER) { if (cmdPart === FFMPEG_PLACEHOLDER) {
return ''; return '';
} else if (cmdPart === INPUT_PATH_PLACEHOLDER) { } else if (cmdPart === INPUT_PATH_PLACEHOLDER) {
@ -80,9 +80,13 @@ export class WasmFFmpeg {
return cmdPart; return cmdPart;
} }
}); });
console.log(cmd);
await this.ffmpeg.run(...cmd); await this.ffmpeg.run(...cmd);
addLogLine(`ffmpeg execute completed for ${inputFile.name}`); addLogLine(`ffmpeg execute completed for ${inputFile.name}`);
return this.ffmpeg.FS('readFile', tempOutputFilePath); return new File(
[this.ffmpeg.FS('readFile', tempOutputFilePath)],
outputFileName
);
} catch (e) { } catch (e) {
addLogLine(`ffmpeg execute failed for ${inputFile.name}`); addLogLine(`ffmpeg execute failed for ${inputFile.name}`);
throw e; throw e;