prism-media
prism-media copied to clipboard
List of allowed rates and frameSizes? (Segmentation faults otherwise)
I wonder what is the allowed combinations of rate
and frameSize
options for prism.opus.Encoder
?
From my experiments just a limited list is actually allowed, step left or right - and it's crashing with segmentation fault error.
Here is a code for example which crashes:
import prism from 'prism-media';
import fs from 'fs';
import { PassThrough } from 'stream';
const samplingRate = 32000; // (1)
const frameSize = 60; // (2)
const stream = fs.createReadStream('01.wav');
const transcoderStream = new prism.FFmpeg({
args: ['-i', '-', '-f', 's16le', '-filter:a', `aresample=${samplingRate}`, '-channel_layout', 'mono'],
});
const encoderOptions = {
rate: samplingRate,
channels: 1,
frameSize: Math.round((frameSize / 1000) * samplingRate),
};
console.log(encoderOptions, 'Encoder options');
const encodeStream = new prism.opus.Encoder(encoderOptions);
stream.pipe(transcoderStream).pipe(encodeStream).pipe(new PassThrough());
If you change lines (1) and (2) to:
const samplingRate = 48000; // (1)
const frameSize = 20; // (2)
or
const samplingRate = 16000; // (1)
const frameSize = 60; // (2)
it won't crash.
I would like to have a helper function for generating appropriate inputs for prism.opus.Encoder
.