Abdullah Sajjad
2020-Jun-11 13:58 UTC
[opus] OPUS encoded data size and bandwidth of encoder
Hey, I am having trouble with the size of the encoded bytes by Opus. I am also having issue with the Bandwidth ctl. Here is the scenario. If I encode 16khz sampled audio: opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_WIDEBAND)) opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&x)) = 1102 opus_encoder_ctl(enc, OPUS_GET_MAX_BANDWIDTH(&x)) = 1103 average encoded size = 120 bytes if I encode 48khz sampled audio: opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_WIDEBAND)) opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&x)) = 1103 opus_encoder_ctl(enc, OPUS_GET_MAX_BANDWIDTH(&x)) = 1103 average encoded size = 280 bytes I do not understand why 48khz encoded data has more bytes even when I am asking it to encode to a smaller frequency range. And why is the bandwidth set to medium band for 16khz sampled input? Shouldn't it be wideband? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.xiph.org/pipermail/opus/attachments/20200611/f598938d/attachment.html>
On Thu, 2020-06-11 at 18:58 +0500, Abdullah Sajjad wrote:> opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&x)) = 1102 > opus_encoder_ctl(enc, OPUS_GET_MAX_BANDWIDTH(&x)) = 1103 > average encoded size = 120 bytesOPUS_GET_BANDWIDTH defaults to OPUS_AUTO. Since it's returning OPUS_BANDWIDTH_MEDIUMBAND (1102) presumedly you set this elsewhere in your programme? OPUS_GET_MAX_BANDWIDTH is returning OPUS_BANDWIDTH_WIDEBAND (1103) which is the value you set, so that is expected.> opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&x)) = 1103 > opus_encoder_ctl(enc, OPUS_GET_MAX_BANDWIDTH(&x)) = 1103 > average encoded size = 280 bytesHere both are returning the WIDEBAND value. I believe MAX_BANDWIDTH defaults to OPUS_BANDWIDTH_FULLBAND so presumedly you also set this somehwere? Note that we recommend you _only_ set OPUS_MAX_BANDWIDTH, leaving OPUS_BANDWIDTH set to OPUS_AUTO. This allows the encoder to adapt to lower-quality signals, allowing better compression.> I do not understand why 48khz encoded data has more bytes even when I > am asking it to encode to a smaller frequency range.According to the values you've posted, the encoder is using MEDIUMBAND for the 16 kHz input. The narrower bandpass may explain the difference. You also don't mention calling OPUS_SET_BITRATE. The default bitrate depends on the input sample rate, so the encoder may feel it has room for a higher-quality encoding with your 48 kHz input even with the same bandpass. Try setting the same explicit bitrate target for both and see if that improves the result. Cheers, Ralph