Skip to content

fusefactory/electron-spout

 
 

Repository files navigation

electron-spout

A native Node.js addon for Electron that enables real-time video sharing via Spout2 on Windows. Send frames from your Electron application to any Spout-compatible receiver (OBS, Resolume, TouchDesigner, etc.).

Features

  • Send video frames to Spout receivers from Electron
  • Two output modes:
    • CPU mode: Send raw pixel buffers (BGRA format)
    • GPU mode: Send DirectX shared texture handles for zero-copy performance
  • Built with N-API for ABI stability across Node.js versions
  • Targets Electron 38.x

Platform Support

Windows only - Spout is a Windows-specific technology that relies on DirectX shared textures.

Prerequisites

  • Windows 10/11
  • Visual Studio 2019 or later with C++ build tools
  • vcpkg package manager
  • Node.js 18+
  • CMake 3.25+

Installation

1. Set up vcpkg

# Clone vcpkg if you haven't already
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat

# Set environment variable
set VCPKG_ROOT=C:\path\to\vcpkg

2. Install dependencies and build

pnpm install
pnpm run build

Or with npm:

npm install
npx cmake-js compile

Usage

import { SpoutOutput } from 'electron-spout';

// Create a Spout sender with a name
const spout = new SpoutOutput('My Electron App');

// Send a frame using raw pixel data (CPU mode)
const width = 1920;
const height = 1080;
const pixels = new Uint8Array(width * height * 4); // BGRA format

// Fill pixels with your frame data...

spout.updateFrame(pixels, { width, height });

// Or send using a shared texture handle (GPU mode - more efficient)
spout.updateTexture({
  widgetType: 'offscreen',
  pixelFormat: 'BGRA8',
  sharedTextureHandle: textureHandle
});

// Change the sender name
spout.name = 'New Sender Name';

With Electron Offscreen Rendering

import { BrowserWindow } from 'electron';
import { SpoutOutput } from 'electron-spout';

const win = new BrowserWindow({
  webPreferences: {
    offscreen: true
  }
});

const spout = new SpoutOutput('Electron Browser');

win.webContents.on('paint', (event, dirty, image) => {
  const size = image.getSize();
  const buffer = image.getBitmap();

  spout.updateFrame(new Uint8Array(buffer), {
    width: size.width,
    height: size.height
  });
});

win.webContents.setFrameRate(60);

API

SpoutOutput

Constructor

new SpoutOutput(name: string)

Creates a new Spout sender with the specified name. The name will be visible to Spout receivers.

Properties

  • name: string - Get or set the Spout sender name

Methods

updateFrame(buffer, size)

Sends a frame using raw pixel data.

  • buffer: Uint8Array - Pixel data in BGRA format
  • size: { width: number, height: number } - Frame dimensions
updateTexture(options)

Sends a frame using a DirectX shared texture handle (zero-copy).

  • options.widgetType: string - Widget type identifier
  • options.pixelFormat: string - Pixel format (e.g., 'BGRA8')
  • options.sharedTextureHandle: string - DirectX shared texture handle

Building from Source

# Debug build
npx cmake-js compile --debug

# Release build
npx cmake-js compile --release

# Rebuild
npx cmake-js rebuild

The compiled .node file will be in build/Release/ or build/Debug/.

Receiving Spout in Other Applications

Your Spout output can be received in:

  • OBS Studio - Use the Spout2 Plugin for OBS
  • Resolume Arena/Avenue - Native Spout support
  • TouchDesigner - Native Spout support
  • Unity - Spout4Unity
  • Any Spout-compatible application

Author

reito - Original author (2023)

License

MIT

Credits

  • Spout2 - The underlying video sharing framework
  • cmake-js - CMake-based build system for native Node.js addons

About

Share Electron's Offscreen to Spout

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 86.3%
  • CMake 10.7%
  • JavaScript 3.0%