Skip to content

Commit

Permalink
Implement select img format
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Aug 14, 2017
1 parent f70c994 commit af74b70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/capture-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const util = require('./util');

bluebird.promisifyAll(fs);

function getFrameFromVideo(video) {
const format = 'jpeg';

function getFrameFromVideo(video, format) {
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
Expand All @@ -21,8 +19,8 @@ function getFrameFromVideo(video) {
return strongDataUri.decode(dataUri);
}

function captureFrame(customOutDir, filePath, video, currentTime) {
const buf = getFrameFromVideo(video);
function captureFrame(customOutDir, filePath, video, currentTime, captureFormat) {
const buf = getFrameFromVideo(video, captureFormat);

const ext = mime.extension(buf.mimetype);
const time = util.formatDuration(currentTime);
Expand Down
18 changes: 16 additions & 2 deletions src/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class App extends React.Component {
cutStartTime: 0,
cutEndTime: undefined,
fileFormat: undefined,
captureFormat: 'jpeg',
};

this.state = _.cloneDeep(defaultState);
Expand Down Expand Up @@ -180,6 +181,11 @@ class App extends React.Component {
return (this.state.filePath || '').replace(/#/g, '%23');
}

toggleCaptureFormat() {
const isPng = this.state.captureFormat === 'png';
this.setState({ captureFormat: isPng ? 'jpeg' : 'png' });
}

jumpCutStart() {
seekAbs(this.state.cutStartTime);
}
Expand Down Expand Up @@ -260,8 +266,10 @@ class App extends React.Component {
const filePath = this.state.filePath;
const outputDir = this.state.outputDir;
const currentTime = this.state.currentTime;
const captureFormat = this.state.captureFormat;
if (!filePath) return;
captureFrame(outputDir, filePath, getVideo(), currentTime).catch(err => alert(err));
captureFrame(outputDir, filePath, getVideo(), currentTime, captureFormat)
.catch(err => alert(err));
}

toggleHelp() {
Expand Down Expand Up @@ -367,7 +375,7 @@ class App extends React.Component {

<div className="right-menu">
<button
title={`Custom output dir (cancel to restore default). Current: ${this.state.outputDir || 'Not set'}`}
title={`Custom output dir (cancel to restore default). Current: ${this.state.outputDir || 'Not set (use input dir)'}`}
onClick={withBlur(() => this.setOutputDir())}
>
{this.state.outputDir ? `...${this.state.outputDir.substr(-10)}` : 'OUT PATH'}
Expand All @@ -384,6 +392,12 @@ class App extends React.Component {
aria-hidden="true"
onClick={() => this.capture()}
/>
<button
title="Capture frame format"
onClick={withBlur(() => this.toggleCaptureFormat())}
>
{this.state.captureFormat}
</button>
</div>

{renderHelpSheet(this.state.helpVisible)}
Expand Down

0 comments on commit af74b70

Please sign in to comment.