[PR #2060] [FIX] DVB subtitle OCR and SPUPNG output for options test on Linux #2872

Closed
opened 2026-01-29 17:24:21 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/2060

State: closed
Merged: No


In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

When processing DVB subtitles from the options test file, three things were wrong:

OCR text extraction failed completely - the code tried to use an undefined variable called "region" which didn't exist in that function scope. This caused crashes or garbage data.
SPUPNG XML output was missing the opening and closing wrapper tags. The file would start with individual subtitle entries but had no and tags around them. This happened because the header writing function was immediately writing the footer and freeing all data structures before any subtitle content could be written.
DVB subtitle regions were being processed repeatedly. After extracting text from a region, the code never marked it as processed by clearing its dirty flag, so the same regions kept getting processed over and over causing duplicate subtitle entries.

What was different in results:
Expected output had OCR text like "explosion" and "Safety remains our number one" inside the subtitle entries. Actual output had no OCR text at all because the extraction crashed.
Expected SPUPNG file structure was:
Actual output was just empty or missing the wrapper tags entirely.

How the fix works:
For OCR: Instead of using the undefined "region" variable, the code now loops through the display list to find the first valid region and uses that for the background color reference needed by the OCR function. This gives OCR the correct data to extract text from bitmap subtitles.
For SPUPNG structure: Removed the code block that was writing the footer immediately after the header. Now the header function only writes the header tags, subtitle content gets written in the middle, and the footer gets written later during normal cleanup. This produces the correct XML structure.
For duplicate processing: Added a loop at the end of subtitle processing that goes through all regions and sets their dirty flag to 0, marking them as already processed so they won't be processed again.

Added safety for non-OCR builds: When CCExtractor is compiled without OCR support, the code now explicitly sets OCR text pointers to NULL to prevent crashes from trying to use uninitialized memory.
All changes are minimal fixes that restore correct behavior without changing the overall architecture.
test link: https://sampleplatform.ccextractor.org/test/7992#

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/2060 **State:** closed **Merged:** No --- <!-- Please prefix your pull request with one of the following: **[FEATURE]** **[FIX]** **[IMPROVEMENT]**. --> **In raising this pull request, I confirm the following (please check boxes):** - [x] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [x] I have checked that another pull request for this purpose does not exist. - [x] I have considered, and confirmed that this submission will be valuable to others. - [x] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [x] I give this submission freely, and claim no ownership to its content. - [x] **I have mentioned this change in the [changelog](https://github.com/CCExtractor/ccextractor/blob/master/docs/CHANGES.TXT).** **My familiarity with the project is as follows (check one):** - [ ] I have never used CCExtractor. - [x] I have used CCExtractor just a couple of times. - [ ] I absolutely love CCExtractor, but have not contributed previously. - [ ] I am an active contributor to CCExtractor. --- When processing DVB subtitles from the options test file, three things were wrong: OCR text extraction failed completely - the code tried to use an undefined variable called "region" which didn't exist in that function scope. This caused crashes or garbage data. SPUPNG XML output was missing the opening and closing wrapper tags. The file would start with individual subtitle entries but had no <subpictures> and <stream> tags around them. This happened because the header writing function was immediately writing the footer and freeing all data structures before any subtitle content could be written. DVB subtitle regions were being processed repeatedly. After extracting text from a region, the code never marked it as processed by clearing its dirty flag, so the same regions kept getting processed over and over causing duplicate subtitle entries. What was different in results: Expected output had OCR text like "explosion" and "Safety remains our number one" inside the subtitle entries. Actual output had no OCR text at all because the extraction crashed. Expected SPUPNG file structure was: Actual output was just empty or missing the wrapper tags entirely. How the fix works: For OCR: Instead of using the undefined "region" variable, the code now loops through the display list to find the first valid region and uses that for the background color reference needed by the OCR function. This gives OCR the correct data to extract text from bitmap subtitles. For SPUPNG structure: Removed the code block that was writing the footer immediately after the header. Now the header function only writes the header tags, subtitle content gets written in the middle, and the footer gets written later during normal cleanup. This produces the correct XML structure. For duplicate processing: Added a loop at the end of subtitle processing that goes through all regions and sets their dirty flag to 0, marking them as already processed so they won't be processed again. Added safety for non-OCR builds: When CCExtractor is compiled without OCR support, the code now explicitly sets OCR text pointers to NULL to prevent crashes from trying to use uninitialized memory. All changes are minimal fixes that restore correct behavior without changing the overall architecture. test link: https://sampleplatform.ccextractor.org/test/7992#
claunia added the pull-request label 2026-01-29 17:24:21 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2872