Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OggMuxer issue with audio duration #114

Open
Valahaar opened this issue Mar 17, 2023 · 0 comments
Open

OggMuxer issue with audio duration #114

Valahaar opened this issue Mar 17, 2023 · 0 comments

Comments

@Valahaar
Copy link

Hi!

I was trying to use your OggMuxer but I encountered an issue with audio duration, which is consistently displayed to be 1/3rd of the correct one. Even if you are not actively thinking of fixing this code, I'd love a response to pinpoint whether this is actually the issue at hand. Unfortunately, I am not entirely familiar with the OGG specification, so I cannot say that this is the issue with 100% certainty, but I think it might be because your granule position code is not taking into account the opus packet code that is received (and thus the number of compressed frames in each packet):

const newCount = packets.reduce((acc, val) => acc + sampleRate * FRAME_SIZE_MAP[val[0] >> 3], 0);

I report here the RFC figures for both TOC and Code 3 packet frame count bytes as reference:

 0 1 2 3 4 5 6 7   0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+  +-+-+-+-+-+-+-+-+
| config  |s| c |  |v|p|     M     |
+-+-+-+-+-+-+-+-+  +-+-+-+-+-+-+-+-+

In my case, the first two bytes I receive from my opus source are 01111011 10000011.

Hence, the packet code is 0b(11) = 3 (the last two bits of the first byte) and the number of frames is also 3 0b(000011) (the last six bits of the second byte), which would explain why my duration is always 1/3rd of the correct one.

If you know this to be the case, I'd gladly open a PR (should be a pretty easy fix, even for code 1 and code 2 packets :) ). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant