1.0.2 • Published 4 years ago
electron-capturer v1.0.2
electron-capturer
Capture Electron's window and export as video
Requirements
ffmpegif you have FFmpeg installed, make sure to set the
FFMPEG_PATHenvironment variable;Or, install @ffmpeg-installer/ffmpeg
electron
Install
npm i electron-capturerUse
const fs = require("fs");
const { capture } = require("electron-capturer");
const { app, BrowserWindow } = require("electron");
app.whenReady().then(() => {
app.on("activate", () => {
const win = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
capture(win, { savePath: 'capture.mp4', fps: 25 }).then(handle => {
handle.stop().then(() => {
const buffer = fs.readFileSync('capture.mp4');
win.close();
win.destroy();
});
})
});
});API
capture(win, options)
win<BrowserWindow>: window to be capturedoptions<Object>- returns: <Promise<VideoCapture>>
class:VideoCapture
Core class of capture, created when call capture(win), and return an instance;
VideoCapture.stop()
Manually stop capturing.
This method will automatically be called when BrowserWindow is closed or destroyed
const capture = await capture(win, "capture.mp4");
await new Promise(r => setTimeout(r, 5000));
await capture.stop();Demo
There's an Electron example in project, Clone the project and run:
yarn dev