Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

cond type take 1

Manav Rathi0c904d37c820
diff --git a/web/packages/gallery/services/ffmpeg/web.ts b/web/packages/gallery/services/ffmpeg/web.ts
index f1b9a6912c..890bdd9882 100644
--- a/web/packages/gallery/services/ffmpeg/web.ts
+++ b/web/packages/gallery/services/ffmpeg/web.ts
@@ -44,17 +44,23 @@ const createFFmpeg = async () => {
*
* @param blob The input data on which to run the command, provided as a blob.
*
- * @param outputFileExtension The extension of the (temporary) output file which
- * will be generated by the command.
+ * @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.
*
- * @returns The contents of the output file generated as a result of executing
- * {@link command} on {@link blob}.
+ * @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.
*/
-export const ffmpegExecWeb = async (
+export const ffmpegExecWeb = async <T extends string | string[]>(
command: string[],
blob: Blob,
- outputFileExtension: string,
-): Promise<Uint8Array> => {
+ outputFileExtension: T,
+): Promise<T extends string ? Uint8Array : Uint8Array[]> => {
const ffmpeg = await ffmpegLazy();
// Interleaving multiple ffmpeg.execs causes errors like
//
@@ -66,14 +72,20 @@ export const ffmpegExecWeb = async (
);
};
-const ffmpegExec = async (
+const ffmpegExec = async <T extends string | string[]>(
ffmpeg: FFmpeg,
command: string[],
- outputFileExtension: string,
+ outputFileExtension: T,
blob: Blob,
-) => {
+): Promise<T extends string ? Uint8Array : Uint8Array[]> => {
const inputPath = newID("in_");
- const outputSuffix = outputFileExtension ? "." + outputFileExtension : "";
+ const firstOutputFileExtension =
+ typeof outputFileExtension == "string"
+ ? outputFileExtension
+ : outputFileExtension[0];
+ const outputSuffix = firstOutputFileExtension
+ ? "." + firstOutputFileExtension
+ : "";
const outputPath = newID("out_") + outputSuffix;
const cmd = substitutePlaceholders(command, inputPath, outputPath);
@@ -97,12 +109,17 @@ const ffmpegExec = async (
throw new Error(`ffmpeg command failed with exit code ${status}`);
}
- const result = await ffmpeg.readFile(outputPath);
- if (typeof result == "string") throw new Error("Expected binary data");
+ if (typeof outputFileExtension == "string") {
+ 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;
+ const ms = Date.now() - startTime;
+ log.debug(() => `[wasm] ffmpeg ${cmd.join(" ")} (${ms} ms)`);
+ return result;
+ } else {
+ return [] as Uint8Array[];
+ }
} finally {
try {
await ffmpeg.deleteFile(inputPath);