Skip to content

The swiss army knife of lossless video/audio editing

allow custom output dir for merge and extract also

Mikael Finstad7c34b50f7ff6
diff --git a/src/ffmpeg.js b/src/ffmpeg.js
index cc030ec1..ee532ef9 100644
--- a/src/ffmpeg.js
+++ b/src/ffmpeg.js
@@ -202,10 +202,10 @@ async function mergeFiles(paths, outPath) {
console.log(result.stdout);
}
-async function mergeAnyFiles(paths) {
+async function mergeAnyFiles({ customOutDir, paths }) {
const firstPath = paths[0];
const ext = path.extname(firstPath);
- const outPath = `${firstPath}-merged${ext}`;
+ const outPath = getOutPath(customOutDir, firstPath, `merged${ext}`);
return mergeFiles(paths, outPath);
}
@@ -293,7 +293,7 @@ function mapCodecToOutputFormat(codec, type) {
}
// https://stackoverflow.com/questions/32922226/extract-every-audio-and-subtitles-from-a-video-with-ffmpeg
-async function extractAllStreams(filePath) {
+async function extractAllStreams({ customOutDir, filePath }) {
const { streams } = await getAllStreams(filePath);
console.log('streams', streams);
@@ -310,7 +310,7 @@ async function extractAllStreams(filePath) {
const streamArgs = flatMap(outStreams, ({
i, codec, type, format: { format, ext },
}) => [
- '-map', `0:${i}`, '-c', 'copy', '-f', format, '-y', `${filePath}-${i}-${type}-${codec}.${ext}`,
+ '-map', `0:${i}`, '-c', 'copy', '-f', format, '-y', getOutPath(customOutDir, filePath, `${i}-${type}-${codec}.${ext}`),
]);
const ffmpegArgs = [
diff --git a/src/renderer.jsx b/src/renderer.jsx
index 83184108..ef4b8af6 100644
--- a/src/renderer.jsx
+++ b/src/renderer.jsx
@@ -168,9 +168,10 @@ class App extends React.Component {
try {
this.setState({ working: true });
- // TODO customOutDir ?
+ const { customOutDir } = this.state;
+
// console.log('merge', paths);
- await ffmpeg.mergeAnyFiles(paths);
+ await ffmpeg.mergeAnyFiles({ customOutDir, paths });
} catch (err) {
errorToast('Failed to merge files. Make sure they are all of the exact same format and codecs');
console.error('Failed to merge files', err);
@@ -192,13 +193,12 @@ class App extends React.Component {
});
electron.ipcRenderer.on('extract-all-streams', async () => {
- const { filePath } = this.state;
+ const { filePath, customOutDir } = this.state;
if (!filePath) return;
try {
this.setState({ working: true });
- // TODO customOutDir ?
- await ffmpeg.extractAllStreams(filePath);
+ await ffmpeg.extractAllStreams({ customOutDir, filePath });
this.setState({ working: false });
} catch (err) {
errorToast('Failed to extract all streams');