Revert "cond type take 1" - It just doesn't seem to work without casts

...and we don't even need in the final goal (this is desktop only).

This reverts commit 0c904d37c8.
This commit is contained in:
Manav Rathi
2025-04-17 10:58:11 +05:30
parent 0c904d37c8
commit bd7fec03d3

View File

@@ -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 <T extends string | string[]>(
export const ffmpegExecWeb = async (
command: string[],
blob: Blob,
outputFileExtension: T,
): Promise<T extends string ? Uint8Array : Uint8Array[]> => {
outputFileExtension: string,
): Promise<Uint8Array> => {
const ffmpeg = await ffmpegLazy();
// Interleaving multiple ffmpeg.execs causes errors like
//
@@ -72,20 +66,14 @@ export const ffmpegExecWeb = async <T extends string | string[]>(
);
};
const ffmpegExec = async <T extends string | string[]>(
const ffmpegExec = async (
ffmpeg: FFmpeg,
command: string[],
outputFileExtension: T,
outputFileExtension: string,
blob: Blob,
): Promise<T extends string ? Uint8Array : Uint8Array[]> => {
) => {
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 <T extends string | string[]>(
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);