Skip to content

Conversation

@cfsmp3
Copy link
Contributor

@cfsmp3 cfsmp3 commented Dec 18, 2025

Summary

Fixes #1109 - Garbled SRT from transport stream

For I/P-only streams (like HDHomeRun recordings), the caption buffer was being flushed on every reference frame. Since ALL frames in these streams are reference frames, this defeated the caption reordering mechanism, causing garbled output like:

  • "eaSnk out of theic offe." instead of "Sneak out of the office."
  • "Wa fitor brdoaing ougrp 12." instead of "Wait for boarding group 12."

Root Cause

The stream has no B-frames (only I/P frames), but frames arrive in decode order rather than display order. The original code flushed the buffer on every reference frame (I and P), which meant:

  1. Buffer was flushed on every frame
  2. No caption reordering could occur
  3. Captions were output in decode order (wrong)

The Fix

  • Only flush the buffer and reset reference PTS on IDR frames (NAL type 5), not on P-frames
  • Initialize currefpts on first frame to avoid huge indices at stream start
  • Properly flush buffer and reset reference when large PTS gaps are detected

This allows P-frames to accumulate in the buffer and be sorted by their PTS-based indices before output.

Before/After

Before After
eaSnk out of theic offe. Sneak out of the office.
Wa fitor brdoaing ougrp 12. Wait for boarding group 12.
Orge, t toou yr neighborho odMcnaDold's now. Or, get to your neighborhood McDonald's now.

The output now matches FFmpeg's extraction exactly.

Test plan

🤖 Generated with Claude Code

For I/P-only streams (like HDHomeRun recordings), the caption buffer was
being flushed on every reference frame (I and P). Since ALL frames in these
streams are reference frames, this defeated the caption reordering mechanism,
causing garbled output.

The fix:
- Only flush the buffer and reset reference PTS on IDR frames (NAL type 5),
  not on P-frames
- Initialize currefpts on first frame to avoid huge indices at stream start
- Properly flush buffer and reset reference when large PTS gaps are detected

This allows P-frames to accumulate in the buffer and be sorted by their
PTS-based indices before output.

Fixes #1109

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit a0809ca...:
Report Name Tests Passed
Broken 4/13
CEA-708 8/14
DVB 6/7
DVD 0/3
DVR-MS 2/2
General 4/27
Hardsubx 0/1
Hauppage 0/3
MP4 3/3
NoCC 10/10
Options 66/86
Teletext 17/21
WTV 0/13
XDS 24/34

Your PR breaks these cases:

NOTE: The following tests have been failing on the master branch as well as the PR:


It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

Fix clippy warning: variable does not need to be mutable.
The current_index variable is only assigned once during initialization
and never modified afterward.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@cfsmp3 cfsmp3 merged commit 138ccd0 into master Dec 18, 2025
29 of 31 checks passed
@cfsmp3 cfsmp3 deleted the fix/issue-1109-garbled-srt-hdhomerun branch December 19, 2025 06:03
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.

[BUG] Garbled SRT from over air transport stream (TS) encoded from HDHomerun Extend

3 participants