commit
ba26969e5b
|
@ -7,7 +7,8 @@ import { ElectronFile } from '../types';
|
|||
export async function runFFmpegCmd(
|
||||
cmd: string[],
|
||||
inputFile: File | ElectronFile,
|
||||
outputFileName: string
|
||||
outputFileName: string,
|
||||
dontTimeout?: boolean
|
||||
) {
|
||||
let inputFilePath = null;
|
||||
let createdTempInputFile = null;
|
||||
|
@ -27,7 +28,8 @@ export async function runFFmpegCmd(
|
|||
'run-ffmpeg-cmd',
|
||||
cmd,
|
||||
inputFilePath,
|
||||
outputFileName
|
||||
outputFileName,
|
||||
dontTimeout
|
||||
);
|
||||
return new File([outputFileData], outputFileName);
|
||||
} finally {
|
||||
|
|
|
@ -2,4 +2,5 @@ export const CustomErrors = {
|
|||
WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED:
|
||||
'Windows native image processing is not supported',
|
||||
INVALID_OS: (os: string) => `Invalid OS - ${os}`,
|
||||
WAIT_TIME_EXCEEDED: 'Wait time exceeded',
|
||||
};
|
||||
|
|
|
@ -6,9 +6,12 @@ import { readFile, rmSync, writeFile } from 'promise-fs';
|
|||
import { logErrorSentry } from './sentry';
|
||||
import { generateTempFilePath, getTempDirPath } from '../utils/temp';
|
||||
import { existsSync } from 'fs';
|
||||
import { promiseWithTimeout } from '../utils/common';
|
||||
|
||||
const execAsync = util.promisify(require('child_process').exec);
|
||||
|
||||
const FFMPEG_EXECUTION_WAIT_TIME = 30 * 1000;
|
||||
|
||||
const INPUT_PATH_PLACEHOLDER = 'INPUT';
|
||||
const FFMPEG_PLACEHOLDER = 'FFMPEG';
|
||||
const OUTPUT_PATH_PLACEHOLDER = 'OUTPUT';
|
||||
|
@ -20,7 +23,8 @@ function getFFmpegStaticPath() {
|
|||
export async function runFFmpegCmd(
|
||||
cmd: string[],
|
||||
inputFilePath: string,
|
||||
outputFileName: string
|
||||
outputFileName: string,
|
||||
dontTimeout = false
|
||||
) {
|
||||
let tempOutputFilePath: string;
|
||||
try {
|
||||
|
@ -40,7 +44,14 @@ export async function runFFmpegCmd(
|
|||
const escapedCmd = shellescape(cmd);
|
||||
log.info('running ffmpeg command', escapedCmd);
|
||||
const startTime = Date.now();
|
||||
await execAsync(escapedCmd);
|
||||
if (dontTimeout) {
|
||||
await execAsync(escapedCmd);
|
||||
} else {
|
||||
await promiseWithTimeout(
|
||||
execAsync(escapedCmd),
|
||||
FFMPEG_EXECUTION_WAIT_TIME
|
||||
);
|
||||
}
|
||||
if (!existsSync(tempOutputFilePath)) {
|
||||
throw new Error('ffmpeg output file not found');
|
||||
}
|
||||
|
|
|
@ -1,2 +1,27 @@
|
|||
import { CustomErrors } from '../../constants/errors';
|
||||
import { app } from 'electron';
|
||||
export const isDev = !app.isPackaged;
|
||||
|
||||
export const promiseWithTimeout = async <T>(
|
||||
request: Promise<T>,
|
||||
timeout: number
|
||||
): Promise<T> => {
|
||||
const timeoutRef: {
|
||||
current: NodeJS.Timeout;
|
||||
} = { current: null };
|
||||
const rejectOnTimeout = new Promise<null>((_, reject) => {
|
||||
timeoutRef.current = setTimeout(
|
||||
() => reject(Error(CustomErrors.WAIT_TIME_EXCEEDED)),
|
||||
timeout
|
||||
);
|
||||
});
|
||||
const requestWithTimeOutCancellation = async () => {
|
||||
const resp = await request;
|
||||
clearTimeout(timeoutRef.current);
|
||||
return resp;
|
||||
};
|
||||
return await Promise.race([
|
||||
requestWithTimeOutCancellation(),
|
||||
rejectOnTimeout,
|
||||
]);
|
||||
};
|
||||
|
|
|
@ -137,8 +137,13 @@ export default function setupIpcComs(
|
|||
|
||||
ipcMain.handle(
|
||||
'run-ffmpeg-cmd',
|
||||
(_, cmd, inputFilePath, outputFileName) => {
|
||||
return runFFmpegCmd(cmd, inputFilePath, outputFileName);
|
||||
(_, cmd, inputFilePath, outputFileName, dontTimeout) => {
|
||||
return runFFmpegCmd(
|
||||
cmd,
|
||||
inputFilePath,
|
||||
outputFileName,
|
||||
dontTimeout
|
||||
);
|
||||
}
|
||||
);
|
||||
ipcMain.handle('get-temp-file-path', (_, formatSuffix) => {
|
||||
|
|
2
ui
2
ui
|
@ -1 +1 @@
|
|||
Subproject commit 914967030603895b08a3c33b7eacdd55a3bc62e0
|
||||
Subproject commit dbdae0d4a9c4bc1deceaa840a20bac2654b97701
|
Loading…
Reference in a new issue