@vygr-labs/ndi-node
v1.0.0
Published
Node.js bindings for NDI (Network Device Interface) SDK
Maintainers
Readme
ndi-node
Node.js bindings for NDI (Network Device Interface) SDK.
NDI is a royalty-free software specification developed by NewTek that enables video-compatible products to communicate, deliver, and receive high-quality video over IP networks.
Features
- NDI Source Discovery - Find NDI sources on your network
- NDI Sender - Broadcast video and audio as an NDI source
- NDI Receiver - Receive video and audio from NDI sources
- PTZ Control - Control PTZ cameras over NDI
- Tally Support - Send and receive tally information
- Metadata - Exchange XML metadata with NDI sources
- TypeScript Support - Full TypeScript type definitions included
Prerequisites
NDI SDK
You need to download and install the NDI SDK from NewTek:
- Visit https://ndi.video/download-ndi-sdk/
- Download the NDI SDK for your platform
- Copy the SDK files to the
deps/ndidirectory:
deps/ndi/
├── include/
│ └── Processing.NDI.Lib.h
└── lib/
└── x64/ (Windows)
├── Processing.NDI.Lib.x64.lib
└── Processing.NDI.Lib.x64.dllBuild Tools
- Windows: Visual Studio Build Tools with C++ workload
- macOS: Xcode Command Line Tools
- Linux: GCC/G++ and build-essential
Installation
npm installThis will compile the native addon using node-gyp.
Quick Start
Finding NDI Sources
const ndi = require('ndi-node');
// Initialize NDI
ndi.initialize();
// Find sources (async convenience function)
const sources = await ndi.find(5000);
console.log('Found sources:', sources);
// Or use the Finder class for continuous discovery
const finder = new ndi.Finder();
finder.on('sources', (sources) => {
console.log('Sources updated:', sources);
});
finder.startPolling(1000);
// Cleanup
finder.destroy();
ndi.destroy();Sending Video
const ndi = require('ndi-node');
ndi.initialize();
const sender = new ndi.Sender({
name: 'My NDI Source',
clockVideo: true
});
// Send a frame
sender.sendVideo({
xres: 1920,
yres: 1080,
fourCC: ndi.FourCC.BGRA,
frameRateN: 30000,
frameRateD: 1001,
data: frameBuffer // Buffer containing BGRA pixel data
});
// Monitor tally
sender.on('tally', (tally) => {
console.log('On Program:', tally.onProgram);
console.log('On Preview:', tally.onPreview);
});
sender.startTallyPolling();
// Cleanup
sender.destroy();
ndi.destroy();Receiving Video
const ndi = require('ndi-node');
ndi.initialize();
const receiver = new ndi.Receiver({
source: { name: 'SOURCE_NAME (COMPUTER)' },
colorFormat: ndi.ColorFormat.BGRX_BGRA,
bandwidth: ndi.Bandwidth.HIGHEST
});
// Event-based capture
receiver.on('video', (frame) => {
console.log(`Video: ${frame.xres}x${frame.yres}`);
// frame.data contains the pixel buffer
});
receiver.on('audio', (frame) => {
console.log(`Audio: ${frame.noSamples} samples`);
});
receiver.startCapture();
// Cleanup
receiver.destroy();
ndi.destroy();API Reference
Core Functions
ndi.initialize(): boolean
Initialize the NDI library. Must be called before using any other functions.
ndi.destroy(): void
Cleanup the NDI library. Should be called when done using NDI.
ndi.version(): string | null
Get the NDI library version string.
ndi.find(timeout?, options?): Promise<Source[]>
Find NDI sources on the network.
Finder Class
new ndi.Finder(options?)Options:
showLocalSources: boolean- Include local sources (default: true)groups: string- Comma-separated list of groups to searchextraIps: string- Extra IPs to search for sources
Methods:
getSources(): Source[]- Get currently discovered sourceswaitForSources(timeout?): boolean- Wait for sources to changestartPolling(interval?)- Start polling for sourcesstopPolling()- Stop pollingdestroy()- Release resources
Events:
'sources'- Emitted when sources change
Sender Class
new ndi.Sender(options)Options:
name: string- Name of the NDI source (required)groups: string- Comma-separated list of groupsclockVideo: boolean- Clock video to frame rate (default: true)clockAudio: boolean- Clock audio to sample rate (default: true)
Methods:
sendVideo(frame)- Send a video framesendVideoAsync(frame)- Send a video frame asynchronouslysendAudio(frame)- Send an audio framesendMetadata(frame)- Send metadatagetTally(timeout?): Tally | null- Get tally statesetTally(tally)- Set tally stategetConnections(timeout?): number- Get number of connectionsgetSourceName(): string | null- Get full source namestartTallyPolling(interval?)- Start polling for tally changesstopTallyPolling()- Stop tally pollingdestroy()- Release resources
Events:
'tally'- Emitted when tally state changes
Receiver Class
new ndi.Receiver(options?)Options:
source: Source- Source to connect tocolorFormat: string- Color format (default: 'BGRX_BGRA')bandwidth: string- Bandwidth mode (default: 'highest')allowVideoFields: boolean- Allow video fields (default: true)name: string- Receiver name
Methods:
connect(source)- Connect to a sourcecapture(timeout?): CaptureResult- Capture any frame typecaptureVideo(timeout?): VideoFrame | null- Capture video onlycaptureAudio(timeout?): AudioFrame | null- Capture audio onlysetTally(tally): boolean- Set tally informationsendMetadata(frame)- Send metadata to sourcestartCapture(timeout?)- Start continuous capturestopCapture()- Stop continuous capturedestroy()- Release resources
PTZ Methods:
ptzIsSupported(): booleanptzZoom(zoom): booleanptzPanTilt(pan, tilt): booleanptzPanTiltSpeed(panSpeed, tiltSpeed): booleanptzStorePreset(presetNo): booleanptzRecallPreset(presetNo, speed?): booleanptzAutoFocus(): booleanptzFocus(focus): booleanptzWhiteBalanceAuto(): booleanptzExposureAuto(): boolean- And more...
Events:
'video'- Emitted when video frame is received'audio'- Emitted when audio frame is received'metadata'- Emitted when metadata is received'status_change'- Emitted when connection status changes'error'- Emitted on receive error
Constants
// Video pixel formats
ndi.FourCC.BGRA
ndi.FourCC.RGBA
ndi.FourCC.UYVY
ndi.FourCC.I420
ndi.FourCC.NV12
// ... and more
// Frame format types
ndi.FrameFormat.PROGRESSIVE
ndi.FrameFormat.INTERLEAVED
ndi.FrameFormat.FIELD_0
ndi.FrameFormat.FIELD_1
// Bandwidth modes
ndi.Bandwidth.HIGHEST
ndi.Bandwidth.LOWEST
ndi.Bandwidth.AUDIO_ONLY
ndi.Bandwidth.METADATA_ONLY
// Color formats
ndi.ColorFormat.BGRX_BGRA
ndi.ColorFormat.UYVY_BGRA
ndi.ColorFormat.RGBX_RGBA
ndi.ColorFormat.FASTEST
ndi.ColorFormat.BEST
// Frame types
ndi.FrameType.VIDEO
ndi.FrameType.AUDIO
ndi.FrameType.METADATA
ndi.FrameType.ERROR
ndi.FrameType.STATUS_CHANGEExamples
See the examples/ directory for complete examples:
finder.js- Discover NDI sourcessender.js- Send video test patternaudio-sender.js- Send audio (sine wave)receiver.js- Receive video/audioptz-control.js- Control PTZ cameras
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Credits
NDI® is a registered trademark of NewTek, Inc.
