[PR #1830] [MERGED] fix(ocr): Improve DVB subtitle OCR quality (fixes #243) #2581

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

📋 Pull Request Information

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

Base: masterHead: fix/issue-243-dvb-ocr-quality


📝 Commits (1)

  • 7e1a014 fix(ocr): Improve DVB subtitle OCR quality (fixes #243)

📊 Changes

7 files changed (+47 additions, -24 deletions)

View changed files

📝 src/lib_ccx/ccx_common_option.c (+1 -1)
📝 src/lib_ccx/dvb_subtitle_decoder.c (+6 -1)
📝 src/lib_ccx/lib_ccx.c (+13 -0)
📝 src/lib_ccx/ocr.c (+4 -17)
📝 src/lib_ccx/telxcc.c (+6 -1)
📝 src/lib_ccx/ts_info.c (+16 -3)
📝 src/rust/lib_ccxr/src/common/options.rs (+1 -1)

📄 Description

Summary

This PR fixes Issue #243 where DVB subtitles from Spanish broadcasts were producing corrupt/garbled OCR output.

Before (garbage text):

alajentiegaranual dep jemios
panalos mejoyesinatonesidellbarco dellRatoniRerez!

After (readable text):

¡Bienvenidos a la entrega anual de premios
para los mejores ratones del barco del Ratón Pérez!

Problem Analysis

The original DVB bitmap images were perfectly clear and readable when examined directly. Running Tesseract directly on the exported PNG bitmaps produced good results like "para los mejores ratones del bareo del Ratón Pérez!" (only minor errors).

However, CCExtractor's preprocessing pipeline was degrading the image quality before passing it to Tesseract:

Issue 1: pixContrastNorm causing problems

The pixContrastNorm() function from Leptonica was being applied to enhance contrast, but for some DVB sources (particularly the Spanish broadcasts), this was actually degrading the image rather than improving it.

Issue 2: Aggressive color quantization

The default ocr_quantmode=1 applies CCExtractor's internal quantize_map() function which reduces the image to just 3 colors. This aggressive color reduction loses important detail that Tesseract needs for accurate character recognition.

Changes Made

Core OCR improvements (src/lib_ccx/ocr.c)

  • Removed pixContrastNorm() calls from both the main OCR pass and the color detection pass
  • These were causing more harm than good for DVB subtitle images

Default settings change

  • src/lib_ccx/ccx_common_option.c: Changed default ocr_quantmode from 1 to 0
  • src/rust/lib_ccxr/src/common/options.rs: Changed Rust-side default to match (the Rust parser was overriding the C default)

Safety improvements

  • src/lib_ccx/dvb_subtitle_decoder.c: Added NULL check in dvbsub_close_decoder()
  • src/lib_ccx/telxcc.c: Added NULL check in telxcc_close()
  • src/lib_ccx/lib_ccx.c: Added code to NULL out cinfo->codec_private_data pointers after decoder close to prevent double-free crashes
  • src/lib_ccx/ts_info.c: Added codec-specific cleanup in dinit_cap() for DVB and Teletext decoders

Testing Performed

Test 21 - English DVB subtitles

  • File: test_21_85271be4d2.mpg
  • Result: Completes in ~1 second with font color tags and good OCR quality
  • Sample output: "Soldier, you put every man and woman in this sub in jeopardy"

Test 239 - DVB timing

  • File: test_239_767b546f96.m2ts
  • Result: All 8 subtitles have valid timing with no overlaps
  • Verified: No zero-duration subtitles, no timing overlaps

Spanish DVB - Issue #243

  • File: Cine Clan TVE Perez, el ratoncito de tus sueños 2_cortado.ts (1.3GB)
  • Result: Now produces readable Spanish text
  • Before: alajentiegaranual dep jemios (garbage)
  • After: a la entrega anual de premios (readable)

Backwards Compatibility

Users who prefer the old quantization behavior can use --quant 1 on the command line to restore it.

Dependencies

This PR is based on branch fix/memory-issues-batch-2.1 which should be merged first.

  • Fixes #243 (DVB Subtitle OCR Problems - corrupt/empty output with Spanish broadcasts)

🤖 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/1830 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/15/2025 **Status:** ✅ Merged **Merged:** 12/16/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/issue-243-dvb-ocr-quality` --- ### 📝 Commits (1) - [`7e1a014`](https://github.com/CCExtractor/ccextractor/commit/7e1a01447a33a6140c7dfd248bc39e626bc89962) fix(ocr): Improve DVB subtitle OCR quality (fixes #243) ### 📊 Changes **7 files changed** (+47 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/ccx_common_option.c` (+1 -1) 📝 `src/lib_ccx/dvb_subtitle_decoder.c` (+6 -1) 📝 `src/lib_ccx/lib_ccx.c` (+13 -0) 📝 `src/lib_ccx/ocr.c` (+4 -17) 📝 `src/lib_ccx/telxcc.c` (+6 -1) 📝 `src/lib_ccx/ts_info.c` (+16 -3) 📝 `src/rust/lib_ccxr/src/common/options.rs` (+1 -1) </details> ### 📄 Description ## Summary This PR fixes Issue #243 where DVB subtitles from Spanish broadcasts were producing corrupt/garbled OCR output. **Before (garbage text):** ``` alajentiegaranual dep jemios panalos mejoyesinatonesidellbarco dellRatoniRerez! ``` **After (readable text):** ``` ¡Bienvenidos a la entrega anual de premios para los mejores ratones del barco del Ratón Pérez! ``` ## Problem Analysis The original DVB bitmap images were perfectly clear and readable when examined directly. Running Tesseract directly on the exported PNG bitmaps produced good results like "para los mejores ratones del bareo del Ratón Pérez!" (only minor errors). However, CCExtractor's preprocessing pipeline was degrading the image quality before passing it to Tesseract: ### Issue 1: pixContrastNorm causing problems The `pixContrastNorm()` function from Leptonica was being applied to enhance contrast, but for some DVB sources (particularly the Spanish broadcasts), this was actually degrading the image rather than improving it. ### Issue 2: Aggressive color quantization The default `ocr_quantmode=1` applies CCExtractor's internal `quantize_map()` function which reduces the image to just 3 colors. This aggressive color reduction loses important detail that Tesseract needs for accurate character recognition. ## Changes Made ### Core OCR improvements (`src/lib_ccx/ocr.c`) - Removed `pixContrastNorm()` calls from both the main OCR pass and the color detection pass - These were causing more harm than good for DVB subtitle images ### Default settings change - **`src/lib_ccx/ccx_common_option.c`**: Changed default `ocr_quantmode` from 1 to 0 - **`src/rust/lib_ccxr/src/common/options.rs`**: Changed Rust-side default to match (the Rust parser was overriding the C default) ### Safety improvements - **`src/lib_ccx/dvb_subtitle_decoder.c`**: Added NULL check in `dvbsub_close_decoder()` - **`src/lib_ccx/telxcc.c`**: Added NULL check in `telxcc_close()` - **`src/lib_ccx/lib_ccx.c`**: Added code to NULL out `cinfo->codec_private_data` pointers after decoder close to prevent double-free crashes - **`src/lib_ccx/ts_info.c`**: Added codec-specific cleanup in `dinit_cap()` for DVB and Teletext decoders ## Testing Performed ### Test 21 - English DVB subtitles - **File**: `test_21_85271be4d2.mpg` - **Result**: ✅ Completes in ~1 second with font color tags and good OCR quality - **Sample output**: "Soldier, you put every man and woman in this sub in jeopardy" ### Test 239 - DVB timing - **File**: `test_239_767b546f96.m2ts` - **Result**: ✅ All 8 subtitles have valid timing with no overlaps - **Verified**: No zero-duration subtitles, no timing overlaps ### Spanish DVB - Issue #243 - **File**: `Cine Clan TVE Perez, el ratoncito de tus sueños 2_cortado.ts` (1.3GB) - **Result**: ✅ Now produces readable Spanish text - **Before**: `alajentiegaranual dep jemios` (garbage) - **After**: `a la entrega anual de premios` (readable) ## Backwards Compatibility Users who prefer the old quantization behavior can use `--quant 1` on the command line to restore it. ## Dependencies This PR is based on branch `fix/memory-issues-batch-2.1` which should be merged first. ## Related Issues - Fixes #243 (DVB Subtitle OCR Problems - corrupt/empty output with Spanish broadcasts) 🤖 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:22:54 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2581