mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-22 02:12:30 +01:00
Bugfixes
Fix issue with two dots in extension Also don't cut end if endpoint is the end of the video
This commit is contained in:
parent
305fae7a94
commit
4493aa5572
@ -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,
|
||||
|
@ -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,
|
||||
return await ffmpeg.cut({
|
||||
customOutDir: outputDir,
|
||||
filePath,
|
||||
fileFormat,
|
||||
cutStartTime,
|
||||
cutEndTime,
|
||||
format: fileFormat,
|
||||
cutFrom: cutStartTime,
|
||||
cutTo: cutEndTime,
|
||||
videoDuration,
|
||||
rotation,
|
||||
progress => this.onCutProgress(progress),
|
||||
);
|
||||
onProgress: progress => this.onCutProgress(progress),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('stdout:', err.stdout);
|
||||
console.error('stderr:', err.stderr);
|
||||
|
Loading…
Reference in New Issue
Block a user