Fix Chrome seeking issues with files produced by opus-recorder #248
+2
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I recently discovered that Chrome has some issues with files created using this library. There are a few symptoms, including "ended" events being dispatched early and incorrect (and unstable) durations.
This codepen contains a simple demonstration of the issue.
I also opened this bug on the Chromium project.
I'm not super familiar with ogg/opus, but I believe this is a Chrome bug and not technically an issue with opus-recorder, however, the issue isn't reproducible with opus files I've created using other means (encoders on Android and iOS). So, even if the files are technically valid, there must be something that opus-recorder could do differently to avoid the Chrome issue. 🤔
Something that jumped out to me about the files Chrome liked is that they all had a start_pts/start_time (as reported by
ffprobe
) that matched the file's pre-skip, while affected files had a start_pts/start_time of 0. To try to confirm this was related, I modified an affected file so that its start_pts matched its pre-skip:The result no longer exhibited the problem in Chrome! 🎉
I ran the command again on the copy with an output_ts_offset of 0, just to verify that the issue came back (and therefore it wasn't being fixed by some other random thing the command was doing).
To translate this change to the library, I set the initial granule position to the offset (pre-skip) when encoding. I think this tracks with the spec's section on PCM sample position:
Interestingly, when I tried to set both the initial granule position and pre-skip to a value besides 3840, the issue returned! (It didn't repro on files created on other platforms that had matching, but different, start_pts and pre-skip values.) I'm not sure why this is; maybe the value is hardcoded into the compiled libopus?
Like I said, I'm not opus expert, so I'd love to hear your thoughts on this. Thanks!