Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/lib_ccx/dvb_subtitle_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ typedef struct DVBSubContext
LLONG time_out;
#ifdef ENABLE_OCR
void *ocr_ctx;
int ocr_initialized; // Flag to track if OCR has been lazily initialized
#endif
DVBSubRegion *region_list;
DVBSubCLUT *clut_list;
Expand Down Expand Up @@ -442,7 +443,11 @@ void *dvbsub_init_decoder(struct dvb_config *cfg)
}

#ifdef ENABLE_OCR
ctx->ocr_ctx = init_ocr(ctx->lang_index);
// Lazy OCR initialization: don't init here, wait until a bitmap actually needs OCR
// This avoids ~10 second Tesseract startup overhead for files that have DVB streams
// but don't actually produce any bitmap subtitles (e.g., files with CEA-608 captions)
ctx->ocr_ctx = NULL;
ctx->ocr_initialized = 0;
#endif
ctx->version = -1;

Expand Down Expand Up @@ -1701,6 +1706,12 @@ static int write_dvb_sub(struct lib_cc_decode *dec_ctx, struct cc_subtitle *sub)
// Perform OCR
#ifdef ENABLE_OCR
char *ocr_str = NULL;
// Lazy OCR initialization: only init when we actually have a bitmap to process
if (!ctx->ocr_initialized)
{
ctx->ocr_ctx = init_ocr(ctx->lang_index);
ctx->ocr_initialized = 1; // Mark as initialized even if init_ocr returns NULL
}
if (ctx->ocr_ctx)
{
int ret = ocr_rect(ctx->ocr_ctx, rect, &ocr_str, region->bgcolor, dec_ctx->ocr_quantmode);
Expand Down
Loading