Skip to content

The swiss army knife of lossless video/audio editing

Bugfixes

Mikael Finstad4493aa5572bd
diff --git a/src/ffmpeg.js b/src/ffmpeg.js
index b2aa3d38..71809c4c 100644
--- a/src/ffmpeg.js
+++ b/src/ffmpeg.js
@@ -55,21 +55,24 @@ function handleProgress(process, cutDuration, onProgress) {
});
}
-async function cut(customOutDir, filePath, format, cutFrom, cutTo, rotation, onProgress) {
- const extWithoutDot = path.extname(filePath) || `.${format}`;
- const ext = `.${extWithoutDot}`;
- const duration = `${util.formatDuration(cutFrom)}-${util.formatDuration(cutTo)}`;
+async function cut({
+ customOutDir, filePath, format, cutFrom, cutTo, videoDuration, rotation, onProgress,
+}) {
+ const ext = path.extname(filePath) || `.${format}`;
+ const cutSpecification = `${util.formatDuration(cutFrom)}-${util.formatDuration(cutTo)}`;
- const outPath = util.getOutPath(customOutDir, filePath, `${duration}${ext}`);
+ const outPath = util.getOutPath(customOutDir, filePath, `${cutSpecification}${ext}`);
console.log('Cutting from', cutFrom, 'to', cutTo);
// https://github.com/mifi/lossless-cut/issues/50
const cutFromArgs = cutFrom === 0 ? [] : ['-ss', cutFrom];
+ const cutToArgs = cutTo === videoDuration ? [] : ['-t', cutTo - cutFrom];
+
const rotationArgs = rotation !== undefined ? ['-metadata:s:v:0', `rotate=${rotation}`] : [];
const ffmpegArgs = [
'-i', filePath, '-y', '-vcodec', 'copy', '-acodec', 'copy', '-scodec', 'copy',
- ...cutFromArgs, '-t', cutTo - cutFrom,
+ ...cutFromArgs, ...cutToArgs,
'-map_metadata', '0',
...rotationArgs,
'-f', format,
diff --git a/src/renderer.jsx b/src/renderer.jsx
index 8407bab2..4b7db354 100644
--- a/src/renderer.jsx
+++ b/src/renderer.jsx
@@ -285,19 +285,22 @@ class App extends React.Component {
return alert('Start time must be before end time');
}
+ const videoDuration = this.state.duration;
+
this.setState({ working: true });
const outputDir = this.state.customOutDir;
const fileFormat = this.state.fileFormat;
try {
- return await ffmpeg.cut(
- outputDir,
- filePath,
- fileFormat,
- cutStartTime,
- cutEndTime,
- rotation,
- progress => this.onCutProgress(progress),
- );
+ return await ffmpeg.cut({
+ customOutDir: outputDir,
+ filePath,
+ format: fileFormat,
+ cutFrom: cutStartTime,
+ cutTo: cutEndTime,
+ videoDuration,
+ rotation,
+ onProgress: progress => this.onCutProgress(progress),
+ });
} catch (err) {
console.error('stdout:', err.stdout);
console.error('stderr:', err.stderr);