Skip to content

Fix Matroska B-frame stream-copy timestamps - #18

Merged
Sergilol88 merged 9 commits into
mainfrom
fix/matroska-bframe-timestamps
Oct 11, 2026
Merged

Sergilol88 merged 9 commits into
mainfrom
fix/matroska-bframe-timestamps

Conversation

@Sergilol88

Copy link
Copy Markdown
Owner

What this fixes

Some Matroska HEVC/H.264 recordings with reordered B-frames expose non-monotonic or missing DTS. A normal FFmpeg stream-copy remux can clamp those decode timestamps and collapse multiple frames onto the same PTS.

Reproduced on an OBS HEVC MKV:

  • source: 0 duplicate PTS, 16/17 ms frame spacing
  • current VFR FastCut export: 195,035 duplicate PTS, dominant 50 ms spacing
  • packet-level setts repair: 0 duplicate PTS, 16/17 ms spacing

Implementation

  • probe a short packet sample before video export
  • leave streams with valid monotonic DTS unchanged
  • for affected streams, preserve source PTS and synthesize only monotonic DTS with FFmpeg setts
  • apply the repair to single-range, multi-range, audio-processing and final concat/remux passes
  • bump app version to 0.5.1
  • add regression coverage and release notes

Video remains stream-copy; no video re-encoding is introduced.

Manual validation still required

Before merge/release, test the PR build with the reproduced OBS source through a real multi-range export and verify packet spacing plus MPC playback.

Copy link
Copy Markdown
Owner Author

Final validation before merge:

  • Source checks: green on Python 3.10 / 3.12 / 3.13.
  • Portable Windows build/audit: green.
  • Minimal FFmpeg runtime verifies required capabilities including setts.
  • Portable launch smoke test: passed.
  • Manual regression test on the reproduced OBS HEVC/MKV source:
    • 47,400 video packets
    • 0 duplicate PTS
    • average interval 16.668 ms
    • median / P95 / P99 = 17 ms
    • 99.998% of positive intervals are 16/17 ms
    • one 77 ms interval occurs exactly at a new keyframe on a lossless multi-range splice boundary
  • Visual playback is smooth in MPC.
  • Audio sync checked around edits and is correct.

Code review found no release-blocking cleanup issues. The repair remains packet-level stream copy; source PTS are preserved and only DTS are synthesized when required. Final Matroska temp-part remux paths are covered so the timestamp corruption is not reintroduced during concat.

Ready for v0.5.1 hotfix release.

@Sergilol88
Sergilol88 merged commit eb6c1df into main Oct 11, 2026
7 checks passed
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.

1 participant