Skip to content

node-av / webrtc / RTPStream

Class: RTPStream

Defined in: src/api/rtp-stream.ts:146

Generic RTP streaming with automatic codec detection and transcoding.

Provides library-agnostic RTP streaming for various applications. Automatically detects input codecs and transcodes non-compatible formats. Supports hardware acceleration for video transcoding. Essential component for building RTP streaming servers.

Example

typescript
import { RTPStream } from 'node-av/api';

// Create stream with RTP packet callbacks
const stream = RTPStream.create('rtsp://camera.local/stream', {
  mtu: 1200,
  hardware: 'auto',
  onVideoPacket: (rtp) => {
    // Send RTP packet
    sendRtpPacket(rtp);
  },
  onAudioPacket: (rtp) => {
    sendRtpPacket(rtp);
  }
});

// Start streaming
await stream.start();

See

Accessors

isStreamActive

Get Signature

get isStreamActive(): boolean

Defined in: src/api/rtp-stream.ts:283

Check if the stream is active.

Returns

boolean

True if the stream is active, false otherwise

Methods

getInput()

getInput(): Demuxer | undefined

Defined in: src/api/rtp-stream.ts:305

Get the demuxer instance.

Used for accessing the underlying demuxer. Only available after start() is called.

Returns

Demuxer | undefined

Demuxer instance or undefined if not started

Example

typescript
const stream = RTPStream.create('input.mp4', {
  onVideoPacket: (rtp) => sendRtp(rtp)
});
await stream.start();
const input = stream.getInput();
console.log('Bitrate:', input?.bitRate);

start()

start(): Promise<void>

Defined in: src/api/rtp-stream.ts:336

Start streaming media to RTP packets.

Begins the media processing pipeline, reading packets from input, transcoding if necessary, and invoking RTP packet callbacks. Automatically handles video and audio streams in parallel. This method returns immediately after starting the pipeline.

Returns

Promise<void>

Promise that resolves when pipeline is started

Throws

If no video stream found in input

Throws

If setup fails

Example

typescript
const stream = RTPStream.create('rtsp://camera.local/stream', {
  onVideoPacket: (rtp) => sendRtp(rtp)
});

// Start streaming (returns immediately)
await stream.start();

// Later: stop streaming
await stream.stop();

stop()

stop(): Promise<void>

Defined in: src/api/rtp-stream.ts:676

Stop streaming gracefully and clean up all resources.

Stops the pipeline, closes output, and releases all FFmpeg resources. Safe to call multiple times. After stopping, you can call start() again to restart the stream.

Returns

Promise<void>

Example

typescript
const stream = RTPStream.create('input.mp4', {
  onVideoPacket: (rtp) => sendRtp(rtp)
});
await stream.start();

// Stop after 10 seconds
setTimeout(async () => await stream.stop(), 10000);

create()

static create(input, options?): RTPStream

Defined in: src/api/rtp-stream.ts:274

Create an RTP stream from a media source.

Configures the stream with input URL and options. The input is not opened until start() is called, allowing the stream to be reused after stop().

Parameters

input

string | Demuxer

Media source URL (RTSP, file path, HTTP, etc.) or a pre-opened Demuxer

options?

RTPStreamOptions = {}

Stream configuration options

Returns

RTPStream

Configured RTP stream instance

Examples

typescript
// Stream from RTSP camera
const stream = RTPStream.create('rtsp://camera.local/stream', {
  mtu: 1200,
  onVideoPacket: (rtp) => sendPacket(rtp),
  onAudioPacket: (rtp) => sendPacket(rtp)
});
typescript
// Stream file with auto hardware acceleration
const stream = RTPStream.create('video.mp4', {
  hardware: 'auto'
});
typescript
// Stream from a pre-opened Demuxer (e.g. Device.openScreen())
const demuxer = await Device.openScreen({ frameRate: 30 });
const stream = RTPStream.create(demuxer, {
  hardware: 'auto',
  onVideoPacket: (rtp) => sendPacket(rtp)
});