Skip to content

armgit / ente

Public Imported from GitHub
0

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

Sketch

Manav Rathi782008e5d32b
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index b0a2eccf0c..97d7b36569 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -13,6 +13,7 @@ import type { BrowserWindow } from "electron";
import { ipcMain } from "electron/main";
import type {
CollectionMapping,
+ FFmpegCommand,
FolderWatch,
PendingUploads,
ZipItem,
@@ -187,7 +188,7 @@ export const attachIPCHandlers = () => {
"ffmpegExec",
(
_,
- command: string[],
+ command: FFmpegCommand,
dataOrPathOrZipItem: Uint8Array | string | ZipItem,
outputFileExtension: string,
) => ffmpegExec(command, dataOrPathOrZipItem, outputFileExtension),
diff --git a/desktop/src/main/services/ffmpeg.ts b/desktop/src/main/services/ffmpeg.ts
index 4a6485c37d..8d1b074fbf 100644
--- a/desktop/src/main/services/ffmpeg.ts
+++ b/desktop/src/main/services/ffmpeg.ts
@@ -2,7 +2,7 @@ import pathToFfmpeg from "ffmpeg-static";
import { randomBytes } from "node:crypto";
import fs from "node:fs/promises";
import path, { basename } from "node:path";
-import type { ZipItem } from "../../types/ipc";
+import type { FFmpegCommand, ZipItem } from "../../types/ipc";
import log from "../log";
import { execAsync } from "../utils/electron";
import {
@@ -44,7 +44,7 @@ const outputPathPlaceholder = "OUTPUT";
* But I'm not sure if our code is supposed to be able to use it, and how.
*/
export const ffmpegExec = async (
- command: string[],
+ command: FFmpegCommand,
dataOrPathOrZipItem: Uint8Array | string | ZipItem,
outputFileExtension: string,
): Promise<Uint8Array> => {
@@ -58,8 +58,12 @@ export const ffmpegExec = async (
try {
await writeToTemporaryInputFile();
+ const resolvedCommand = Array.isArray(command)
+ ? command
+ : command.default;
+
const cmd = substitutePlaceholders(
- command,
+ resolvedCommand,
inputFilePath,
outputFilePath,
);
@@ -251,6 +255,9 @@ export const ffmpegGenerateHLSPlaylistAndSegments = async (
// brightness drop. So we conditionally apply this filter chain only if the
// colorspace is not already BT.709.
//
+ // See also: [Note: Alternative FFmpeg command for HDR videos], although
+ // that uses a allow-list based check (while here we use deny-list).
+ //
// Reference:
// - https://trac.ffmpeg.org/wiki/colorspace
const tonemap = !isBT709;
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index 0260beb36d..0c96d61b30 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -66,6 +66,7 @@ import type { IpcRendererEvent } from "electron";
import type {
AppUpdate,
CollectionMapping,
+ FFmpegCommand,
FolderWatch,
PendingUploads,
ZipItem,
@@ -201,7 +202,7 @@ const generateImageThumbnail = (
);
const ffmpegExec = (
- command: string[],
+ command: FFmpegCommand,
dataOrPathOrZipItem: Uint8Array | string | ZipItem,
outputFileExtension: string,
) =>
diff --git a/desktop/src/types/ipc.ts b/desktop/src/types/ipc.ts
index f61cd71a2a..7701836217 100644
--- a/desktop/src/types/ipc.ts
+++ b/desktop/src/types/ipc.ts
@@ -32,3 +32,5 @@ export interface PendingUploads {
filePaths: string[];
zipItems: ZipItem[];
}
+
+export type FFmpegCommand = string[] | { default: string[]; hdr: string[] };
diff --git a/web/packages/base/types/ipc.ts b/web/packages/base/types/ipc.ts
index b27fade8dd..345efd30f7 100644
--- a/web/packages/base/types/ipc.ts
+++ b/web/packages/base/types/ipc.ts
@@ -359,7 +359,7 @@ export interface Electron {
* (specified as {@link outputPathPlaceholder} in {@link command}).
*/
ffmpegExec: (
- command: string[],
+ command: FFmpegCommand,
dataOrPathOrZipItem: Uint8Array | string | ZipItem,
outputFileExtension: string,
) => Promise<Uint8Array>;
@@ -740,3 +740,15 @@ export interface PendingUploads {
*/
zipItems: ZipItem[];
}
+
+/**
+ * A command that we can ask FFmpeg to run for us.
+ *
+ * [Note: Alternative FFmpeg command for HDR videos]
+ *
+ * Usually, this is a single command (specified as an array of strings
+ * containing the "words" of the command). However, we can also provide two
+ * alternative commands - one to run when the input is (heuristically) detected
+ * as a HDR video, and one otherwise.
+ */
+export type FFmpegCommand = string[] | { default: string[]; hdr: string[] };