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

how to configure opus encoder? #80

Open
vinnitu opened this issue Oct 29, 2021 · 1 comment
Open

how to configure opus encoder? #80

vinnitu opened this issue Oct 29, 2021 · 1 comment

Comments

@vinnitu
Copy link

vinnitu commented Oct 29, 2021

const beamcoder = require('beamcoder');

async function run() {
  let encoder = beamcoder.encoder({
    name: 'opus',
  });

  let demuxer = await beamcoder.demuxer('./f.mp3');
  let decoder = await beamcoder.decoder({ demuxer: demuxer, stream_index: 0 });

  for ( let x = 0 ; x < 100 ; x++ ) {
    let packet = await demuxer.read();
    let frames = await decoder.decode(packet);
    for (let frame in frames) {
        const p = encoder.encode(frame);
        console.log(p);
    }
  }
}

run();
Promise {
  <rejected> Error: In file ../src/encode.cc on line 330, found error: All passed values as arguments must be of type frame.
      at run (/home/user/project/index.js:26:27) {
    code: '5001'
  }
}
@Bahlinc-Dev
Copy link

First of all, the decoded frames are located in in "frames" sub property, and not the root object, so you would need to change your encode line to: const p = encoder.encode(frame.frames). Also you need to specify additional opus specific encoding parameters on the encoder like this: (example)

let encoder = beamcoder.encoder({ name: 'libopus', bit_rate: 128000, time_base: [1, 48000], sample_rate: 48000, channels: 1, channel_layout: 'mono', interleaved: false, sample_fmt: 'flt', });

Additionally, if the source "sample_fmt" is not in either s16 or flt bit format (the only possible for opus) you will need a filter in between the decode and encode steps to convert the source format to the destination format defined in the decoder, it's not automatic.

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

2 participants