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

PGS demuxing: set DTS equal to PTS for packets with PTS_DTS_flags=0b10 #833

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

cubicibo
Copy link
Contributor

@cubicibo cubicibo commented Mar 4, 2024

This is a tiny change in demuxing. I think this is more logical than a sporadically null DTS in the output .SUP file.

  • PTS_DTS_flags=0b10 suggests PTS=DTS, rather than DTS=0.
  • To mux back the stream, it is easier to check for PTS=DTS to find back 0b10 == PTS_DTS_flags candidates rather than look at the segment type and do guess work, as DTS=0 can be a valid value, while PTS and DTS should never be equal in a TS packet.

@cubicibo
Copy link
Contributor Author

cubicibo commented Apr 4, 2024

Hi @jcdr428, unfortunately this is a widespread misconception originating from DGDemux/eac3to suites. Many files were produced with these programs that always set DTS to zero, and people got the impression the field is never used.

However, when drmpeg designed the 'PG' SUP file format, he made sure to convey both PTS and DTS (truncated from 33 to 32 bits). Since the DTS is irrelevant for software players, it has been discarded by some tools like DGDemux.
If the SUP file is muxed back to a transport stream, the incorrect DTS value will cause issue to some decoders. It can range from PTS-DTS difference being larger than one second, memory overruns in the PG decoder (too many PCS buffered at once, overwriting ODS when it should be read-only). Or not enough decoding time if tsMuxer uses PTS for scheduling when DTS is zero.

If you take professionally authored discs and analyze the transport stream, you will see actual DTS values to ensure decoder memory and bandwidth are dully respected. Here is a good PG stream but with DTS=0 played on PS3. As you can see, the effect is catastrophic. https://github.com/justdan96/tsMuxer/assets/55701024/a634d8c4-a654-4d8a-874c-a8523f6d9d60

When muxing, tsMuxer and other professional muxers uses the "not permitted" case of PTS=DTS to know when a PES packet should have PTS_DTS_Flags equal to 0b10 or 0b11: https://github.com/justdan96/tsMuxer/blob/94cafe7244213870aaab37035c827ef839a15929/tsMuxer/tsMuxer.cpp#L609C1-L612C51

This proposed code change makes tsMuxer muxing and demuxing operations bijective for PG streams.

@jcdr428 jcdr428 merged commit 0bbbed3 into justdan96:master Apr 4, 2024
@jcdr428
Copy link
Collaborator

jcdr428 commented Apr 4, 2024

Ok, I've pushed the commit.

@cubicibo cubicibo deleted the MR/pgdts branch April 4, 2024 11:30
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

Successfully merging this pull request may close these issues.

2 participants