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 { ElectronFile } from '../types';
|
||||
|
||||
export function runFFmpegCmd(
|
||||
export async function runFFmpegCmd(
|
||||
cmd: string[],
|
||||
inputFile: ElectronFile,
|
||||
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');
|
||||
import util from 'util';
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
import { getElectronFile } from './fs';
|
||||
import log from 'electron-log';
|
||||
import { rmSync } from 'promise-fs';
|
||||
import { readFile, rmSync } from 'promise-fs';
|
||||
import { logErrorSentry } from './sentry';
|
||||
import { generateTempName, getTempDirPath } from '../utils/temp';
|
||||
import { ElectronFile } from '../types';
|
||||
|
||||
export const INPUT_PATH_PLACEHOLDER = 'INPUT';
|
||||
export const FFMPEG_PLACEHOLDER = 'FFMPEG';
|
||||
|
@ -20,7 +18,7 @@ function getFFmpegStaticPath() {
|
|||
|
||||
export async function runFFmpegCmd(
|
||||
cmd: string[],
|
||||
inputFile: ElectronFile,
|
||||
inputFilePath: string,
|
||||
outputFileName: string
|
||||
) {
|
||||
let tempOutputFilePath: string;
|
||||
|
@ -36,7 +34,7 @@ export async function runFFmpegCmd(
|
|||
if (cmdPart === FFMPEG_PLACEHOLDER) {
|
||||
return getFFmpegStaticPath();
|
||||
} else if (cmdPart === INPUT_PATH_PLACEHOLDER) {
|
||||
return inputFile.path;
|
||||
return inputFilePath;
|
||||
} else if (cmdPart === OUTPUT_PATH_PLACEHOLDER) {
|
||||
return tempOutputFilePath;
|
||||
} else {
|
||||
|
@ -46,11 +44,10 @@ export async function runFFmpegCmd(
|
|||
cmd = shellescape(cmd);
|
||||
log.info('cmd', cmd);
|
||||
await exec(cmd);
|
||||
|
||||
const outputFile = await getElectronFile(tempOutputFilePath);
|
||||
return outputFile;
|
||||
return new Uint8Array(await readFile(tempOutputFilePath));
|
||||
} catch (e) {
|
||||
logErrorSentry(e, 'ffmpeg run command error');
|
||||
throw e;
|
||||
} finally {
|
||||
try {
|
||||
rmSync(tempOutputFilePath);
|
||||
|
|
|
@ -21,7 +21,6 @@ import {
|
|||
updateAndRestart,
|
||||
} from '../services/appUpdater';
|
||||
import { runFFmpegCmd } from '../services/ffmpeg';
|
||||
import { ElectronFile } from '../types';
|
||||
|
||||
export default function setupIpcComs(
|
||||
tray: Tray,
|
||||
|
@ -130,8 +129,8 @@ export default function setupIpcComs(
|
|||
|
||||
ipcMain.handle(
|
||||
'run-ffmpeg-cmd',
|
||||
(_, cmd: string[], inputFile: ElectronFile, outputFileName: string) => {
|
||||
return runFFmpegCmd(cmd, inputFile, outputFileName);
|
||||
(_, cmd: string[], inputFilePath: string, outputFileName: string) => {
|
||||
return runFFmpegCmd(cmd, inputFilePath, outputFileName);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue