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
PTS/DTS adjustment produces negative PTS/DTS values #1796
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump |
It will work correctly as-is running for several days. I don't know why it does... maybe the data is being appended as |
The src/remux/mp4-remuxer.js file also has a ptsNormalize method that probably does the same thing. |
If folks agree with the below implementation plan I'll go about implementing. Where it talks about timestampOffset, I believe this is already handled, as is the discontinuity. So like the issue report, this is purely about doing the rollover calculation correct. First step will be to find a MPEG-TS sample with a rollover to add it's bytes as a unit test. If anyone has one on hand, would appreciate it!
|
I think the first step is to fix any and all rollover math so the numbers don't turn negative. I can work on generating an MPEG-TS version of Big Buck Bunny that overflows in the first 15 seconds or so. |
We should be fine subtracting the 33-bit number itself. Javascript can safely represent integers to 53 bits. However, the bitwise operators work on 32-bit integer, so we will need to ensure the current code handles this accurately for the 33-bit timestamp. If something is done incorrectly in this process, I'd imagine it will be there. |
Hey @jon-valliere I got a test asset generated using Big Buck Bunny.
Confirms the roll-over in its own way. I can also see it in the hls.js PES parsing code. Looking at places we can host this for long term functional testing. Going to start looking at the code now that I've got all the respective pieces to ensure it's working accurately. 👍 |
szatmary while helping me craft the test asset also made an important point. If we want to handle the rollover completely, one case to keep in mind is one where you join a stream right at the point of rollover. It's possible the DTS will still be post-rollover, and the PTS is pre-rollover. |
Please see v0.14.3...v0.14.5#diff-14a34ee6c08b15d0e309d10c2c05f3d0 for recent changes in the remuxer.
Let me know if there's anything I can do to see this work across the line. 👍 |
So, one thing I've identified, because of the interesting property of the hls.js code subtracting I'm generating a second asset that will test the rollover point for us internally, which is at 2^32. It'd be nice to know the original intent behind the way the rollover point is handled now, but I believe it has to do with wanting easier bitwise operations on the PTS. But I don't think it's documented anywhere. The original commit is here; 48119b3 and it references keeping the sign in the 33-bit. The hls.js rollover point can be tested with;
Both continue to playback seamlessly across both the true MPEG-TS PTS rollover point, and when hls.js rolls over to (I believe) keep the PTS represented in a signed 32bit space.
The above was true on feature/v1 based branch. It is not so for master. On master, removing this adjustment code leads to very odd behaviour (410 hour stream time offset). The way we calculate InitPTS, and where that is applied has changed between the two branches. And the new way in feature/v1 doesn't set an incorrect stream time duration based on the initial (large) PTS value. As such, I've removed this code in the transmuxer TS PR; in |
@robwalch I don't know if there is anything to be done here for < v1. But the changes you've been making more recently around the muxing code if you could get them merged up into I don't believe there is any incorrect behaviour coming from this internal adjustment on either branch, but it does seem to be unnecessary on feature/v1.0.0. |
HI @itsjamie, I'll get the changes up to v0.14.6 merged in to feature/v1.0.0 by tomorrow afternoon. |
@jon-valliere I dont' remember exactly in what context this quote was fit, but I understand this is a case of bitstream reading, which obviously DataView itself does not provide. We have a bitstream reader in the demuxing codebase however as part of the Exponential-Golomb decoder which we use for the H264 syntax ( EDIT: That being said, you can also always read any bytes, and get to the bitwise values using appropriates bitmasks/shifting/adding operations :) Nothing else is what the bitstream reader will do for you in the end. |
On a side note, also check if we can rather make use of |
@tchakabam |
@robwalch The problem with a negative erroneous DTS (negative millions) is when the CTS is computed by subtracting the CTS = PTS - DTS you get a huge crazy number. |
See #2928 I think what you'll want to do is set https://github.com/video-dev/hls.js/pull/2928/files#diff-08ad4da53cab1312d324d6065c7722d1R266-R271
|
* upstream_hls.js/master: Bump webpack from 4.44.0 to 4.44.1 Compare set sort and shift flags after PTSNormalize is applied to both samples video-dev#1796 Bump karma from 5.1.0 to 5.1.1 Bump webpack from 4.43.0 to 4.44.0 Bump @types/chai from 4.2.11 to 4.2.12 Bump chromedriver from 84.0.0 to 84.0.1 Update lastDTS after realigning samples in case firstDTS set to a higher value video-dev#2905
Hi @jon-valliere, Please take a look at this build https://deploy-preview-2930--hls-js-dev.netlify.app/demo/ from #2930 and let it know if it addresses this issue. If you have stream samples with rolling PTS in audio/video/text/id3 tracks to test with it would be great to know they are working. Thanks! |
Environment
Steps to reproduce
https://github.com/video-dev/hls.js/blob/master/src/demux/tsdemuxer.js
Both PTS and DTS values have an adjustment code block
if (pesPts > 4294967295) { pesPts -= 8589934592; }
I believe this to be a mistake and the number should be decremented by 2^32 instead of 2^33. This will produce always positive numbers and forcing the integer rollover to occur at the 32bit Javascript integer ceiling.
@tchakabam Had suggested using DataView for reading the numbers. I do not believe this is possible because the PTS/DTS values are coded using the following format.
Using DataView to read a 32bit number would not produce the correct number in this situation.
The text was updated successfully, but these errors were encountered: