ccextractor icon indicating copy to clipboard operation
ccextractor copied to clipboard

[BUG] --hardsubx --tickertext bypasses subtitle output and leaves debug side effects

Open Xavrir opened this issue 8 months ago • 1 comments

CCExtractor version: 0.96.5

Necessary information

  • Is this a regression (i.e. did it work before)? Unknown
  • What platform did you use? Linux
  • What were the used arguments? --hardsubx --tickertext input.mp4

Summary

The --hardsubx --tickertext path appears to be incomplete.

--tickertext is documented as searching for burned-in ticker text at the bottom of the screen, but the current implementation does not send OCR results through the normal subtitle output path.

Instead, it:

  1. prints ticker OCR text with printf()
  2. writes debug JPEG files into the current working directory
  3. never frees the returned Rust string
  4. calls strlen() without a NULL check

As a result, the ticker-text path appears to bypass subtitle encoding entirely even though it is exposed as a user-facing option.

Code

src/lib_ccx/hardsubx.c

if (ctx->tickertext)
    hardsubx_process_frames_tickertext(ctx, enc_ctx);

src/lib_ccx/hardsubx_decoder.c

ticker_text = _process_frame_tickertext(ctx, ctx->rgb_frame,
                                        ctx->codec_ctx->width,
                                        ctx->codec_ctx->height,
                                        frame_number);
printf("frame_number: %d\n", frame_number);

if (strlen(ticker_text) > 0)
    printf("%s\n", ticker_text);

There is no add_cc_sub_text() / encode_sub() call in hardsubx_process_frames_tickertext(), so enc_ctx is never used.

src/rust/src/hardsubx/decoder.rs

let write_path: String = format!("./lum_im{}.jpg", index);
pixWrite(write_path_c, lum_im, IFF_JFIF_JPEG as i32);

let write_path: String = format!("./im{}.jpg", index);
pixWrite(write_path_c, lum_im, IFF_JFIF_JPEG as i32);

subtitle_text

The Rust helper writes JPEGs unconditionally and returns a string to C, but the C caller does not call free_rust_c_string(ticker_text).

Expected behavior

--hardsubx --tickertext should route OCR results through the normal subtitle output flow and should not leave debug-only side effects in normal runs.

Suggested Fix

  • send ticker OCR results through add_cc_sub_text() / encode_sub()
  • remove or guard the pixWrite() calls behind a debug option
  • add free_rust_c_string(ticker_text) in the ticker-text path
  • add a NULL check before strlen(ticker_text)

Xavrir avatar Mar 25 '26 15:03 Xavrir

I reproduced this on the pre-fix commit (74e3842e) with a synthetic ticker sample

Commands used:

./linux/build -debug -system-libs -hardsubx
ffmpeg -y -f lavfi -i color=c=black:s=1280x720:r=25:d=45 \
  -vf \"drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:text='NUUS DIT IS N TOETS TIKKER':fontcolor=white:fontsize=40:x=40:y=h-48\" \
  -c:v libx264 -pix_fmt yuv420p ticker.mp4
./linux/ccextractor --quiet --hardsubx --tickertext --ocrlang afr -o out.srt ticker.mp4

Observed terminal output:

frame_number: 1000
NUUS DIT IS N TOETS TIKKER

=================================================================
==100849==ERROR: LeakSanitizer: detected memory leaks
...
SUMMARY: AddressSanitizer: 28 byte(s) leaked in 1 allocation(s).

Observed side effects:

$ ls /tmp | grep -E '^(lum_im|im)1000\\.jpg$'
im1000.jpg
lum_im1000.jpg

$ stat /tmp/ccextractor-ticker-repro/out.srt
stat: cannot statx '/tmp/ccextractor-ticker-repro/out.srt': No such file or directory

So the pre-fix behavior is:

  • ticker OCR text is printed to stdout
  • debug JPEGs are written into the working directory
  • no subtitle output file is produced
  • ASan reports the leaked ticker string

Xavrir avatar Mar 25 '26 16:03 Xavrir