Skip to main content
Topic: Bitrate seems constant even with drastic code changes (Read 1440 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Bitrate seems constant even with drastic code changes

I am encoding data from a receiver (speech or digital data plus noise) using Opus.  I am looking at the output as I vary options bench as the predicted packet loss, enabling of FEC, complexity, etc. and I seem to generally get ~75kbps regardless of the settings I choose.  Now I can "force" Opus to a specific bitrate by supplying the rate instead of AUTO and in that case I seem to get about 20kbps plus the rate I specified. (10 -> 32, 40 -> 63, 80 -> 103)

Here's my code:

Code: [Select]
    OpusEncoder *ptr = NULL;

    ptr = opus_encoder_create(24000, 2, OPUS_APPLICATION_AUDIO, &err);

    if (err<0)
    {
        output("failed to create an encoder: %s\n", opus_strerror(err));
        return NULL;
    }
    err = opus_encoder_ctl(ptr, OPUS_SET_BITRATE(OPUS_AUTO));
    opus_encoder_ctl(ptr, OPUS_SET_COMPLEXITY(1));
    opus_encoder_ctl(ptr, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_SUPERWIDEBAND));
    opus_encoder_ctl(ptr, OPUS_SET_PACKET_LOSS_PERC(5));
    opus_encoder_ctl(ptr, OPUS_SET_INBAND_FEC(TRUE));
   
    return ptr;

Is this to be expected or am I missing something?  I originally thought maybe my code wasn't "working" but I can change the bandwidth and hear the loss of frequencies in the upper bands not contained in the bandwidth so this makes me believe that things are working, in general.

Thanks

Re: Bitrate seems constant even with drastic code changes

Reply #1
I don't understand what is supposedly unexpected here?
"I hear it when I see it."

Re: Bitrate seems constant even with drastic code changes

Reply #2
The encoder always targets a specific bitrate. Setting it to OPUS_AUTO causes that target to be set based on the number of channels and sample rate of the input.

There are three modes that change how strongly the encoder biases its decisions to hit the target bitrate: CBR, CVBR, and VBR.

In CBR mode, every frame is exactly the same size in order to hit the target bitrate as closely as possible.

In CVBR mode (the default), the encoder produces frames of different sizes in an attempt to provide consistent quality, but adjusts the quality level so that the average bitrate over a short period of time will be close to the target bitrate.

In VBR mode, the target bitrate is only used to set the quality level, and the frame sizes will be however big or small the encoder thinks is necessary to meet that quality level. The quality level is set so that if you encode many hours of audio with a large variety of content, the average bitrate will be close to the target. Since your audio won't have much variety, you may not see bitrates very close to the target if you use this mode.

Re: Bitrate seems constant even with drastic code changes

Reply #3
My expectation was that as I increased the redundancy settings -- expected packet drop, FEC TRUE, etc. that the bitrate would go up.  Since it didn't I'm confused.  Is quality being reduced in order to provide these features?  Is there a generic target of 75kbps and if it can fit features in that bandwidth, it does?  Even when I jacked up the expected packet loss to 50% it had the same rate.  This is not what I expected...

Steve

Re: Bitrate seems constant even with drastic code changes

Reply #4
Octocontrabass answered this.

For reference, opus_encoder.c in opus_encoder_init:
Code: [Select]
st->bitrate_bps = 3000+Fs*channels;
"I hear it when I see it."

Re: Bitrate seems constant even with drastic code changes

Reply #5
Is quality being reduced in order to provide these features?
Yes. Since libopus always targets a specific bitrate, enabling features that require additional bits will reduce quality to ensure that the target is still being met.

Is there a generic target of 75kbps and if it can fit features in that bandwidth, it does?
OPUS_AUTO selects the target bitrate based on the number of channels and sample rate, and nothing else. Since all of your tests have been with the same number of channels and the same sample rate, the target bitrate has been the same.

Re: Bitrate seems constant even with drastic code changes

Reply #6
What Octocontrabass wrote above is correct.

Now I can "force" Opus to a specific bitrate by supplying the rate instead of AUTO and in that case I seem to get about 20kbps plus the rate I specified. (10 -> 32, 40 -> 63, 80 -> 103)

As for why you're getting a higher bitrate than you ask for, it's likely that you're using VBR *and* the file you're testing with is a hard sample for which Opus needs more bits. I believe the "default" (auto) bitrate is actually 64 kb/s.

 
SimplePortal 1.0.0 RC1 © 2008-2019