@seydx/rtsp / RawAudioTranscoder
Class: RawAudioTranscoder
Defined in: sources/raw-audio-transcoder.ts:264
Normalizes raw framed elementary audio into a demuxable stream.
Some devices deliver audio as bare coded frames with no container at all — the canonical case is raw AAC-ELD, whose frames cannot be expressed in ADTS and therefore break every ADTS-based consumer. This class accepts those frames one push() at a time, decodes them (optionally with an explicit decoder such as libfdk_aac), re-encodes to a standards-compliant target (AAC-LC in ADTS by default), and exposes the result as a Readable that plugs directly into an AvSource or MultiSource input.
Example
import { buildAacEldConfig, MultiSource, RawAudioTranscoder } from '@seydx/rtsp';
// Raw AAC-ELD: 16 kHz mono, 480-sample frames, decodable only via libfdk.
const audio = new RawAudioTranscoder({
from: { codec: 'aac', decoder: 'libfdk_aac', sampleRate: 16000, channels: 1, samplesPerFrame: 480, config: buildAacEldConfig(16000, 1, 480) },
to: { bitRate: 32000 },
});
await audio.start();
audioFrameStream.on('data', (frame) => audio.push(frame));
const source = new MultiSource([
{ input: videoStream, format: 'h264' },
{ input: audio.stream, format: 'aac' },
]);See
- MultiSource For combining the normalized audio with other inputs
- buildAacEldConfig For the AAC-ELD codec configuration
Constructors
Constructor
new RawAudioTranscoder(
options):RawAudioTranscoder
Defined in: sources/raw-audio-transcoder.ts:288
Create a raw audio transcoder.
The transcoder is inert until RawAudioTranscoder.start is called; the constructor only captures configuration.
Parameters
options
Input format, target format, and tuning.
Returns
RawAudioTranscoder
Accessors
stream
Get Signature
get stream():
Readable
Defined in: sources/raw-audio-transcoder.ts:302
The transcoded output as a readable byte stream.
Emits the target container bytes (ADTS by default) as they are produced. Hand this to an AvSource/MultiSource input; it ends when the transcoder is closed.
Example
const inputs = [{ input: transcoder.stream, format: 'aac' }];Returns
Readable
Methods
close()
close():
Promise<void>
Defined in: sources/raw-audio-transcoder.ts:481
Stop the transcoder and release all pipeline resources.
Interrupts the blocked demuxer read so the background loop can unwind, waits for it, then closes every stage and ends the output stream. Safe to call when the transcoder was never started or is already closed.
Returns
Promise<void>
Resolves once all resources are released.
Example
await transcoder.close();push()
push(
frame):void
Defined in: sources/raw-audio-transcoder.ts:460
Feed one complete coded audio frame into the pipeline.
The buffer must contain exactly one frame in the configured input format; partial or concatenated frames are undecodable for raw elementary codecs. Calling push before RawAudioTranscoder.start (or after RawAudioTranscoder.close) is a silent no-op.
Parameters
frame
Buffer
One coded audio frame.
Returns
void
Example
audioSource.on('data', (frame) => transcoder.push(frame));start()
start():
Promise<void>
Defined in: sources/raw-audio-transcoder.ts:324
Start the transcode pipeline.
Resolves the decoder and encoder, announces the input format to the demuxer via a synthetic SDP (including the codec config when given), and wires up the decode, resample, encode, and mux stages. Calling start when already active is a no-op.
Returns
Promise<void>
Resolves once the pipeline is running.
Throws
If the input decoder or target encoder cannot be resolved, or the synthetic SDP contains no audio stream.
Example
await transcoder.start();