Skip DTS advancement when source frames are missing #465
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.
PR Title
Improve DTS pass-through handling to maintain contiguous MP4 timelines
Description
This PR enhances the DTSPassThroughStrategy to make MP4 timeline generation more robust when dealing with irregular or unstable source timestamps.
Problem
In pass-through DTS mode, raw frame timestamps from the source can:
Jump forward significantly (e.g., due to connectivity drops or source jitter)
The cases lead to non-contiguous DTS values in the generated MP4, causing issues with seeking, playback smoothness, and timeline consistency.
Solution
The DTSPassThroughStrategy::getDTS() logic has been updated to normalize and clamp frame timestamps while still preserving pass-through behavior as much as possible:
Large positive jumps (diffInMsecs > ideal frame duration)
Clamps the jump to one ideal frame duration to keep the MP4 timeline contiguous, with a warning log for visibility.
Key Changes:
Introduced calculation of:
idealDurationInMsecs (1000 / fps)
maxJumpInMsecs (equal to ideal frame duration)
Added explicit clamping for large timestamp gaps
Added log when timestamp jumps are corrected
Impact:
Ensures monotonically increasing DTS values
Prevents large gaps in MP4 timelines
Improves seek accuracy and playback stability