1.0.2 • Published 4 years ago

electron-capturer v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

electron-capturer

Capture Electron's window and export as video

Requirements

Install

npm i electron-capturer

Use

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)

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
1.0.2

4 years ago

1.0.1

4 years ago