From 4493aa5572bd169225fef6c7d22b9a233cb77f10 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sun, 18 Feb 2018 13:59:42 +0100 Subject: [PATCH] Bugfixes Fix issue with two dots in extension Also don't cut end if endpoint is the end of the video --- src/ffmpeg.js | 15 +++++++++------ src/renderer.jsx | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) 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);