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

@arcsine/screen-recorder

v0.2.9

Published

Leverages FFMpeg to perform screen recordings

Downloads

32

Readme

@arcsine/screen-recorder

@arcsine/screen-recorder is a cross-platform library for recording desktop screens. The application relies upon FFmpeg as the base for recording. The primary functionality of the library is to start and stop recordings for a specific process (or active window). Additionally, the recorder supports audio recording, but has some limitations on macOS.

OSX requires a custom build of FFmpeg to bypass choppy audio. More information on the custom build can be found here.

The library works on macOS, Windows and X11-based Desktops (Linux, BSD). Wayland support is missing.

Prereqs

  • FFmpeg, 4.1+ with libx264 support.

Install

$ npm install @arcsine/screen-recorder

Usage

const { Recorder } = require('@arcsine/screen-recorder');

(async () => {
    const { finish, stop } = await Recorder.recordActiveWindow({
      file: './test.mp4',
      fps: 3,
      duration: 5
    });
    
    await finish;
})();

API

Recording

The recording api is for initiating and handling screen recordings.


class Recorder {
  static async recordActiveWindow(opts: RecordingOptions): Promise<RecordingResult>;
  static async recordWindowForProcess(pid: number, opts: RecordingOptions): Promise<RecordingResult>;
  static async recordWindow(opts: RecordingOptions): Promise<RecordingResult>;
}

interface RecordingOptions {
  // The location you want to store your output to
  file: string;
  // The framerate for recording, defaults to ffmpeg's default if not specified
  fps?: number;
  // Record audio?
  audio?: boolean;
  // How long to record for, default is until stop is called
  duration?: number;

  ffmpeg: {
    // Path to ffmpeg executable, if not specified, the library will attempt to find it on the path
    binary?: string;
    // Any specific transcoding flags  
    transcode?: any;
    // Any specific ffmpeg flags
    flags?: any;
  }
}

interface RecordingResult {
  // A promise that resolves when the recording finishes, the resolved options are returned and 
  //    are usable as inputs into the GIFCreator
  finish: Promise<RecordingOptions>;
  
  // The raw child process of the ffmpeg operation
  proc: ChildProcess;
  
  // A function to programmatically stop the recording
  //  The now parameter indicates a hard stop or a soft stop
  stop: (now?: boolean) => void;
}

Animated GIF Construction

The GIF generator handles files generated from screen recordings to produce animated gifs of the output


class GIFCreator  {
  static async generate(opts: GIFOptions): Promise<GIFResult>;
}

interface GIFOptions {
  // The file you want to convert to an animated gif
  file: string;
  // Output file defaults to the file name with a .gif extension
  output?: string;  
  // The framerate for recording, defaults to ffmpeg's default if not specified
  fps?: number;
  // The scale factor on the final gif
  scale?: number;

  ffmpeg?: {
    // Path to ffmpeg executable, if not specified, the library will attempt to find it on the path
    binary?: string;
  };
}

interface GIFResult {
  // A promise that resolves when the recording finishes, the final filename is returned
  finish: Promise<string>;
  
  // A function to programmatically stop the conversion
  //  The now parameter indicates a hard stop or a soft stop
  stop: (now?: boolean) => void;
}

DownloadUtil

Additionally, the library supports the ability to dynamically download an ffmpeg binary. This is meant to be used by library consumers to allow for prompting of downloads if the binary is not found.

class DownloadUtil {
  /**
   * Will download a component to the specified destination 
   */
  static async downloadComponent(opts: {
    // ffmpeg | ffplay | ffprobe
    component?: Component,
    // Where the executable should be stored
    destination: string,
    // The version you want installed, defaults to latest
    version?: string,
    // The os/arch you want to install, defaults to auto-detect
    platform?: Platform,
    // Listen on the download progress with percentage downloaded
    progress?: (pct: number) => void
  }):Promise<string>;
}

Example

Recording an active window, and converting to an animated gif

import { Recorder, GIFCreator } from './src';

(async function () {
  const { finish } = await Recorder.recordActiveWindow({
    file: './test.mp4',
    fps: 3,
    duration: 5
  });

  const finalOpts = await finish;

  const gifOpts = await GIFCreator.generate({
    ...finalOpts,
    scale: .25,
    output: 'funny.gif'
  });
  await gifOpts!.finish;
})();

Maintainers

License

MIT