Skip to content

Conversation

@DhanushVarma-2
Copy link
Contributor

@DhanushVarma-2 DhanushVarma-2 commented Nov 10, 2025

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

@cfsmp3
Copy link
Contributor

cfsmp3 commented Dec 8, 2025

Why would no subtitles cause an infinite loop? Do you have an example file?

I don't like the heuristics solution TBH.

@cfsmp3 cfsmp3 self-requested a review December 8, 2025 02:04
Copy link
Contributor

@cfsmp3 cfsmp3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please submit an example video to shows the problem.
There must be a way to fix it that doesn't consist on a random limit.

@DhanushVarma-2
Copy link
Contributor Author

Example TS file (no subtitles):
no_subs.ts
This is a valid MPEG-TS containing video + audio only, with no subtitle streams
Verified via:
ffprobe no_subs.ts | grep -i subtitle
(no output)

@DhanushVarma-2
Copy link
Contributor Author

A hard packet limit is not ideal and was added only as a safeguard to prevent the infinite loop.
The fix can instead terminate cleanly based on EOF / PMT parsing when no subtitle streams exist

- Check if all PMTs have been analyzed
- After PMT analysis, verify if any caption streams (PIDs) were found
- Exit after 1000 packets if num_of_PIDs == 0 (no caption streams)
- Uses PMT-based detection instead of arbitrary packet limits

This fix properly uses the Program Map Table data to determine if
subtitle streams exist, rather than relying on arbitrary packet counts.

Fixes CCExtractor#1754
@DhanushVarma-2 DhanushVarma-2 force-pushed the fix-ts-infinite-loop-fresh branch from 8e5f4d2 to 8d4d84b Compare December 17, 2025 06:53
@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 0b3ad40...:
Report Name Tests Passed
Broken 3/13
CEA-708 13/14
DVB 4/7
DVD 0/3
DVR-MS 2/2
General 5/27
Hardsubx 0/1
Hauppage 0/3
MP4 3/3
NoCC 10/10
Options 62/86
Teletext 1/21
WTV 0/13
XDS 25/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.

@ccextractor-bot
Copy link
Collaborator

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

Your PR breaks these cases:

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

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 8e8229b88b..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 7236304cfc..., Last passed: Never
  • ccextractor --out=srt --latin1 06b3a9237d..., Last passed: Never
  • ccextractor --out=srt --latin1 83f8cceb74..., Last passed: Never
  • ccextractor --out=srt --latin1 611b4a9235..., Last passed: Never
  • ccextractor --out=srt --latin1 b46e9e8e3f..., Last passed: Never
  • ccextractor --out=srt --latin1 89e417e622..., Last passed: Never
  • ccextractor --out=srt --latin1 d59eadc4ed..., Last passed: Never
  • ccextractor --out=sami --latin1 --autoprogram --no-goptime 5b4e0a6034..., Last passed: Never
  • ccextractor --service 1 --out=ttxt da904de35d..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 5ae2007a79..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 1e44efd810..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 add511677c..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 9a496d3828..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 56c9f34548..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 e9b9008fdf..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 c032183ef0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 d037c7509e..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 1974a299f0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 132d7df7e9..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 99e5eaafdc..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 b22260d065..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 7aad20907e..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla c41f73056a..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 5d3a29f9f8..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 70000200c0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 6dc772d881..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla adce82fd39..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 01509e4d27..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla ab9cf8cfad..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --output-field 2 5d3a29f9f8..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --output-field 2 c41f73056a..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --sentencecap c032183ef0..., Last passed: Never
  • ccextractor --autoprogram --out=bin --latin1 c032183ef0..., Last passed: Never
  • ccextractor --hauppauge --autoprogram --out=srt --latin1 a03b5b2a56..., Last passed: Never
  • ccextractor --autoprogram --out=srt --hauppauge --latin1 553d78e755..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --hauppauge --ucla --latin1 553d78e755..., Last passed: Never
  • ccextractor --out=ttxt c83f765c66..., Last passed: Never
  • ccextractor --goptime c83f765c66..., Last passed: Never
  • ccextractor --in=es dc7169d7c4..., Last passed: Never
  • ccextractor --in=wtv b46e9e8e3f..., Last passed: Never
  • ccextractor --wtvmpeg2 10f0f77cf4..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --endcreditstext "CCextractor Ends crdit Testing" addf5e2fc9..., Last passed: Never
  • ccextractor --endcreditsforatleast 3 --endcreditstext "CCextractor Ends crdit Testing" addf5e2fc9..., Last passed: Never
  • ccextractor --endcreditsforatmost 2 --endcreditstext "CCextractor Ends crdit Testing" addf5e2fc9..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --datets dcada745de..., Last passed: Never
  • ccextractor --out=srt --latin1 f23a544ba8..., Last passed: Never
  • ccextractor --out=srt --latin1 97cc394d87..., Last passed: Never
  • ccextractor --out=srt --latin1 10f0f77cf4..., Last passed: Never
  • ccextractor --out=srt --latin1 df3b4d62d3..., Last passed: Never
  • ccextractor --out=srt --latin1 d7e7dbdf68..., Last passed: Never
  • ccextractor --out=srt --latin1 76734ac4a7..., Last passed: Never
  • ccextractor --out=srt --latin1 c791382c94..., Last passed: Never
  • ccextractor --out=srt --latin1 f673b2f916..., Last passed: Never
  • ccextractor --out=srt --latin1 da75bdee47..., Last passed: Never
  • ccextractor --out=srt --latin1 bd6f33a669..., Last passed: Never
  • ccextractor --out=srt --latin1 0e5e6b26be..., Last passed: Never
  • ccextractor --out=srt --latin1 a226cc302d..., Last passed: Never
  • ccextractor --out=srt --latin1 ae6327683e..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 725a49f871..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --xds --ucla c813e713a0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds b992e0cccb..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds d0291cdcf6..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds c8dc039a88..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --ucla 53339f3455..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 83b03036a2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 7d3f25c32c..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --ucla 7d3f25c32c..., Last passed: Never

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.

@rboy1
Copy link
Contributor

rboy1 commented Dec 21, 2025

What's the root cause of the problem? what is subtitles begin half way through the video (e.g. when a new segment or show starts)?

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] Infinite binary output when processing .ts files with no subtitles

4 participants