This commit is contained in:
Manav Rathi 2024-04-20 20:02:16 +05:30
parent 5992efd58a
commit 8d6787b823
No known key found for this signature in database
5 changed files with 39 additions and 41 deletions

View file

@ -10,7 +10,7 @@ import { isPlaybackPossible } from "@ente/shared/media/video-playback";
import { Remote } from "comlink"; import { Remote } from "comlink";
import { FILE_TYPE } from "constants/file"; import { FILE_TYPE } from "constants/file";
import isElectron from "is-electron"; import isElectron from "is-electron";
import * as ffmpegService from "services/ffmpeg/ffmpegService"; import * as ffmpegService from "services/ffmpeg";
import { EnteFile } from "types/file"; import { EnteFile } from "types/file";
import { generateStreamFromArrayBuffer, getRenderableImage } from "utils/file"; import { generateStreamFromArrayBuffer, getRenderableImage } from "utils/file";
import { PhotosDownloadClient } from "./clients/photos"; import { PhotosDownloadClient } from "./clients/photos";

View file

@ -5,8 +5,8 @@ import {
OUTPUT_PATH_PLACEHOLDER, OUTPUT_PATH_PLACEHOLDER,
} from "constants/ffmpeg"; } from "constants/ffmpeg";
import { ElectronFile } from "types/upload"; import { ElectronFile } from "types/upload";
import ComlinkFFmpegWorker from "utils/comlink/ComlinkFFmpegWorker";
import { parseFFmpegExtractedMetadata } from "utils/ffmpeg"; import { parseFFmpegExtractedMetadata } from "utils/ffmpeg";
import ffmpegFactory from "./ffmpegFactory";
export async function generateVideoThumbnail( export async function generateVideoThumbnail(
file: File | ElectronFile, file: File | ElectronFile,
@ -98,3 +98,38 @@ export async function convertToMP4(file: File | ElectronFile) {
throw e; throw e;
} }
} }
interface IFFmpeg {
run: (
cmd: string[],
inputFile: File | ElectronFile,
outputFilename: string,
dontTimeout?: boolean,
) => Promise<File | ElectronFile>;
}
class FFmpegFactory {
private client: IFFmpeg;
async getFFmpegClient() {
if (!this.client) {
const electron = globalThis.electron;
if (electron) {
this.client = {
run(cmd, inputFile, outputFilename, dontTimeout) {
return electron.runFFmpegCmd(
cmd,
inputFile,
outputFilename,
dontTimeout,
);
},
};
} else {
this.client = await ComlinkFFmpegWorker.getInstance();
}
}
return this.client;
}
}
const ffmpegFactory = new FFmpegFactory();

View file

@ -1,37 +0,0 @@
import { ElectronFile } from "types/upload";
import ComlinkFFmpegWorker from "utils/comlink/ComlinkFFmpegWorker";
export interface IFFmpeg {
run: (
cmd: string[],
inputFile: File | ElectronFile,
outputFilename: string,
dontTimeout?: boolean,
) => Promise<File | ElectronFile>;
}
class FFmpegFactory {
private client: IFFmpeg;
async getFFmpegClient() {
if (!this.client) {
const electron = globalThis.electron;
if (electron) {
this.client = {
run(cmd, inputFile, outputFilename, dontTimeout) {
return electron.runFFmpegCmd(
cmd,
inputFile,
outputFilename,
dontTimeout,
);
},
};
} else {
this.client = await ComlinkFFmpegWorker.getInstance();
}
}
return this.client;
}
}
export default new FFmpegFactory();

View file

@ -11,7 +11,7 @@ import {
import { Remote } from "comlink"; import { Remote } from "comlink";
import { FILE_TYPE } from "constants/file"; import { FILE_TYPE } from "constants/file";
import { FILE_READER_CHUNK_SIZE, NULL_LOCATION } from "constants/upload"; import { FILE_READER_CHUNK_SIZE, NULL_LOCATION } from "constants/upload";
import * as ffmpegService from "services/ffmpeg/ffmpegService"; import * as ffmpegService from "services/ffmpeg";
import { getElectronFileStream, getFileStream } from "services/readerService"; import { getElectronFileStream, getFileStream } from "services/readerService";
import { getFileType } from "services/typeDetectionService"; import { getFileType } from "services/typeDetectionService";
import { FilePublicMagicMetadataProps } from "types/file"; import { FilePublicMagicMetadataProps } from "types/file";

View file

@ -4,7 +4,7 @@ import { CustomErrorMessage, type Electron } from "@/next/types/ipc";
import { CustomError } from "@ente/shared/error"; import { CustomError } from "@ente/shared/error";
import { FILE_TYPE } from "constants/file"; import { FILE_TYPE } from "constants/file";
import { BLACK_THUMBNAIL_BASE64 } from "constants/upload"; import { BLACK_THUMBNAIL_BASE64 } from "constants/upload";
import * as FFmpegService from "services/ffmpeg/ffmpegService"; import * as FFmpegService from "services/ffmpeg";
import HeicConversionService from "services/heicConversionService"; import HeicConversionService from "services/heicConversionService";
import { ElectronFile, FileTypeInfo } from "types/upload"; import { ElectronFile, FileTypeInfo } from "types/upload";
import { isFileHEIC } from "utils/file"; import { isFileHEIC } from "utils/file";