[PR #1763] [CLOSED] fix: prevent infinite loop when processing TS files with no subtitles #2486

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

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1763
Author: @DhanushVarma-2
Created: 11/10/2025
Status: Closed

Base: masterHead: fix-ts-infinite-loop-fresh


📝 Commits (2)

  • 8d4d84b fix: prevent infinite loop when TS files have no subtitle streams
  • 926293c style: apply clang-format to ts_functions.c

📊 Changes

1 file changed (+27 additions, -0 deletions)

View changed files

📝 src/lib_ccx/ts_functions.c (+27 -0)

📄 Description

Problem
When processing TS files containing no subtitles, ccextractor enters an infinite loop instead of exiting gracefully (Issue #1754).

Root Cause
The ts_readstream function had a do-while (!gotpes) loop that would run indefinitely when no subtitle streams were detected, because gotpes never became true in files without subtitles.

Solution
Instead of using an arbitrary packet limit, this fix properly detects when no subtitle streams exist by:

  1. Tracking PMT analysis: Monitors when all Program Map Tables have been analyzed
  2. Checking for caption streams: After PMT analysis, checks if any caption PIDs were registered (ctx->num_of_PIDs == 0)
  3. Grace period: Waits 1000 packets after PMT analysis to ensure all streams are detected
  4. Clean exit: Returns CCX_EOF with a clear debug message when no subtitles are found

Why This Approach is Better

  • PMT-based detection: Uses actual stream metadata instead of arbitrary limits
  • Deterministic: Based on MPEG-TS structure, not guesswork
  • Faster: Exits as soon as it's confirmed no caption streams exist (~1000 packets vs 50,000)
  • Maintains compatibility: Works for files with subtitles exactly as before
  • No magic numbers: Logic is based on actual stream parsing

Changes Made

  • src/lib_ccx/ts_functions.c: Added PMT analysis tracking and caption stream detection in ts_readstream function

Testing

  • Code compiles successfully without errors
  • Maintains backward compatibility for files with subtitles

Fixes #1754


🔄 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/1763 **Author:** [@DhanushVarma-2](https://github.com/DhanushVarma-2) **Created:** 11/10/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix-ts-infinite-loop-fresh` --- ### 📝 Commits (2) - [`8d4d84b`](https://github.com/CCExtractor/ccextractor/commit/8d4d84bd499ea3a457bc96d339bc8455c594fc86) fix: prevent infinite loop when TS files have no subtitle streams - [`926293c`](https://github.com/CCExtractor/ccextractor/commit/926293cd4395e2911774be2527a5144b64288299) style: apply clang-format to ts_functions.c ### 📊 Changes **1 file changed** (+27 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/ts_functions.c` (+27 -0) </details> ### 📄 Description Problem When processing TS files containing no subtitles, ccextractor enters an infinite loop instead of exiting gracefully (Issue #1754). Root Cause The `ts_readstream` function had a `do-while (!gotpes)` loop that would run indefinitely when no subtitle streams were detected, because `gotpes` never became true in files without subtitles. Solution Instead of using an arbitrary packet limit, this fix properly detects when no subtitle streams exist by: 1. **Tracking PMT analysis**: Monitors when all Program Map Tables have been analyzed 2. **Checking for caption streams**: After PMT analysis, checks if any caption PIDs were registered (`ctx->num_of_PIDs == 0`) 3. **Grace period**: Waits 1000 packets after PMT analysis to ensure all streams are detected 4. **Clean exit**: Returns `CCX_EOF` with a clear debug message when no subtitles are found Why This Approach is Better - **PMT-based detection**: Uses actual stream metadata instead of arbitrary limits - **Deterministic**: Based on MPEG-TS structure, not guesswork - **Faster**: Exits as soon as it's confirmed no caption streams exist (~1000 packets vs 50,000) - **Maintains compatibility**: Works for files with subtitles exactly as before - **No magic numbers**: Logic is based on actual stream parsing Changes Made - `src/lib_ccx/ts_functions.c`: Added PMT analysis tracking and caption stream detection in `ts_readstream` function Testing - Code compiles successfully without errors - Maintains backward compatibility for files with subtitles Fixes #1754 --- <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:22:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2486