Skip to content

OCR frame prep re-probes every frame and runs two serial upscales per frame #291

Closed

Description

@TMHSDigital

Summary

readFrames probes every frame with an unbounded Promise.all (up to 120 concurrent ffprobe) even though all frames share one known size, then runs the x2 and x4 lanczos upscales as separate ffmpeg passes writing compressed PNGs.

Where

  • src/utils/ocrScan.ts:27-47 (readFrames)
  • src/utils/ocrScan.ts:96 (MAX_SCAN_FRAMES)
  • src/utils/ocr.ts:20 (OCR_SCALES = [2, 4])
  • src/tools/findText.ts:22-23

Details

Measured locally on a 1080p frame: x2 upscale ~489 ms, x4 ~922 ms (2.7 MB PNG), ffprobe ~146 ms.

Impact

find_text/bug_report scans of 120 frames spend ~170 s upscaling before OCR, and spike to 120 concurrent ffprobe processes.

Steps to reproduce

  1. find_text { input: <1080p video>, scanEverySec: 1, maxFrames: 120 }

Suggested fix

Pass the known width/height from scanVideoFrames to skip per-frame probes; produce both scales in one ffmpeg (split to two outputs); write intermediates uncompressed (-compression_level 0 or BMP); run frames through the bounded pool from the frame-extraction issue.

Acceptance criteria

  • No per-frame ffprobe when the size is known
  • One ffmpeg per frame for both scales
  • Concurrency bounded

Getting started

  • Relevant files: src/utils/ocrScan.ts, src/utils/ocr.ts, src/tools/findText.ts
  • How to run tests: npm run build && npm test (also npm run typecheck and npm run lint)
  • Related docs: CONTRIBUTING.md, AGENTS.md

Filed by repo-audit/full-audit at f2fda28. Severity: medium. Effort: S-M. audit-key: performance|src/utils/ocrScan.ts|readFrames

Activity

  1. added
    performance
    on Nov 9, 2026
  2. TMHSDigital commented on Nov 10, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 81a8a4f: frames from one video are probed once (readFrames(..., { sameSize: true })), buildOcrPassArgs writes both upscales from one ffmpeg run as uncompressed scratch PNGs, and probes and pass runs go through the bounded mapPool. Measured: 20 frames at 1080p, 17.8 s before vs 7.2 s after (2.5x). Verified: new args tests, including a real ffmpeg run checking both output sizes, and the full suite (1089 passed).

  3. added a commit that references this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancepriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions