[PR #1842] [MERGED] fix: Fix garbled captions from HDHomeRun and I/P-only H.264 streams #2607

Open
opened 2026-01-29 17:23:03 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1842
Author: @cfsmp3
Created: 12/18/2025
Status: Merged
Merged: 12/18/2025
Merged by: @cfsmp3

Base: masterHead: fix/issue-1109-garbled-srt-hdhomerun


📝 Commits (2)

  • c8f6b56 fix: Fix garbled captions from HDHomeRun and I/P-only H.264 streams
  • 9fe2dab style: Remove unused mut from current_index variable

📊 Changes

2 files changed (+73 additions, -15 deletions)

View changed files

📝 src/lib_ccx/avc_functions.c (+32 -3)
📝 src/rust/src/avc/nal.rs (+41 -12)

📄 Description

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

  • Tested with HDHomeRun sample from issue #1109
  • Verified output matches FFmpeg extraction
  • Tested with other TS samples to ensure no regression

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/1842 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/18/2025 **Status:** ✅ Merged **Merged:** 12/18/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/issue-1109-garbled-srt-hdhomerun` --- ### 📝 Commits (2) - [`c8f6b56`](https://github.com/CCExtractor/ccextractor/commit/c8f6b565fd148a7b1e2193bf160448d55db55956) fix: Fix garbled captions from HDHomeRun and I/P-only H.264 streams - [`9fe2dab`](https://github.com/CCExtractor/ccextractor/commit/9fe2dab6d4dfccd879d4cbb47d6838b8ebd498ba) style: Remove unused mut from current_index variable ### 📊 Changes **2 files changed** (+73 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/avc_functions.c` (+32 -3) 📝 `src/rust/src/avc/nal.rs` (+41 -12) </details> ### 📄 Description ## 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 - [x] Tested with HDHomeRun sample from issue #1109 - [x] Verified output matches FFmpeg extraction - [x] Tested with other TS samples to ensure no regression 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:23:03 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2607