π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove ffmpeg timeout
Manav Rathibf7c97c0067e
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex b0e0e8ba16..5072db29ea 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -174,14 +174,7 @@ export const attachIPCHandlers = () => {command: string[],dataOrPathOrZipItem: Uint8Array | string | ZipItem,outputFileExtension: string,- timeoutMS: number,- ) =>- ffmpegExec(- command,- dataOrPathOrZipItem,- outputFileExtension,- timeoutMS,- ),+ ) => ffmpegExec(command, dataOrPathOrZipItem, outputFileExtension),);// - MLdiff --git a/desktop/src/main/services/app-update.ts b/desktop/src/main/services/app-update.tsindex c12e1e3193..ed6dc0e18f 100644--- a/desktop/src/main/services/app-update.ts+++ b/desktop/src/main/services/app-update.ts@@ -140,17 +140,17 @@ const checkForUpdatesAndNotify = async (mainWindow: BrowserWindow) => {log.debug(() => "Attempting auto update");await autoUpdater.downloadUpdate();- let timeoutId: ReturnType<typeof setTimeout>;+ let timeout: ReturnType<typeof setTimeout>;const fiveMinutes = 5 * 60 * 1000;autoUpdater.on("update-downloaded", () => {- timeoutId = setTimeout(+ timeout = setTimeout(() => showUpdateDialog({ autoUpdatable: true, version }),fiveMinutes,);});autoUpdater.on("error", (error) => {- clearTimeout(timeoutId);+ clearTimeout(timeout);log.error("Auto update failed", error);showUpdateDialog({ autoUpdatable: false, version });});diff --git a/desktop/src/main/services/ffmpeg.ts b/desktop/src/main/services/ffmpeg.tsindex ddbb31e4c2..1860b89a44 100644--- a/desktop/src/main/services/ffmpeg.ts+++ b/desktop/src/main/services/ffmpeg.ts@@ -1,7 +1,7 @@import pathToFfmpeg from "ffmpeg-static";import fs from "node:fs/promises";import type { ZipItem } from "../../types/ipc";-import { ensure, withTimeout } from "../utils/common";+import { ensure } from "../utils/common";import { execAsync } from "../utils/electron";import {deleteTempFileIgnoringErrors,@@ -45,7 +45,6 @@ export const ffmpegExec = async (command: string[],dataOrPathOrZipItem: Uint8Array | string | ZipItem,outputFileExtension: string,- timeoutMS: number,): Promise<Uint8Array> => {// TODO (MR): This currently copies files for both input (when// dataOrPathOrZipItem is data) and output. This needs to be tested@@ -68,8 +67,7 @@ export const ffmpegExec = async (outputFilePath,);- if (timeoutMS) await withTimeout(execAsync(cmd), timeoutMS);- else await execAsync(cmd);+ await execAsync(cmd);return fs.readFile(outputFilePath);} finally {@@ -135,5 +133,5 @@ export const ffmpegConvertToMP4 = async (const cmd = substitutePlaceholders(command, inputFilePath, outputFilePath);- await withTimeout(execAsync(cmd), 30 * 1000);+ await execAsync(cmd);};diff --git a/desktop/src/main/utils/common.ts b/desktop/src/main/utils/common.tsindex 1f5016e617..5ed46aa8a1 100644--- a/desktop/src/main/utils/common.ts+++ b/desktop/src/main/utils/common.ts@@ -13,32 +13,3 @@ export const ensure = <T>(v: T | null | undefined): T => {if (v === undefined) throw new Error("Required value was not found");return v;};--/**- * Wait for {@link ms} milliseconds- *- * This function is a promisified `setTimeout`. It returns a promise that- * resolves after {@link ms} milliseconds.- */-export const wait = (ms: number) =>- new Promise((resolve) => setTimeout(resolve, ms));--/**- * Await the given {@link promise} for {@link timeoutMS} milliseconds. If it- * does not resolve within {@link timeoutMS}, then reject with a timeout error.- */-export const withTimeout = async <T>(promise: Promise<T>, ms: number) => {- let timeoutId: ReturnType<typeof setTimeout>;- const rejectOnTimeout = new Promise<T>((_, reject) => {- timeoutId = setTimeout(- () => reject(new Error("Operation timed out")),- ms,- );- });- const promiseAndCancelTimeout = async () => {- const result = await promise;- clearTimeout(timeoutId);- return result;- };- return Promise.race([promiseAndCancelTimeout(), rejectOnTimeout]);-};diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex cad2f14c75..d52745184e 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -143,14 +143,12 @@ const ffmpegExec = (command: string[],dataOrPathOrZipItem: Uint8Array | string | ZipItem,outputFileExtension: string,- timeoutMS: number,) =>ipcRenderer.invoke("ffmpegExec",command,dataOrPathOrZipItem,outputFileExtension,- timeoutMS,);// - MLdiff --git a/web/apps/photos/src/services/ffmpeg.ts b/web/apps/photos/src/services/ffmpeg.tsindex f50c978f0b..85dd5db397 100644--- a/web/apps/photos/src/services/ffmpeg.ts+++ b/web/apps/photos/src/services/ffmpeg.ts@@ -36,7 +36,7 @@ import {*/export const generateVideoThumbnailWeb = async (blob: Blob) =>_generateVideoThumbnail((seekTime: number) =>- ffmpegExecWeb(makeGenThumbnailCommand(seekTime), blob, "jpeg", 0),+ ffmpegExecWeb(makeGenThumbnailCommand(seekTime), blob, "jpeg"),);const _generateVideoThumbnail = async (@@ -75,7 +75,6 @@ export const generateVideoThumbnailNative = async (makeGenThumbnailCommand(seekTime),toDataOrPathOrZipEntry(desktopUploadItem),"jpeg",- 0,),);@@ -112,12 +111,11 @@ export const extractVideoMetadata = async (const command = extractVideoMetadataCommand;const outputData =uploadItem instanceof File- ? await ffmpegExecWeb(command, uploadItem, "txt", 0)+ ? await ffmpegExecWeb(command, uploadItem, "txt"): await electron.ffmpegExec(command,toDataOrPathOrZipEntry(uploadItem),"txt",- 0,);return parseFFmpegExtractedMetadata(outputData);@@ -224,10 +222,9 @@ const ffmpegExecWeb = async (command: string[],blob: Blob,outputFileExtension: string,- timeoutMs: number,) => {const worker = await workerFactory.lazy();- return await worker.exec(command, blob, outputFileExtension, timeoutMs);+ return await worker.exec(command, blob, outputFileExtension);};/**@@ -246,19 +243,15 @@ export const convertToMP4 = async (blob: Blob): Promise<Blob | Uint8Array> => {if (electron) {return convertToMP4Native(electron, blob);} else {- return ffmpegExecWeb(- [- ffmpegPathPlaceholder,- "-i",- inputPathPlaceholder,- "-preset",- "ultrafast",- outputPathPlaceholder,- ],- blob,- "mp4",- 30 * 1000,- );+ const command = [+ ffmpegPathPlaceholder,+ "-i",+ inputPathPlaceholder,+ "-preset",+ "ultrafast",+ outputPathPlaceholder,+ ];+ return ffmpegExecWeb(command, blob, "mp4");}};diff --git a/web/apps/photos/src/worker/ffmpeg.worker.ts b/web/apps/photos/src/worker/ffmpeg.worker.tsindex 408c2197c5..d9d6c718f8 100644--- a/web/apps/photos/src/worker/ffmpeg.worker.ts+++ b/web/apps/photos/src/worker/ffmpeg.worker.ts@@ -1,5 +1,4 @@import log from "@/next/log";-import { withTimeout } from "@/utils/promise";import QueueProcessor from "@ente/shared/utils/queueProcessor";import { expose } from "comlink";import {@@ -48,15 +47,11 @@ export class DedicatedFFmpegWorker {command: string[],blob: Blob,outputFileExtension: string,- timeoutMs,): Promise<Uint8Array> {if (!this.ffmpeg.isLoaded()) await this.ffmpeg.load();- const go = () =>- ffmpegExec(this.ffmpeg, command, outputFileExtension, blob);-const request = this.ffmpegTaskQueue.queueUpRequest(() =>- timeoutMs ? withTimeout(go(), timeoutMs) : go(),+ ffmpegExec(this.ffmpeg, command, outputFileExtension, blob),);return await request.promise;diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex 78e9b7fd69..d91f7bf3fa 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -267,7 +267,7 @@ export interface Electron {* This executes the command using a FFmpeg executable we bundle with our* desktop app. We also have a wasm FFmpeg wasm implementation that we use* when running on the web, which has a sibling function with the same- * parameters. See [Note: ffmpeg in Electron].+ * parameters. See [Note:FFmpeg in Electron].** @param command An array of strings, each representing one positional* parameter in the command to execute. Placeholders for the input, output@@ -287,9 +287,6 @@ export interface Electron {* just return its contents, for some FFmpeg command the extension matters* (e.g. conversion to a JPEG fails if the extension is arbitrary).*- * @param timeoutMS If non-zero, then abort and throw a timeout error if the- * ffmpeg command takes more than the given number of milliseconds.- ** @returns The contents of the output file produced by the ffmpeg command* (specified as {@link outputPathPlaceholder} in {@link command}).*/@@ -297,7 +294,6 @@ export interface Electron {command: string[],dataOrPathOrZipItem: Uint8Array | string | ZipItem,outputFileExtension: string,- timeoutMS: number,) => Promise<Uint8Array>;// - ML