Opus 1.4 Corrupted audio while encode of 128 channels
Environment
Opus 1.4 (commit: 82ac57d9f1aa) OS: Win/MacOS
Repro steps
I have very simple encoder as below, I try to encode 128 channels where I have sine wave on every channel, I set total bitrate as 64kbps * 128 = 8192kbps
So I instantiate Encoder as follows:
Encoder encoder(8192, 48000, 128);
Actual result:
Audio corrupted on last channels, up to total loss of audio in last channel.
Issue can be reproduced on any number of channels depending on set total bitrate.
Expected result:
Audio should be of good quality in every channel if set total bitrate as 64kbps * channels
Results on different bitrates:
total bitrate 8192kbps - no audio on 128th channel at all:
total bitrate 16384kbps - it's 128kbps per channel, still 128th channel is corrupted:
Workaround:
Only after setting total bitrate to 20480kbps audio looks fine.
Encoder::Encoder(int bitrateKbps, int sampleRate, int numChannels)
{
int error = 0;
msEncoder_ = opus_multistream_encoder_create(sampleRate, numChannels, numChannels, 0, kChannelMapping.data(), OPUS_APPLICATION_AUDIO, &error);
if (error != OPUS_OK)
throw std::logic_error(std::string("Failed to create opus mulistream encoder, error: ") + opus_strerror(error));
opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_BITRATE(bitrateKbps * 1000));
opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_VBR(0));
opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_PACKET_LOSS_PERC(5));
opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_COMPLEXITY(5));
opus_multistream_encoder_ctl(msEncoder_, OPUS_SET_BANDWIDTH(OPUS_AUTO));
}
Encoder::~Encoder()
{
opus_multistream_encoder_destroy(msEncoder_);
}
bool Encoder::encode(const float* inBuf, int numInputSamples, unsigned char *outBuf, int outBufCapacity, int& encBytes)
{
encBytes = opus_multistream_encode_float(msEncoder_, inBuf, numInputSamples, outBuf, outBufCapacity);
if (encBytes < 0)
{
return false;
}
return true;
}
@jmvalin Would it be possible for you to review and suggest on the matter?
Are you able to reproduce with opus-tools?
Are you able to reproduce with opus-tools?
Hi! i can partly reproduce it for 12 channels with opus-tools. opusenc tells me the encoding succeeded, while neither opusdec nor Adobe Audition can open that encoded file. But ffmpeg can decode that file back to wav and the output is fine.
> opusenc --bitrate 1536 test.wav 1.opus
Encoding using libopus 1.5.2 (audio)
-----------------------------------------------------
Input: 48 kHz, 12 channels
Output: 12 channels (12 uncoupled)
20ms packets, 1536 kbit/s VBR
Preskip: 312
Encoding complete
-----------------------------------------------------
Encoded: 1 minute and 55.02 seconds
Runtime: 4 seconds
(28.75x realtime)
Wrote: 22900920 bytes, 5751 packets, 377 pages
Bitrate: 1585.64 kbit/s (without overhead)
Instant rates: 178.8 to 2990 kbit/s
(447 to 7475 bytes per packet)
Overhead: 0.452% (container+metadata)
> opusdec 1.opus 1.wav
Failed to open '1.opus'.
> ffmpeg -i 1.opus 1.wav
[ogg @ 0x13af06360] 644 bytes of comment header remain
[aist#0:0/opus @ 0x13af06c50] Guessed Channel Layout: 7.1.4
Input #0, ogg, from '1.opus':
Duration: 00:01:55.01, start: 0.000000, bitrate: 1593 kb/s
Stream #0:0: Audio: opus, 48000 Hz, 7.1.4, fltp
Metadata:
ENCODER : opusenc from opus-tools 0.2
ENCODER_OPTIONS : --bitrate 1536
Stream mapping:
Stream #0:0 -> #0:0 (opus (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '1.wav':
Metadata:
ISFT : Lavf61.7.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 12 channels, s16, 9216 kb/s
Metadata:
ENCODER_OPTIONS : --bitrate 1536
encoder : Lavc61.19.101 pcm_s16le
[out#0/wav @ 0x600001168000] video:0KiB audio:129375KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.000059%
size= 129375KiB time=00:01:55.00 bitrate=9216.0kbits/s speed=95.3x
Can you provide the test file you use and ideally the exact options you used to build libopus, opusenc, and opus-tools?
Hi, this is the 12 channel wav file i use, it's just white noise generated by python. 7_1_4_sequential_noise_test.wav
I use opusenc --bitrate 1536 7_1_4_sequential_noise_test.wav 714.opus to encode it to opus,
Here's the output file (github doesn't allow me to upload .opus file, so please rename it to 714.opus)
714.opus.wav
I tried to decode it but failed
opusdec 714.opus 714.wav
Failed to open '714.opus'.
I didn't build them by myself, i use brew install opus-tools to install them yesterday so i guess they are the latest version. I'm using macOS 15.6 with M4 chip.