Skip to content

@seydx/rtsp / FfmpegSink

Class: FfmpegSink ​

Defined in: sinks/ffmpeg.ts:90

Sink that remuxes the relayed stream into another container.

Pipes the relay's packets into a node-av muxer entirely in-process, with no child process involved. Streams are copied rather than re-encoded, so the operation stays cheap and lossless. Point it at a file, a streaming URL, or a writable stream to record or republish the upstream media.

Examples ​

typescript
import { Relay, FfmpegSink } from '@seydx/rtsp';

const sink = new FfmpegSink({ output: 'out.mp4' });
relay.pipe(sink);
typescript
import { FfmpegSink } from '@seydx/rtsp';

const sink = new FfmpegSink({
  output: 'rtmp://localhost/live/stream',
  format: 'flv',
  options: { flvflags: 'no_duration_filesize' },
});

See ​

  • Relay For wiring sinks to a source
  • Sink For the sink contract this implements

Implements ​

Constructors ​

Constructor ​

new FfmpegSink(options): FfmpegSink

Defined in: sinks/ffmpeg.ts:105

Create a new ffmpeg sink.

Parameters ​

options ​

FfmpegSinkOptions

Output destination and muxer configuration

Returns ​

FfmpegSink

Example ​

typescript
const sink = new FfmpegSink({ output: 'out.mp4', format: 'mp4' });

Methods ​

close() ​

close(): Promise<void>

Defined in: sinks/ffmpeg.ts:175

Finalize and release the muxer.

Flushes any buffered output, writes the container trailer, and frees the stream mapping. Safe to call when the sink was never initialized. Errors raised while closing are reported through the configured logger rather than thrown, so teardown of other sinks is not interrupted.

Returns ​

Promise<void>

Resolves once the muxer has been closed

Example ​

typescript
await sink.close();

Implementation of ​

Sink.close


init() ​

init(info): Promise<void>

Defined in: sinks/ffmpeg.ts:125

Initialize the muxer and map the source tracks onto it.

Opens the output destination, then registers each AV-backed track as a muxer stream so packets can later be routed to the correct output index. Tracks without a native handle are skipped, since they cannot be copied.

Parameters ​

info ​

StreamInfo

Resolved description of the upstream tracks

Returns ​

Promise<void>

Resolves once the muxer is open and all streams are mapped

Throws ​

If the output cannot be opened by node-av

Example ​

typescript
await sink.init(streamInfo);

Implementation of ​

Sink.init


write() ​

write(packet): Promise<void>

Defined in: sinks/ffmpeg.ts:154

Write a single packet to the muxer.

Routes the packet to its mapped output stream by index. Packets for unmapped tracks, or packets without an underlying AV payload, are dropped silently.

Parameters ​

packet ​

MediaPacket

The media packet to remux

Returns ​

Promise<void>

Resolves once the packet has been handed to the muxer

Example ​

typescript
await sink.write(packet);

Implementation of ​

Sink.write