Don't set cutEndTime when duration arrives

Instead make cutEndTime === undefined mean that there is no cut end
The problem was that duration can change later
...when starting to playback
pull/83/head
Mikael Finstad 8 years ago
parent c6a75600cf
commit c13e54f5a3

@ -56,19 +56,21 @@ function handleProgress(process, cutDuration, onProgress) {
} }
async function cut({ async function cut({
customOutDir, filePath, format, cutFrom, cutTo, videoDuration, rotation, includeAllStreams, customOutDir, filePath, format, cutFrom, cutTo, cutToApparent, videoDuration, rotation,
onProgress, stripAudio, includeAllStreams, onProgress, stripAudio,
}) { }) {
const ext = path.extname(filePath) || `.${format}`; const ext = path.extname(filePath) || `.${format}`;
const cutSpecification = `${util.formatDuration(cutFrom, true)}-${util.formatDuration(cutTo, true)}`; const cutSpecification = `${util.formatDuration(cutFrom, true)}-${util.formatDuration(cutToApparent, true)}`;
const outPath = util.getOutPath(customOutDir, filePath, `${cutSpecification}${ext}`); const outPath = util.getOutPath(customOutDir, filePath, `${cutSpecification}${ext}`);
console.log('Cutting from', cutFrom, 'to', cutTo); console.log('Cutting from', cutFrom, 'to', cutToApparent);
const cutDuration = cutToApparent - cutFrom;
// https://github.com/mifi/lossless-cut/issues/50 // https://github.com/mifi/lossless-cut/issues/50
const cutFromArgs = cutFrom === 0 ? [] : ['-ss', cutFrom]; const cutFromArgs = cutFrom === 0 ? [] : ['-ss', cutFrom];
const cutToArgs = cutTo === videoDuration ? [] : ['-t', cutTo - cutFrom]; const cutToArgs = cutTo === undefined || cutTo === videoDuration ? [] : ['-t', cutDuration];
const rotationArgs = rotation !== undefined ? ['-metadata:s:v:0', `rotate=${rotation}`] : []; const rotationArgs = rotation !== undefined ? ['-metadata:s:v:0', `rotate=${rotation}`] : [];
const ffmpegArgs = [ const ffmpegArgs = [
@ -90,7 +92,7 @@ async function cut({
const ffmpegPath = await getFfmpegPath(); const ffmpegPath = await getFfmpegPath();
const process = execa(ffmpegPath, ffmpegArgs); const process = execa(ffmpegPath, ffmpegArgs);
handleProgress(process, cutTo - cutFrom, onProgress); handleProgress(process, cutDuration, onProgress);
const result = await process; const result = await process;
console.log(result.stdout); console.log(result.stdout);

@ -193,7 +193,6 @@ class App extends React.Component {
onDurationChange(duration) { onDurationChange(duration) {
this.setState({ duration }); this.setState({ duration });
if (!this.state.cutEndTime) this.setState({ cutEndTime: duration });
} }
onCutProgress(cutProgress) { onCutProgress(cutProgress) {
@ -232,17 +231,19 @@ class App extends React.Component {
return `${this.getRotation()}°`; return `${this.getRotation()}°`;
} }
getApparentCutEndTime() {
if (this.state.cutEndTime !== undefined) return this.state.cutEndTime;
if (this.state.duration !== undefined) return this.state.duration;
return 0; // Haven't gotten duration yet
}
isRotationSet() { isRotationSet() {
// 360 means we don't modify rotation // 360 means we don't modify rotation
return this.state.rotation !== 360; return this.state.rotation !== 360;
} }
areCutTimesSet() {
return (this.state.cutStartTime !== undefined || this.state.cutEndTime !== undefined);
}
isCutRangeValid() { isCutRangeValid() {
return this.areCutTimesSet() && this.state.cutStartTime < this.state.cutEndTime; return this.state.cutStartTime < this.getApparentCutEndTime();
} }
increaseRotation() { increaseRotation() {
@ -264,7 +265,7 @@ class App extends React.Component {
} }
jumpCutEnd() { jumpCutEnd() {
seekAbs(this.state.cutEndTime); seekAbs(this.getApparentCutEndTime());
} }
handlePan(e) { handlePan(e) {
@ -318,9 +319,6 @@ class App extends React.Component {
const includeAllStreams = this.state.includeAllStreams; const includeAllStreams = this.state.includeAllStreams;
const stripAudio = this.state.stripAudio; const stripAudio = this.state.stripAudio;
if (!this.areCutTimesSet()) {
return alert('Please select both start and end time');
}
if (!this.isCutRangeValid()) { if (!this.isCutRangeValid()) {
return alert('Start time must be before end time'); return alert('Start time must be before end time');
} }
@ -333,6 +331,7 @@ class App extends React.Component {
format: fileFormat, format: fileFormat,
cutFrom: cutStartTime, cutFrom: cutStartTime,
cutTo: cutEndTime, cutTo: cutEndTime,
cutToApparent: this.getApparentCutEndTime(),
videoDuration, videoDuration,
rotation, rotation,
includeAllStreams, includeAllStreams,
@ -367,7 +366,6 @@ class App extends React.Component {
} }
renderCutTimeInput(type) { renderCutTimeInput(type) {
const cutTimeKey = type === 'start' ? 'cutStartTime' : 'cutEndTime';
const cutTimeManualKey = type === 'start' ? 'cutStartTimeManual' : 'cutEndTimeManual'; const cutTimeManualKey = type === 'start' ? 'cutStartTimeManual' : 'cutEndTimeManual';
const cutTimeInputStyle = { width: '8em', textAlign: type === 'start' ? 'right' : 'left' }; const cutTimeInputStyle = { width: '8em', textAlign: type === 'start' ? 'right' : 'left' };
@ -386,7 +384,7 @@ class App extends React.Component {
return; return;
} }
this.setState({ [cutTimeManualKey]: undefined, [cutTimeKey]: time }); this.setState({ [cutTimeManualKey]: undefined, [type === 'start' ? 'cutStartTime' : 'cutEndTime']: time });
}; };
@ -396,7 +394,7 @@ class App extends React.Component {
onChange={e => handleCutTimeInput(e.target.value)} onChange={e => handleCutTimeInput(e.target.value)}
value={isCutTimeManualSet() value={isCutTimeManualSet()
? this.state[cutTimeManualKey] ? this.state[cutTimeManualKey]
: util.formatDuration(this.state[cutTimeKey]) : util.formatDuration(type === 'start' ? this.state.cutStartTime : this.getApparentCutEndTime())
} }
/>); />);
} }
@ -445,7 +443,7 @@ class App extends React.Component {
className="cut-start-time" className="cut-start-time"
style={{ style={{
left: `${((this.state.cutStartTime) / (this.state.duration || 1)) * 100}%`, left: `${((this.state.cutStartTime) / (this.state.duration || 1)) * 100}%`,
width: `${(((this.state.cutEndTime) - this.state.cutStartTime) / (this.state.duration || 1)) * 100}%`, width: `${(((this.getApparentCutEndTime()) - this.state.cutStartTime) / (this.state.duration || 1)) * 100}%`,
}} }}
/> />
} }

Loading…
Cancel
Save