1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 02:12:30 +01:00

Fix capture frame

https://github.com/mifi/lossless-cut/issues/25
This commit is contained in:
Mikael Finstad 2017-02-11 13:27:03 +01:00
parent 87c7db35c9
commit aee96f300b
3 changed files with 34 additions and 8 deletions

View File

@ -42,7 +42,6 @@
}, },
"dependencies": { "dependencies": {
"bluebird": "^3.4.6", "bluebird": "^3.4.6",
"capture-frame": "^1.0.0",
"classnames": "^2.2.5", "classnames": "^2.2.5",
"electron": "^1.4.5", "electron": "^1.4.5",
"electron-default-menu": "^1.0.0", "electron-default-menu": "^1.0.0",
@ -52,10 +51,12 @@
"jquery": "^3.1.1", "jquery": "^3.1.1",
"keyboardjs": "^2.3.3", "keyboardjs": "^2.3.3",
"lodash": "^4.16.4", "lodash": "^4.16.4",
"mime-types": "^2.1.14",
"react": "^15.3.2", "react": "^15.3.2",
"react-dom": "^15.3.2", "react-dom": "^15.3.2",
"react-hammerjs": "^0.5.0", "react-hammerjs": "^0.5.0",
"read-chunk": "^2.0.0", "read-chunk": "^2.0.0",
"strong-data-uri": "^1.0.4",
"which": "^1.2.11" "which": "^1.2.11"
} }
} }

29
src/capture-frame.js Normal file
View File

@ -0,0 +1,29 @@
const bluebird = require('bluebird');
const fs = require('fs');
const mime = require('mime-types');
const strongDataUri = require('strong-data-uri');
bluebird.promisifyAll(fs);
function getFrameFromVideo(video) {
const format = 'jpeg';
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0);
const dataUri = canvas.toDataURL(`image/${format}`);
return strongDataUri.decode(dataUri);
}
function captureFrame(video, outPathWithoutExt) {
const buf = getFrameFromVideo(video);
const ext = mime.extension(buf.mimetype);
const outPath = `${outPathWithoutExt}.${ext}`;
return fs.writeFileAsync(outPath, buf);
}
module.exports = captureFrame;

View File

@ -2,14 +2,13 @@ const electron = require('electron'); // eslint-disable-line
const $ = require('jquery'); const $ = require('jquery');
const keyboardJs = require('keyboardjs'); const keyboardJs = require('keyboardjs');
const _ = require('lodash'); const _ = require('lodash');
const captureFrame = require('capture-frame');
const fs = require('fs');
const Hammer = require('react-hammerjs'); const Hammer = require('react-hammerjs');
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const classnames = require('classnames'); const classnames = require('classnames');
const captureFrame = require('./capture-frame');
const ffmpeg = require('./ffmpeg'); const ffmpeg = require('./ffmpeg');
const util = require('./util'); const util = require('./util');
@ -245,11 +244,8 @@ class App extends React.Component {
capture() { capture() {
if (!this.state.filePath) return; if (!this.state.filePath) return;
const buf = captureFrame(getVideo(), 'jpg'); const outPathWithoutExt = `${this.state.filePath}-${util.formatDuration(this.state.currentTime)}`;
const outPath = `${this.state.filePath}-${util.formatDuration(this.state.currentTime)}.jpg`; captureFrame(getVideo(), outPathWithoutExt).catch(err => alert(err));
fs.writeFile(outPath, buf, (err) => {
if (err) alert(err);
});
} }
toggleHelp() { toggleHelp() {