npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@microbium/electron-recorder

v3.3.0

Published

Record video with `electron` and `ffmpeg`

Downloads

12

Readme

electron-recorder

A streaming video recorder using electron and ffmpeg.

Example

Here is a simple page showing how to use electron-recorder to create a movie:

<html>
  <body>
    <h1>Test Movie</h1>
    <script>
      const electron = require('electron')
      const createVideoRecorder = require('electron-recorder')

      // First we grab a reference to the current window object
      const win = electron.remote.getCurrentWindow()

      // The size of the animation is the same as the size of the window
      win.setSize(200, 200)

      // Here we create recorder object
      const video = createVideoRecorder(win, {
        fps: 60,
        output: 'test.mp4'
      })

      let frameCount = 360
      function renderFrame () {
        // Here is where we render the movie (we just make the text rotate)
        Object.assign(document.querySelector('h1').style, {
          'width': 100,
          'margin-left': 50,
          'margin-top': 50,
          '-webkit-transform': 'rotate(' + frameCount + 'deg)'
        })

        // If we still have frames left, then take a snapshot and schedule
        // another frame
        if (--frameCount > 0) {
          video.frame(renderFrame)
        } else {
          // Otherwise, movie is over and we save the snapshot to file
          video.end()
          win.close()
        }
      }

      renderFrame()
    </script>
  </body>
</html>

Suppose that this was saved to a file called index.html. Then we could run this using electron with the following command:

electron index.html

And once it is done, we should get the following:

Result

Install

While electron-recorder does not have any JavaScript dependencies, it does have system requirements that you need to configure.

First, you need to install electron. Instructions for this can be found on the electron web page, or you can install via npm using the electron-prebuild package:

npm i electron-prebuild

Then you need to install ffmpeg on your system and put it on your path. Instructions can be found on the ffmpeg homepage, or if you are on a debian Linux system you can use apt:

apt-get install ffmpeg

Finally, after all that is done you can install the module:

npm i electron-recorder

And that's it!

API

var recorder = require('electron-recorder')(window[, options])

This creates a new recorder instance. It takes two arguments:

  • window which is a reference to the window object in which we are recording
  • options which is a dictionary of optional configuration parameters.
    • ffmpeg a string representing the path to the ffmpeg executable (default ffmpeg)
    • fps the frame rate of the video (default 60)
    • output the name of the file to write the output to. If not specified, then output is streamed (note that some movie formats like AVI and MP4 do not support streaming output)
    • format The type of the output format (default matroska)

Returns A new video recorder instance

recorder.frame([next(err)])

Takes a snapshot of the current browser window and appends it to the movie.

  • next(err) is a callback which is executed once the frame is successfully recorded.

recorder.end()

Ends the video recording and saves the results

recorder.log

A streaming text log of the output of ffmpeg as it is encoding.

recorder.stream

If no output was specified, then the .stream property of the recorder is a readable stream object containing the encoded movie.

FAQ

Can this be run headless?

Sort of. On linux, you can use xvfb to redirect the display to an offscreen buffer. You can also try using electron-spawn. Better options right now are limited because electron does not yet support headless rendering natively, but this may change in the future.

Why use this instead of ccapture.js?

electron-recorder records your whole display and is streaming. It is geared to recording longer animations and requires specially instrumenting your code. ccapture.js runs in your browser and has no dependencies, but also shims a bunch of functions to emulate timing and globs all your frames at once in your tab's memory which can cause slow downs or crashes on very long movies. Also it only supports export to a limited number of formats, while electron-recorder can export to anything ffmpeg supports.

What happens if I touch my window during the animation?

Stuff will probably break. Don't do that!

License

(c) 2016 Mikola Lysenko. MIT License