Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Decoder crashs when using files encoded by opus-recorder #16

Closed
Robbson opened this issue May 9, 2016 · 8 comments
Closed

Decoder crashs when using files encoded by opus-recorder #16

Robbson opened this issue May 9, 2016 · 8 comments

Comments

@Robbson
Copy link

Robbson commented May 9, 2016

Hello,

I am trying to decode ogg-opus files encoded by opus-recorder (a RecorderJS fork by Chris-Rudmin) with the help of node-opus. Unfortunately it crashes node. The output of the format event seems also to be weird because it's always showing 44100Hz independent from my chosen encoder settings on the client, which isn't a valid rate for opus at all.
The files created by opus-recorder work fine in the browser and also in VLC.

Btw. ogg-opus doesn't crash on all files. So e.g. the included 'input.opus' works as expected.
I have no idea where to look for the problem. The native binaries are gyp-compiled on Windows using the version delivered.

It can be easily tested using opus-recorder's decoder example that does some microphone recording and stores it to a blob that can be saved to a file. Using this file with the alsa example (or a modified version that puts all data to a file stream) on node leads to the crash.

Thanks,
Robbson

@Rantanen
Copy link
Owner

Rantanen commented May 9, 2016

Can you provide a sample file if you got one?

@Robbson
Copy link
Author

Robbson commented May 9, 2016

I've attached a test file. It has to be renamed before because of the file type restrictions.
test-file.ogg.txt

@Robbson
Copy link
Author

Robbson commented May 10, 2016

Btw. I tested in on Linux (Ubuntu 14.04) and it also crashed node (4.4.4).

@Robbson
Copy link
Author

Robbson commented May 12, 2016

After some investigation I noticed that the libopus version of node-opus is pretty old (1.1 Beta from 2014).
So I replaced it using the current 1.1.2 build. Now it doesn't crash anymore but there is still no decoded data. And the weird 44100Hz are still shown as format.

If you use the opusinfo command line tool you can also see those 44100Hz. By the way opusdec tool plays the ogg-opus file successfully but it also shows several errors before ("Error playing audio").

Now I try to debug node-opus in Visual Studio. Using the problematic file I get an exception because it tries to access a reference to the decoder which doesn't exist (dec is null):
int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) { return opus_packet_get_nb_samples(packet, len, dec->Fs); }

@Robbson
Copy link
Author

Robbson commented May 12, 2016

Ok, the print of the 44100Hz is not so weird because it's the original input frequency that is preserved in the opus header as metadata, independent from the encoding frequency.
After trying several other files (including official samples from the opus web site) the problem occurs when the original input frequency was 44100Hz. That's usually the case in a browser when using the Web Audio API.

@Robbson
Copy link
Author

Robbson commented May 12, 2016

I've found the issue.
If you don't specify the decode (output) frequency when instancing the decoder it doesn't fall back to 48000Hz but to the original input frequency that is stored in the header of the file. So when this original frequency is 44100 (e.g. sampled from a CD) you set it as the decoding frequency.
That leads to a crash because 44100 is a not supported decode frequency by opus and so the decoder instance is internally not created.

Btw. this output frequency is totally independent from any original or encoding frequency. So if you e.g. encoded a 44100Hz source at full band with 48000Hz you can still set the decoding freq. to 16000Hz if required.

That's why your assumption in the sample code:
"// NOTE: The decoder must use the same values when decoding the packets."
is not correct.

@Rantanen
Copy link
Owner

Rantanen commented Jun 5, 2016

Took me ages to get back to this. Was under allergies the week this was reported and then I kept pushing it away.

I updated opus to 1.1.2 and added some error checks for encoder/decoder creation and the opus _ctl function return value.

This shouldn't "fix" the issue of the encoder not working with bad bitrates but it should maybe give better error message and not crash.

Sorry for the delays. 😒

@Rantanen
Copy link
Owner

Rantanen commented Nov 7, 2016

Apparently even if you specified the decode frequency, it wasn't used. 😥

#21 should fix this as well.

@Rantanen Rantanen closed this as completed Nov 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants