This commit is contained in:
Manav Rathi 2024-04-20 20:54:40 +05:30
parent 9285954e01
commit 71cf2c30d7
No known key found for this signature in database

View file

@ -1,3 +1,4 @@
import { nameAndExtension } from "@/next/file";
import log from "@/next/log"; import log from "@/next/log";
import { withTimeout } from "@ente/shared/utils"; import { withTimeout } from "@ente/shared/utils";
import QueueProcessor from "@ente/shared/utils/queueProcessor"; import QueueProcessor from "@ente/shared/utils/queueProcessor";
@ -7,7 +8,7 @@ import {
INPUT_PATH_PLACEHOLDER, INPUT_PATH_PLACEHOLDER,
OUTPUT_PATH_PLACEHOLDER, OUTPUT_PATH_PLACEHOLDER,
} from "constants/ffmpeg"; } from "constants/ffmpeg";
import { createFFmpeg, FFmpeg } from "ffmpeg-wasm"; import { FFmpeg, createFFmpeg } from "ffmpeg-wasm";
import { getUint8ArrayView } from "services/readerService"; import { getUint8ArrayView } from "services/readerService";
const FFMPEG_EXECUTION_WAIT_TIME = 30 * 1000; const FFMPEG_EXECUTION_WAIT_TIME = 30 * 1000;
@ -65,7 +66,7 @@ export class WasmFFmpeg {
let tempOutputFilePath: string; let tempOutputFilePath: string;
try { try {
await this.ready; await this.ready;
const extension = getFileExtension(inputFile.name); const [, extension] = nameAndExtension(inputFile.name);
const tempNameSuffix = extension ? `input.${extension}` : "input"; const tempNameSuffix = extension ? `input.${extension}` : "input";
tempInputFilePath = `${generateTempName(10, tempNameSuffix)}`; tempInputFilePath = `${generateTempName(10, tempNameSuffix)}`;
this.ffmpeg.FS( this.ffmpeg.FS(
@ -106,11 +107,3 @@ export class WasmFFmpeg {
} }
} }
} }
function getFileExtension(filename: string) {
const lastDotPosition = filename.lastIndexOf(".");
if (lastDotPosition === -1) return null;
else {
return filename.slice(lastDotPosition + 1);
}
}