Skip to content

Commit

Permalink
Implement custom output dir button
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Nov 25, 2016
1 parent 3d47759 commit 08d9976
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ function canExecuteFfmpeg(ffmpegPath) {
function getFfmpegPath() {
const internalFfmpeg = path.join(__dirname, '..', 'app.asar.unpacked', 'ffmpeg', getWithExt('ffmpeg'));
return canExecuteFfmpeg(internalFfmpeg)
.then(() => internalFfmpeg)
.catch(() => {
console.log('Internal ffmpeg unavail');
return which('ffmpeg');
});
.then(() => internalFfmpeg)
.catch(() => {
console.log('Internal ffmpeg unavail');
return which('ffmpeg');
});
}

function cut(filePath, format, cutFrom, cutTo) {
function cut(outputDir, filePath, format, cutFrom, cutTo) {
return bluebird.try(() => {
const ext = path.extname(filePath) || `.${format}`;
const outFileAppend = `${util.formatDuration(cutFrom)}-${util.formatDuration(cutTo)}`;
const outFile = `${filePath}-${outFileAppend}${ext}`;
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}`;

console.log('Cutting from', cutFrom, 'to', cutTo);

Expand Down
25 changes: 21 additions & 4 deletions src/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const keyboardJs = require('keyboardjs');
const _ = require('lodash');
const captureFrame = require('capture-frame');
const fs = require('fs');
const path = require('path');
const Hammer = require('react-hammerjs');

const React = require('react');
Expand All @@ -13,6 +14,8 @@ const classnames = require('classnames');
const ffmpeg = require('./ffmpeg');
const util = require('./util');

const dialog = electron.remote.dialog;

function getVideo() {
return $('#player video')[0];
}
Expand Down Expand Up @@ -131,6 +134,12 @@ class App extends React.Component {
this.setState({ cutEndTime: this.state.currentTime });
}

setOutputDir() {
dialog.showOpenDialog({ properties: ['openDirectory'] }, (paths) => {
this.setState({ outputDir: (paths && paths.length === 1) ? paths[0] : undefined });
});
}

jumpCutStart() {
seekAbs(this.state.cutStartTime);
}
Expand Down Expand Up @@ -191,7 +200,9 @@ class App extends React.Component {
}

this.setState({ working: true });
return ffmpeg.cut(filePath, this.state.fileFormat, cutStartTime, cutEndTime)
const outputDir = this.state.outputDir;
const fileFormat = this.state.fileFormat;
return ffmpeg.cut(outputDir, filePath, fileFormat, cutStartTime, cutEndTime)
.catch((err) => {
console.error('stdout:', err.stdout);
console.error('stderr:', err.stderr);
Expand Down Expand Up @@ -283,7 +294,7 @@ class App extends React.Component {
</div>
<div>
<button
className="jump-cut-start" title="Cut start time"
className="jump-cut-start" title="Cut start time (jump)"
onClick={() => this.jumpCutStart()}
>{util.formatDuration(this.state.cutStartTime || 0)}</button>
<i
Expand All @@ -305,15 +316,21 @@ class App extends React.Component {
onClick={() => this.setCutEnd()}
/>
<button
className="jump-cut-end" title="Cut end time"
className="jump-cut-end" title="Cut end time (jump)"
onClick={() => this.jumpCutEnd()}
>{util.formatDuration(this.state.cutEndTime || 0)}</button>
</div>
</div>

<div className="right-menu">
<button
title={`Custom output dir (cancel to restore default). Current: ${this.state.outputDir || 'Not set'}`}
onClick={() => this.setOutputDir()}
>
{this.state.outputDir ? `...${this.state.outputDir.substr(-10)}` : 'OUT PATH'}
</button>
<button title="Format">
{this.state.fileFormat || '-'}
{this.state.fileFormat || 'FMT'}
</button>
<button className="playback-rate" title="Playback rate">
{_.round(this.state.playbackRate, 1) || 1}x
Expand Down

0 comments on commit 08d9976

Please sign in to comment.