@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 {
file: string;
fps?: number;
audio?: boolean;
duration?: number;
ffmpeg: {
binary?: string;
transcode?: any;
flags?: any;
}
}
interface RecordingResult {
finish: Promise<RecordingOptions>;
proc: ChildProcess;
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 {
file: string;
output?: string;
fps?: number;
scale?: number;
ffmpeg?: {
binary?: string;
};
}
interface GIFResult {
finish: Promise<string>;
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 {
static async downloadComponent(opts: {
component?: Component,
destination: string,
version?: string,
platform?: Platform,
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