mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-02-03 21:23:48 +00:00
[PR #1675] [MERGED] [FIX] DVB OCR: Memory Leak & Quantization Issues #2387
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/CCExtractor/ccextractor/pull/1675
Author: @hrideshmg
Created: 3/15/2025
Status: ✅ Merged
Merged: 3/22/2025
Merged by: @cfsmp3
Base:
master← Head:fix_985📝 Commits (2)
580a168fix: do not free ocr text before return435de6cfix(OCR): erode and dilate function📊 Changes
1 file changed (+24 additions, -27 deletions)
View changed files
📝
src/lib_ccx/ocr.c(+24 -27)📄 Description
In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
Closes #985
DVB subtitle extraction is currently broken on the latest master build. I've verified this by testing it on the following few files:
09-ITV_Red_Heat.ts2016-12-15-BBC4.tsCHANNEL_4_2016-06-21.tschan7_BBC NEWS.tsI've found two root issues on why this is the case:
ocr_bitmap()is freed before being returned. Removing this free causes memory leaks (as pointed out by #1511).quantize_map()function--quant 0 (or 2)with the first fix enables proper extraction of DVB subtitles.I've spent the past two days trying to understand this function and have narrowed it down to the
erode()function introduced in PR 1510. I believe this is better explained visually, so here are the subtitle bitmaps before and after theerode()call for two different video files:Before
After
Fixes
erode()function, I noticed that the text was being eroded based on transparency rather than the text background. This method will only work for bitmaps which have their quantized text color be transparent.I've modified erode and dilate so that they now use the text and text background color rather than the alpha.
I'm getting these colors from the loop which populates the mcit variable. This approach has been pretty successful in my limited amount of testing, however it relies on the assumption that the background and text color will always be the second and third most frequently occurring colors respectively.
channel5-2018-02-12.tsis one exception though, in it the text color is the fourth most frequently occurring color (black, the bg color is repeated twice for some reason). So erosion succeeds but dilation fails, the result is still better than the raw quantized results but it might be worthwhile to disable quantization by default.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.