Class: RTPStream
Defined in: src/api/rtp-stream.ts:196
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
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
- Demuxer For input media handling
- HardwareContext For GPU acceleration
Accessors
isStreamActive
Get Signature
get isStreamActive():
boolean
Defined in: src/api/rtp-stream.ts:344
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:366
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
const stream = RTPStream.create('input.mp4', {
onVideoPacket: (rtp) => sendRtp(rtp)
});
await stream.start();
const input = stream.getInput();
console.log('Bitrate:', input?.bitRate);requestVideoKeyframe()
requestVideoKeyframe():
void
Defined in: src/api/rtp-stream.ts:386
Request that the next encoded video frame is a keyframe.
Used to answer receiver feedback (e.g. a WebRTC PLI) so a receiver that missed the stream start or lost packets can resync without waiting for the next scheduled GOP keyframe. Currently effective for frame-source inputs (MediaFrameSource); for demuxer inputs the encoder's regular GOP cadence applies.
Returns
void
Example
transceiver.sender.onPictureLossIndication.subscribe(() => {
stream.requestVideoKeyframe();
});start()
start():
Promise<void>
Defined in: src/api/rtp-stream.ts:440
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
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:1064
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
const stream = RTPStream.create('input.mp4', {
onVideoPacket: (rtp) => sendRtp(rtp)
});
await stream.start();
// Stop after 10 seconds
setTimeout(async () => await stream.stop(), 10000);create()
staticcreate(input,options?):RTPStream
Defined in: src/api/rtp-stream.ts:335
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 | MediaFrameSource
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
// Stream from RTSP camera
const stream = RTPStream.create('rtsp://camera.local/stream', {
mtu: 1200,
onVideoPacket: (rtp) => sendPacket(rtp),
onAudioPacket: (rtp) => sendPacket(rtp)
});// Stream file with auto hardware acceleration
const stream = RTPStream.create('video.mp4', {
hardware: 'auto'
});// 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)
});