Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove unused ffmpeg from cast

Manav Rathi02207ca96c34
diff --git a/web/apps/cast/src/constants/ffmpeg.ts b/web/apps/cast/src/constants/ffmpeg.ts
deleted file mode 100644
index 9ecc41eb5e..0000000000
--- a/web/apps/cast/src/constants/ffmpeg.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export const INPUT_PATH_PLACEHOLDER = "INPUT";
-export const FFMPEG_PLACEHOLDER = "FFMPEG";
-export const OUTPUT_PATH_PLACEHOLDER = "OUTPUT";
diff --git a/web/apps/cast/src/services/ffmpeg/ffmpegFactory.ts b/web/apps/cast/src/services/ffmpeg/ffmpegFactory.ts
deleted file mode 100644
index 0f7d226c89..0000000000
--- a/web/apps/cast/src/services/ffmpeg/ffmpegFactory.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import ComlinkFFmpegWorker from "utils/comlink/ComlinkFFmpegWorker";
-
-export interface IFFmpeg {
- run: (
- cmd: string[],
- inputFile: File,
- outputFilename: string,
- dontTimeout?: boolean,
- ) => Promise<File>;
-}
-
-class FFmpegFactory {
- private client: IFFmpeg;
- async getFFmpegClient() {
- if (!this.client) {
- this.client = await ComlinkFFmpegWorker.getInstance();
- }
- return this.client;
- }
-}
-
-export default new FFmpegFactory();
diff --git a/web/apps/cast/src/services/ffmpeg/ffmpegService.ts b/web/apps/cast/src/services/ffmpeg/ffmpegService.ts
deleted file mode 100644
index 325f1d66b3..0000000000
--- a/web/apps/cast/src/services/ffmpeg/ffmpegService.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { logError } from "@ente/shared/sentry";
-import {
- FFMPEG_PLACEHOLDER,
- INPUT_PATH_PLACEHOLDER,
- OUTPUT_PATH_PLACEHOLDER,
-} from "constants/ffmpeg";
-import ffmpegFactory from "./ffmpegFactory";
-
-export async function convertToMP4(file: File) {
- try {
- const ffmpegClient = await ffmpegFactory.getFFmpegClient();
- return await ffmpegClient.run(
- [
- FFMPEG_PLACEHOLDER,
- "-i",
- INPUT_PATH_PLACEHOLDER,
- "-preset",
- "ultrafast",
- OUTPUT_PATH_PLACEHOLDER,
- ],
- file,
- "output.mp4",
- true,
- );
- } catch (e) {
- logError(e, "ffmpeg convertToMP4 failed");
- throw e;
- }
-}
diff --git a/web/apps/cast/src/services/wasm/ffmpeg.ts b/web/apps/cast/src/services/wasm/ffmpeg.ts
deleted file mode 100644
index 154f5ac61a..0000000000
--- a/web/apps/cast/src/services/wasm/ffmpeg.ts
+++ /dev/null
@@ -1,116 +0,0 @@
-import { addLogLine } from "@ente/shared/logging";
-import { logError } from "@ente/shared/sentry";
-import { promiseWithTimeout } from "@ente/shared/utils";
-import QueueProcessor from "@ente/shared/utils/queueProcessor";
-import { generateTempName } from "@ente/shared/utils/temp";
-import { createFFmpeg, FFmpeg } from "ffmpeg-wasm";
-import { getUint8ArrayView } from "services/readerService";
-
-const INPUT_PATH_PLACEHOLDER = "INPUT";
-const FFMPEG_PLACEHOLDER = "FFMPEG";
-const OUTPUT_PATH_PLACEHOLDER = "OUTPUT";
-
-const FFMPEG_EXECUTION_WAIT_TIME = 30 * 1000;
-
-export class WasmFFmpeg {
- private ffmpeg: FFmpeg;
- private ready: Promise<void> = null;
- private ffmpegTaskQueue = new QueueProcessor<File>();
-
- constructor() {
- this.ffmpeg = createFFmpeg({
- corePath: "/js/ffmpeg/ffmpeg-core.js",
- mt: false,
- });
-
- this.ready = this.init();
- }
-
- private async init() {
- if (!this.ffmpeg.isLoaded()) {
- await this.ffmpeg.load();
- }
- }
-
- async run(
- cmd: string[],
- inputFile: File,
- outputFileName: string,
- dontTimeout = false,
- ) {
- const response = this.ffmpegTaskQueue.queueUpRequest(() => {
- if (dontTimeout) {
- return this.execute(cmd, inputFile, outputFileName);
- } else {
- return promiseWithTimeout<File>(
- this.execute(cmd, inputFile, outputFileName),
- FFMPEG_EXECUTION_WAIT_TIME,
- );
- }
- });
- try {
- return await response.promise;
- } catch (e) {
- logError(e, "ffmpeg run failed");
- throw e;
- }
- }
-
- private async execute(
- cmd: string[],
- inputFile: File,
- outputFileName: string,
- ) {
- let tempInputFilePath: string;
- let tempOutputFilePath: string;
- try {
- await this.ready;
- const extension = getFileExtension(inputFile.name);
- const tempNameSuffix = extension ? `input.${extension}` : "input";
- tempInputFilePath = `${generateTempName(10, tempNameSuffix)}`;
- this.ffmpeg.FS(
- "writeFile",
- tempInputFilePath,
- await getUint8ArrayView(inputFile),
- );
- tempOutputFilePath = `${generateTempName(10, outputFileName)}`;
-
- cmd = cmd.map((cmdPart) => {
- if (cmdPart === FFMPEG_PLACEHOLDER) {
- return "";
- } else if (cmdPart === INPUT_PATH_PLACEHOLDER) {
- return tempInputFilePath;
- } else if (cmdPart === OUTPUT_PATH_PLACEHOLDER) {
- return tempOutputFilePath;
- } else {
- return cmdPart;
- }
- });
- addLogLine(`${cmd}`);
- await this.ffmpeg.run(...cmd);
- return new File(
- [this.ffmpeg.FS("readFile", tempOutputFilePath)],
- outputFileName,
- );
- } finally {
- try {
- this.ffmpeg.FS("unlink", tempInputFilePath);
- } catch (e) {
- logError(e, "unlink input file failed");
- }
- try {
- this.ffmpeg.FS("unlink", tempOutputFilePath);
- } catch (e) {
- logError(e, "unlink output file failed");
- }
- }
- }
-}
-
-function getFileExtension(filename: string) {
- const lastDotPosition = filename.lastIndexOf(".");
- if (lastDotPosition === -1) return null;
- else {
- return filename.slice(lastDotPosition + 1);
- }
-}
diff --git a/web/apps/cast/src/utils/comlink/ComlinkFFmpegWorker.ts b/web/apps/cast/src/utils/comlink/ComlinkFFmpegWorker.ts
deleted file mode 100644
index 77d140bdb8..0000000000
--- a/web/apps/cast/src/utils/comlink/ComlinkFFmpegWorker.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { Remote } from "comlink";
-import { DedicatedFFmpegWorker } from "worker/ffmpeg.worker";
-import { ComlinkWorker } from "./comlinkWorker";
-
-class ComlinkFFmpegWorker {
- private comlinkWorkerInstance: Promise<Remote<DedicatedFFmpegWorker>>;
-
- async getInstance() {
- if (!this.comlinkWorkerInstance) {
- const comlinkWorker = getDedicatedFFmpegWorker();
- this.comlinkWorkerInstance = comlinkWorker.remote;
- }
- return this.comlinkWorkerInstance;
- }
-}
-
-const getDedicatedFFmpegWorker = () => {
- const cryptoComlinkWorker = new ComlinkWorker<typeof DedicatedFFmpegWorker>(
- "ente-ffmpeg-worker",
- new Worker(new URL("worker/ffmpeg.worker.ts", import.meta.url)),
- );
- return cryptoComlinkWorker;
-};
-
-export default new ComlinkFFmpegWorker();
diff --git a/web/apps/cast/src/worker/ffmpeg.worker.ts b/web/apps/cast/src/worker/ffmpeg.worker.ts
deleted file mode 100644
index d3f503abb9..0000000000
--- a/web/apps/cast/src/worker/ffmpeg.worker.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import * as Comlink from "comlink";
-import { WasmFFmpeg } from "services/wasm/ffmpeg";
-
-export class DedicatedFFmpegWorker {
- wasmFFmpeg: WasmFFmpeg;
- constructor() {
- this.wasmFFmpeg = new WasmFFmpeg();
- }
-
- run(cmd, inputFile, outputFileName, dontTimeout) {
- return this.wasmFFmpeg.run(cmd, inputFile, outputFileName, dontTimeout);
- }
-}
-
-Comlink.expose(DedicatedFFmpegWorker, self);