Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Opus output files - always stereo at 48kHz? (Read 13348 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Opus output files - always stereo at 48kHz?

Hello there,

I'm doing some tests with the Opus codec to use it in applications where we are not looking for pristine sound quality, but small file sizes. Usually we have found that a sampling rate of 11kHz, downmixed to mono and a quality setting of -2 or -1 in the vorbis codec is the most used configuration. This gives around 12kbps.

So, with that parameters, I'm trying to see if Opus sounds better than vorbis but I have found difficult to create an "equivalent" file, at least with the metrics I use, so I have the following questions:
  - For what I have been able to find, it appears that even if in the documentation and so on it says that it supports sample rates of 8-48KHz, the resulting file is always 48Khz, correct? (if not, how can I change this?) Or is it that in the codec it internally uses/resamples the file at what samping rate is best for the specified kbps, but the decoding always shows 48khz?
  - As the parameter of the quality is specified in kbps then I guess that to save space in the resulting file I should pass a lower bitrate for a mono audio than for a stereo, or, if I specify the same bitrate, then the quality of the mono audio should be better?

I hope this makes somewhat sense. I'm really impressed with the performance of the codec, and I'm just trying to understand how it works and how should I use it.

Thanks a lot for your help,

Rodrigo Gómez

Opus output files - always stereo at 48kHz?

Reply #1
Ok... I read the Official Opus Codec  RFC and I think I found some answers:
  - Sampling rate: depending on the specified bitrate, the codec will use the sampling rate that fits best. The resulting file will have whichever sample rate the encoder used, but the decoding can be at any supported sample rate (so if it says 48khz in VLC, for instance, is because the decoder there always uses 48khz, correct?)
  - Channels: in the definition it says that the encoder chooses the number of channel according to the bitrate specified, but this parameter can be modified and appears to be used in the opusenc, I mean: if I specify the --downmix-mono option then the resulting file says that it has 1 channel, but the bitrate specified is used in any case, so in theory (and that's an example they mention on the definition) a downmixed-mono audio at a specific bitrate should have better quality than the same audio at the same bitrate, but with the 2 channels.

Are this answers correct, or I'm mistaken in my understanding of the definition?

Thanks!

Rodrigo Gómez

Opus output files - always stereo at 48kHz?

Reply #2
Sampling rate: depending on the specified bitrate, the codec will use the sampling rate that fits best. The resulting file will have whichever sample rate the encoder used, but the decoding can be at any supported sample rate (so if it says 48khz in VLC, for instance, is because the decoder there always uses 48khz, correct?)
That's kind of what it does. It actually changes the bandwidth, not the sample rate, but the result is similar to what happens when you reduce the sample rate. All Opus files are 48kHz, so decoders will typically output 48kHz audio.

Channels: in the definition it says that the encoder chooses the number of channel according to the bitrate specified, but this parameter can be modified and appears to be used in the opusenc, I mean: if I specify the --downmix-mono option then the resulting file says that it has 1 channel, but the bitrate specified is used in any case, so in theory (and that's an example they mention on the definition) a downmixed-mono audio at a specific bitrate should have better quality than the same audio at the same bitrate, but with the 2 channels.
True, but opusenc is very good at deciding when to downmix to mono. If your bitrate is low enough, you'll get the same thing whether you use --downmix-mono or not. (Technically, all Opus streams are stereo. To encode mono audio in opus, the encoder just doesn't encode the difference between left and right.)

Opus output files - always stereo at 48kHz?

Reply #3
I assume you are just using opusenc?  Internally all sorts of things are going on, but at a high level you always get 48kHz.  You can have any number of channels you want with Opus, but opusenc aggressively downmixes at low bitrates.  You are seeing stereo to mono, but it will also downmix surround to stereo at quite modest bitrates.  Internally it prefers to use coupled channels at all but the highest bitrates.

Opus output files - always stereo at 48kHz?

Reply #4
Here are the relevant internal definitions lifted from the spec.    Whichever bandwidth type is used internally, the sample rate is always reported externally as 48 kHz, and timings, samples, etc are all calculated using this rate.
Code: [Select]
+----------------------+-----------------+-------------------------+
  | Abbreviation        | Audio Bandwidth | Sample Rate (Effective) |
  +----------------------+-----------------+-------------------------+
  | NB (narrowband)      |          4 kHz |                  8 kHz |
  |                      |                |                        |
  | MB (medium-band)    |          6 kHz |                  12 kHz |
  |                      |                |                        |
  | WB (wideband)        |          8 kHz |                  16 kHz |
  |                      |                |                        |
  | SWB (super-wideband) |          12 kHz |                  24 kHz |
  |                      |                |                        |
  | FB (fullband)        |      20 kHz (*) |                  48 kHz |
  +----------------------+-----------------+-------------------------+

Each of the five bandwidths is only available with certain encoding modes (Celt/Silk/hybrid) and certain frame sizes, giving a total of 32 possible audio frame configurations.

Opus output files - always stereo at 48kHz?

Reply #5
Hello,

Thanks for the info and confirmation.

@lithopsian: yes, I'm using opusenc to encode. In my particular case I will be dealing with mono or stereo samples only.

Regards,

Rodrigo Gómez

Opus output files - always stereo at 48kHz?

Reply #6
Mine seems not to be at 48khz, it's 44.1 (when my file was that).

Though this was a Mono file, but pretty sure it always upsampled before, not matter the content (or downsample).

Opus output files - always stereo at 48kHz?

Reply #7
Mine seems not to be at 48khz, it's 44.1 (when my file was that).

Though this was a Mono file, but pretty sure it always upsampled before, not matter the content (or downsample).


The Opus output is 48kHz.  There is a header field that contains the sample rate that the Opus was encoded from and presumably you are seeing that.  What software is telling you that it is 44.1kHz?

Not always stereo though.  Opus can support anything from 1 to 255 channels, although only up to 8 is currently meaningful.  Some decoders will always output stereo since there is a simplified API for this.

Opus output files - always stereo at 48kHz?

Reply #8
Hiyas, I'm confused a bit too tho I think opus resamples everything to 48kHz (unless it's already 48k)

Here mediainfo raw output for converte file

Code: [Select]
General
Complete name                            : E:\xfer\phone\Music\Bonobo - Ten Tigers (2014)\01 - Ten Tigers (Bengal Edit).opus
Format                                   : OGG
File size                                : 2.63 MiB
Duration                                 : 3mn 33s
Overall bit rate                         : 103 Kbps
Album                                    : Ten Tigers
Album/Performer                          : Bonobo
Track name                               : Ten Tigers (Bengal Edit)
Track name/Position                      : 1
Track name/Total                         : 3
Performer                                : Bonobo
Label                                    : Ninja Tune
Recorded date                            : 2014
Writing application                      : opusenc from opus-tools v0.1.9
ENCODER_OPTIONS                          : --bitrate 96 --vbr --comp 10 --ignorelength
R128_TRACK_GAIN                          : -2

Audio
ID                                       : 23531 (0x5BEB)
Format                                   : Opus
Duration                                 : 3mn 33s
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Writing library                          : libopus 1.1


and here foobar's properties tech tab for the same output

Code: [Select]
File name : 01 - Ten Tigers (Bengal Edit).opus
Folder name : E:\xfer\phone\Music\Bonobo - Ten Tigers (2014)
File path : E:\xfer\phone\Music\Bonobo - Ten Tigers (2014)\01 - Ten Tigers (Bengal Edit).opus
Subsong index : 0
File size : 2.62 MB (2 755 892 bytes)
Last modified : 2014-06-24 17:45:40
Duration : 3:33.772 (10 261 076 samples)
Sample rate : 48000 Hz
Channels : 2
Bitrate : 103 kbps
Codec : Opus
Encoding : lossy
Tool : libopus 1.1
Track gain : -0.00 dB
Album gain : +0.00 dB
<SAMPLERATE_ORIGINAL> : 44100


I wonder that MI doesn't mention 48khz at all.

Opus output files - always stereo at 48kHz?

Reply #9
Might be a simple case of sloppy coding.  The Opus header has a field called "Input Sample Rate".  This is *not* the sample rate of the encoded Opus audio, but I wouldn't be surprised if many tools simply read it and throw it onto the screen.  The spec specifically says "This field is _not_ the sample rate to use for playback of the encoded data".  The Input Sample Rate field is the sample rate of the audio that was originally input to the Opus encoder, possibly useful in some situations.

If you want to get technical, it is possible to decode Opus audio at rates other than 48kHz, although the internal sample counting rate (the granulepos) is fixed at 48kHz.  The reference decoder can output at 8, 12, 16, 24, or 48 kHz, but in practice you are very unlikely to see anything except 48 kHz for music output.

Opus output files - always stereo at 48kHz?

Reply #10
Mine seems not to be at 48khz, it's 44.1 (when my file was that).

Though this was a Mono file, but pretty sure it always upsampled before, not matter the content (or downsample).


The Opus output is 48kHz.  There is a header field that contains the sample rate that the Opus was encoded from and presumably you are seeing that.  What software is telling you that it is 44.1kHz?

Not always stereo though.  Opus can support anything from 1 to 255 channels, although only up to 8 is currently meaningful.  Some decoders will always output stereo since there is a simplified API for this.


Mediainfo is what i looked at.

Opus output files - always stereo at 48kHz?

Reply #11
Yeah, mediainfo just reports the sample rate from the header, which is the sample rate of whatever the Opus was encoded from.

 

Opus output files - always stereo at 48kHz?

Reply #12
Yeah, mediainfo just reports the sample rate from the header, which is the sample rate of whatever the Opus was encoded from.


Ah okay, that explains it.