diff --git a/web/packages/gallery/services/ffmpeg/web.ts b/web/packages/gallery/services/ffmpeg/web.ts index 890bdd9882..f1b9a6912c 100644 --- a/web/packages/gallery/services/ffmpeg/web.ts +++ b/web/packages/gallery/services/ffmpeg/web.ts @@ -44,23 +44,17 @@ const createFFmpeg = async () => { * * @param blob The input data on which to run the command, provided as a blob. * - * @param outputFileExtension The extension(s) of the (temporary) output file - * which will be generated by the command. If multiple of these are provided, - * then the first one is used for the OUTPUT placeholder, while the rest of them - * are expected to have been generated by the ffmpeg command implicitly. + * @param outputFileExtension The extension of the (temporary) output file which + * will be generated by the command. * - * @returns The contents (bytes as {@link Uint8Array}) of the output file - * generated as a result of executing {@link command} on {@link blob}. If a - * single {@link outputFileExtension} is provided, then the result will be a - * single {@link Uint8Array}, otherwise it will be an array of - * {@link Uint8Array}, one for each entry in {@link outputFileExtension} - * respectively. + * @returns The contents of the output file generated as a result of executing + * {@link command} on {@link blob}. */ -export const ffmpegExecWeb = async ( +export const ffmpegExecWeb = async ( command: string[], blob: Blob, - outputFileExtension: T, -): Promise => { + outputFileExtension: string, +): Promise => { const ffmpeg = await ffmpegLazy(); // Interleaving multiple ffmpeg.execs causes errors like // @@ -72,20 +66,14 @@ export const ffmpegExecWeb = async ( ); }; -const ffmpegExec = async ( +const ffmpegExec = async ( ffmpeg: FFmpeg, command: string[], - outputFileExtension: T, + outputFileExtension: string, blob: Blob, -): Promise => { +) => { const inputPath = newID("in_"); - const firstOutputFileExtension = - typeof outputFileExtension == "string" - ? outputFileExtension - : outputFileExtension[0]; - const outputSuffix = firstOutputFileExtension - ? "." + firstOutputFileExtension - : ""; + const outputSuffix = outputFileExtension ? "." + outputFileExtension : ""; const outputPath = newID("out_") + outputSuffix; const cmd = substitutePlaceholders(command, inputPath, outputPath); @@ -109,17 +97,12 @@ const ffmpegExec = async ( throw new Error(`ffmpeg command failed with exit code ${status}`); } - if (typeof outputFileExtension == "string") { - const result = await ffmpeg.readFile(outputPath); - if (typeof result == "string") - throw new Error("Expected binary data"); + const result = await ffmpeg.readFile(outputPath); + if (typeof result == "string") throw new Error("Expected binary data"); - const ms = Date.now() - startTime; - log.debug(() => `[wasm] ffmpeg ${cmd.join(" ")} (${ms} ms)`); - return result; - } else { - return [] as Uint8Array[]; - } + const ms = Date.now() - startTime; + log.debug(() => `[wasm] ffmpeg ${cmd.join(" ")} (${ms} ms)`); + return result; } finally { try { await ffmpeg.deleteFile(inputPath);