-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base audio demuxer: track PTS of last sample for ID3 frames #5014
Conversation
@robwalch sorry for the initial noise - my first attempt with resetting the frameindex allowed the test video with broken timestamp values to play - but my volume was low, and I didn't notice the audio got out of sync. I've force-pushed a new fix. In this version, I changed the logic for recalculating the basePTS value to trigger whenever a timestamp is available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this works because each of your segments contains an ID3 timestamp?
src/demux/base-audio-demuxer.ts
Outdated
if ( | ||
this.basePTS === null || | ||
(this.frameIndex === 0 && Number.isFinite(timestamp)) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably works because each of your audio segments has timestamp data (Number.isFinite(timestamp)
is true
). If they did not, basePTS
would be the first PTS of the first segment we started demuxing. And that's what it should be as segments without ID3 timestamps are added based on frameIndex * sampleRate
(ADTS.appendFrame
).
So to resolve this issue we either need another property like lastPTS
which is the timestamp of the last frame or a method that will read the sample rate and return a current pts track time like we have at the top of appendFrame
in each audio demuxer. This way the latest PTS can be assigned to ID3 samples, and not only audio sample.
Big thank you for root causing this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also have a feeling that frameIndex === 0
was important, but I don't recall why off the top of my head - maybe for MP3 and/or one of the audio-only demo page streams?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR will...
lastPTS
), which tracks the PTS of the most recently added audio frame.Why is this Pull Request needed?
Changes in #4847 (to fix #4835) caused the basePTS value to only update on discontinuity events, which causes ID3 frames to all have the same PTS.
This tracks the PTS of added frames in a new field, which is then used when adding ID3 frames. This field is reset anytime on discontinuities and defaults to the basePTS value when no other value is available (first sample, etc).
Are there any points in the code the reviewer needs to double check?
Not that I'm aware of
Resolves issues:
#4963
Additional note, I also tested with the test video in #4835 and confirmed it still plays correctly as well.
Checklist