webRTC: How to tell Opus codec to use super wide band/full band
Asked Answered
B

1

6

I am working on a webRTC web application which works wonderfully so far. What I have not figured out yet is how to tell the Opus codec to (force) use "full band", for example.

Setting the codec up for 510 kHz bit rate is easy:

desc.sdp=desc.sdp.replace(/a=mid:audio\r\n/g,'a=mid:audio\r\nb=AS:510\r\n');

But is there a way to tell Opus which band to use?

Blackandwhite answered 9/9, 2015 at 7:12 Comment(0)
L
8

Specifying the band is not that bad. With opus, you just specify the MAX rate capabilities and let it run from there. By default OPUS goes to its max capabilities(48000, aka fullband).

Also, keep in mind that rtp clock rate must be 48000 no matter what capture rate you specify.

The below examples are taken from the rfc section-7.

m=audio 54312 RTP/AVP 101
a=rtpmap:101 opus/48000/2
a=fmtp:101 maxplaybackrate=16000; sprop-maxcapturerate=16000

That specifies a max capture and play back rate for the sender of 16kHz (aka Wideband).

Two-way full band stereo

m=audio 54312 RTP/AVP 101
a=rtpmap:101 opus/48000/2
a=fmtp:101 stereo=1; sprop-stereo=1

The options that you will be most concerned with if you want to specify the prefered band are:

  • maxplaybackrate: a hint about the maximum output sampling rate that the receiver is capable of rendering in Hz.
  • sprop-maxcapturerate: a hint about the maximum input sampling rate that the sender is likely to produce.

The different bands and their respected max:

  • NB: 8 kHz
  • MB: 12 kHz
  • WB: 16 kHz
  • SWB: 24 kHz
  • FB: 48 kHz //the codec default in webrtc

Also, note, there is a difference between Bitrate and Sample Rate. You modified the bitrate which may have forced Opus to change the sample rate but the options I have showed do not modify the bitrate at all and only change the sample rate.

Post Script, all this is contingent on the webrtc implementation and if it actually cares about what is specified in the SDP and if it actually effects the opus encoding/decoding. I have noticed(in the past, it very well may have changed) that the implementation in Firefox couldn't care less about what is in the SDP and just does what it wants by default.

Latia answered 9/9, 2015 at 13:34 Comment(5)
Thanks a lot. I hope those setting will get rid of the audio artifacts that I constantly hear (and the tempo(!) change in music). Do you know if there is a better/standard way to modify the sdp string instead of doing a find & replace of certain parts?Blackandwhite
@ArminHierstetter, I know that there are some lighter weight sdp parsers out there that could work but replacing the strings in the SDP before setting it locally and sending it are the only ways I know of doing this in the browser implementation of WebRTC technologiesLatia
@ArminHierstetter, you can also keep the bitrate from dropping or raising by making sure it is using a constant bitrate(can be set in the SDP as well, see the rfc mentioned).Latia
And what about opus 8000/1 in asterisk ? Is it possible narrow bandwidth in asterisk ?Rosebay
@Avanibadheka this question has nothing to do with asterisk, if you have an asterisk specific question...you should post a new questionLatia

© 2022 - 2024 — McMap. All rights reserved.