update to pass filePath instead of whole File
This commit is contained in:
parent
756b04750e
commit
2875dbce07
|
@ -1,10 +1,16 @@
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import { ElectronFile } from '../types';
|
import { ElectronFile } from '../types';
|
||||||
|
|
||||||
export function runFFmpegCmd(
|
export async function runFFmpegCmd(
|
||||||
cmd: string[],
|
cmd: string[],
|
||||||
inputFile: ElectronFile,
|
inputFile: ElectronFile,
|
||||||
outputFileName: string
|
outputFileName: string
|
||||||
) {
|
) {
|
||||||
return ipcRenderer.invoke('run-ffmpeg-cmd', cmd, inputFile, outputFileName);
|
const fileData = await ipcRenderer.invoke(
|
||||||
|
'run-ffmpeg-cmd',
|
||||||
|
cmd,
|
||||||
|
inputFile.path,
|
||||||
|
outputFileName
|
||||||
|
);
|
||||||
|
return new File([fileData], outputFileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@ import path from 'path';
|
||||||
const shellescape = require('any-shell-escape');
|
const shellescape = require('any-shell-escape');
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const exec = util.promisify(require('child_process').exec);
|
||||||
import { getElectronFile } from './fs';
|
|
||||||
import log from 'electron-log';
|
import log from 'electron-log';
|
||||||
import { rmSync } from 'promise-fs';
|
import { readFile, rmSync } from 'promise-fs';
|
||||||
import { logErrorSentry } from './sentry';
|
import { logErrorSentry } from './sentry';
|
||||||
import { generateTempName, getTempDirPath } from '../utils/temp';
|
import { generateTempName, getTempDirPath } from '../utils/temp';
|
||||||
import { ElectronFile } from '../types';
|
|
||||||
|
|
||||||
export const INPUT_PATH_PLACEHOLDER = 'INPUT';
|
export const INPUT_PATH_PLACEHOLDER = 'INPUT';
|
||||||
export const FFMPEG_PLACEHOLDER = 'FFMPEG';
|
export const FFMPEG_PLACEHOLDER = 'FFMPEG';
|
||||||
|
@ -20,7 +18,7 @@ function getFFmpegStaticPath() {
|
||||||
|
|
||||||
export async function runFFmpegCmd(
|
export async function runFFmpegCmd(
|
||||||
cmd: string[],
|
cmd: string[],
|
||||||
inputFile: ElectronFile,
|
inputFilePath: string,
|
||||||
outputFileName: string
|
outputFileName: string
|
||||||
) {
|
) {
|
||||||
let tempOutputFilePath: string;
|
let tempOutputFilePath: string;
|
||||||
|
@ -36,7 +34,7 @@ export async function runFFmpegCmd(
|
||||||
if (cmdPart === FFMPEG_PLACEHOLDER) {
|
if (cmdPart === FFMPEG_PLACEHOLDER) {
|
||||||
return getFFmpegStaticPath();
|
return getFFmpegStaticPath();
|
||||||
} else if (cmdPart === INPUT_PATH_PLACEHOLDER) {
|
} else if (cmdPart === INPUT_PATH_PLACEHOLDER) {
|
||||||
return inputFile.path;
|
return inputFilePath;
|
||||||
} else if (cmdPart === OUTPUT_PATH_PLACEHOLDER) {
|
} else if (cmdPart === OUTPUT_PATH_PLACEHOLDER) {
|
||||||
return tempOutputFilePath;
|
return tempOutputFilePath;
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,11 +44,10 @@ export async function runFFmpegCmd(
|
||||||
cmd = shellescape(cmd);
|
cmd = shellescape(cmd);
|
||||||
log.info('cmd', cmd);
|
log.info('cmd', cmd);
|
||||||
await exec(cmd);
|
await exec(cmd);
|
||||||
|
return new Uint8Array(await readFile(tempOutputFilePath));
|
||||||
const outputFile = await getElectronFile(tempOutputFilePath);
|
|
||||||
return outputFile;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logErrorSentry(e, 'ffmpeg run command error');
|
logErrorSentry(e, 'ffmpeg run command error');
|
||||||
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
rmSync(tempOutputFilePath);
|
rmSync(tempOutputFilePath);
|
||||||
|
|
|
@ -21,7 +21,6 @@ import {
|
||||||
updateAndRestart,
|
updateAndRestart,
|
||||||
} from '../services/appUpdater';
|
} from '../services/appUpdater';
|
||||||
import { runFFmpegCmd } from '../services/ffmpeg';
|
import { runFFmpegCmd } from '../services/ffmpeg';
|
||||||
import { ElectronFile } from '../types';
|
|
||||||
|
|
||||||
export default function setupIpcComs(
|
export default function setupIpcComs(
|
||||||
tray: Tray,
|
tray: Tray,
|
||||||
|
@ -130,8 +129,8 @@ export default function setupIpcComs(
|
||||||
|
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
'run-ffmpeg-cmd',
|
'run-ffmpeg-cmd',
|
||||||
(_, cmd: string[], inputFile: ElectronFile, outputFileName: string) => {
|
(_, cmd: string[], inputFilePath: string, outputFileName: string) => {
|
||||||
return runFFmpegCmd(cmd, inputFile, outputFileName);
|
return runFFmpegCmd(cmd, inputFilePath, outputFileName);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue