Skip to content

The swiss army knife of lossless video/audio editing

Also save to custom output dir when capturing frame

Mikael Finstadf70c994b9fe3
diff --git a/src/capture-frame.js b/src/capture-frame.js
index 125ff5ba..aa4a38ab 100644
--- a/src/capture-frame.js
+++ b/src/capture-frame.js
@@ -3,6 +3,8 @@ const fs = require('fs');
const mime = require('mime-types');
const strongDataUri = require('strong-data-uri');
+const util = require('./util');
+
bluebird.promisifyAll(fs);
function getFrameFromVideo(video) {
@@ -19,10 +21,13 @@ function getFrameFromVideo(video) {
return strongDataUri.decode(dataUri);
}
-function captureFrame(video, outPathWithoutExt) {
+function captureFrame(customOutDir, filePath, video, currentTime) {
const buf = getFrameFromVideo(video);
+
const ext = mime.extension(buf.mimetype);
- const outPath = `${outPathWithoutExt}.${ext}`;
+ const time = util.formatDuration(currentTime);
+
+ const outPath = util.getOutPath(customOutDir, filePath, `${time}.${ext}`);
return fs.writeFileAsync(outPath, buf);
}
diff --git a/src/ffmpeg.js b/src/ffmpeg.js
index c02afe0f..2b70d157 100644
--- a/src/ffmpeg.js
+++ b/src/ffmpeg.js
@@ -35,14 +35,13 @@ function getFfmpegPath() {
});
}
-function cut(outputDir, filePath, format, cutFrom, cutTo) {
+function cut(customOutDir, filePath, format, cutFrom, cutTo) {
return bluebird.try(() => {
- const ext = path.extname(filePath) || `.${format}`;
+ const extWithoutDot = path.extname(filePath) || `.${format}`;
+ const ext = `.${extWithoutDot}`;
const duration = `${util.formatDuration(cutFrom)}-${util.formatDuration(cutTo)}`;
- const basename = path.basename(filePath);
- const outFile = outputDir ?
- path.join(outputDir, `${basename}-${duration}${ext}`) :
- `${filePath}-${duration}${ext}`;
+
+ const outPath = util.getOutPath(customOutDir, filePath, `${duration}${ext}`);
console.log('Cutting from', cutFrom, 'to', cutTo);
@@ -50,7 +49,7 @@ function cut(outputDir, filePath, format, cutFrom, cutTo) {
'-i', filePath, '-y', '-vcodec', 'copy', '-acodec', 'copy',
'-ss', cutFrom, '-t', cutTo - cutFrom,
'-f', format,
- outFile,
+ outPath,
];
console.log('ffmpeg', ffmpegArgs.join(' '));
diff --git a/src/renderer.jsx b/src/renderer.jsx
index 94dd24e2..f445e294 100644
--- a/src/renderer.jsx
+++ b/src/renderer.jsx
@@ -257,9 +257,11 @@ class App extends React.Component {
}
capture() {
- if (!this.state.filePath) return;
- const outPathWithoutExt = `${this.state.filePath}-${util.formatDuration(this.state.currentTime)}`;
- captureFrame(getVideo(), outPathWithoutExt).catch(err => alert(err));
+ const filePath = this.state.filePath;
+ const outputDir = this.state.outputDir;
+ const currentTime = this.state.currentTime;
+ if (!filePath) return;
+ captureFrame(outputDir, filePath, getVideo(), currentTime).catch(err => alert(err));
}
toggleHelp() {
diff --git a/src/util.js b/src/util.js
index f8de2853..8c3a614f 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,4 +1,5 @@
const _ = require('lodash');
+const path = require('path');
function formatDuration(_seconds) {
const seconds = _seconds || 0;
@@ -14,6 +15,15 @@ function formatDuration(_seconds) {
return `${hoursPadded}.${minutesPadded}.${secondsPadded}.${msPadded}`;
}
+function getOutPath(customOutDir, filePath, nameSuffix) {
+ const basename = path.basename(filePath);
+
+ return customOutDir ?
+ path.join(customOutDir, `${basename}-${nameSuffix}`) :
+ `${filePath}-${nameSuffix}`;
+}
+
module.exports = {
formatDuration,
+ getOutPath,
};