NodeAV supports multiple input methods via the Demuxer API:
- Files or Network: Pass a file path or a network URL (e.g.,
rtsp://...). - Buffers: Pass a Node.js
Buffer directly to Demuxer.open(). - Custom I/O Callbacks: Implement
IOInputCallbacks to provide custom read and seek logic. - Raw Media: Open raw video (e.g., YUV) or raw audio (e.g., PCM) by specifying the type, dimensions, pixel format, or sample rate.
// From Files or Network
const media = await Demuxer.open('input.mp4');
// or
const media = await Demuxer.open('rtsp://example.com/stream');
// From Buffers
import { readFile } from 'fs/promises';
const buffer = await readFile('input.mp4');
const media = await Demuxer.open(buffer);
// Custom I/O Callbacks
import type { IOInputCallbacks, IOOutputCallbacks } from 'node-av/api';
const inputCallbacks: IOInputCallbacks = {
read: (size: number) => {
return buffer; // or null for EOF
},
seek: (offset: bigint, whence: number) => {
return newPosition;
}
};
await using input = await Demuxer.open(inputCallbacks, { format: 'mp4' });
// Raw video input
const rawVideo = await Demuxer.open({
type: 'video',
input: 'input.yuv',
width: 1280,
height: 720,
pixelFormat: AV_PIX_FMT_YUV420P,
frameRate: { num: 30, den: 1 }
});
// Raw audio input
const rawAudio = await Demuxer.open({
type: 'audio',
input: 'input.pcm',
sampleRate: 48000,
channels: 2,
sampleFormat: AV_SAMPLE_FMT_S16
}, { format: 's16le' });