Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of allowed rates and frameSizes? (Segmentation faults otherwise) #73

Open
OnkelTem opened this issue Mar 28, 2021 · 0 comments
Open

Comments

@OnkelTem
Copy link

OnkelTem commented Mar 28, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant