Skip to content

OCR video scans decode every frame at full resolution to keep 30–120 frames #391

Backlog

Description

@TMHSDigital

Summary

scanVideoFrames uses one -vf fps=N job, which decodes every source frame at full resolution to keep a few dozen. A pipeline redact { secrets: true } on a one-hour 30 fps recording decodes about 108,000 frames to keep 30, and a trim before the redact does not narrow the scan.

Where

  • src/utils/ocrScan.ts:104-112
  • src/utils/media.ts:178-199
  • src/utils/pipelineRun.ts:220-228
  • src/tools/findText.ts:203-204
  • src/tools/bugReport.ts:151-160
  • src/tools/indexRecording.ts:125-128 (the cheaper pattern already in use)
  • src/utils/targets.ts:310-315 (2 s GOP)

Details

scanVideoFrames sizes a sparse plan (planFpsSampling(length, 1 / opts.everySec, opts.maxFrames), by default 30 frames, at most 120) and then runs a single buildSampleByFpsArgs job: -i input -vf fps=N -frames:v MAX out_%05d.png. The fps filter needs every source frame decoded, at full resolution, to pick the few it keeps. For a pipeline redact { secrets: true } on a 1 h, 30 fps recording, everySec = ceil(3600/30) = 120, so about 108,000 frames are decoded to keep 30. The pipeline scan also gets no range, so a trim placed before the redact still has the whole source decoded (pipelineRun.ts:215 computes offset only to shift the hits afterwards). Recordings get a keyframe every 2 s (captureKeyframeArgs: -g fps*2), and index_recording already grabs its keyframes with one input-seek -ss t -i in -frames:v 1 per timestamp through mapPool (indexRecording.ts:125-128). Seeking that way decodes at most about 60 frames per sample.

Impact

Every pipeline render with secrets: true, find_text { scanEverySec } on a long clip, and bug_report on a long window spend minutes of full-core software decode before any OCR runs. At a typical 300-800 fps for 1080p H.264, 108k frames take roughly 2-6 min, against a few seconds for 30 seeks. The cost grows with recording length, not with the number of frames asked for, and the pipeline pays it again on every render.

Steps to reproduce

Record about 1 h at the default 30 fps, then call pipeline { input, steps: [{op:"trim",start:0,end:30},{op:"redact",secrets:true}], output }. The secret scan runs fps=0.0083 over the full hour before the 30 s clip is encoded.

Suggested fix

In scanVideoFrames, when the step is well above the keyframe interval (for example 1/plan.fps >= 4 s), compute the timestamps (range.start + i*step) and grab each with buildSampleAtTimestampArgs through mapPool, as index_recording does. Keep the fps filter for dense sampling. In resolveSecrets, pass range: { start: offset, duration: <trimmed length> } so a leading trim limits the scan to the frames that are actually rendered.

Acceptance criteria

  • Sparse scans seek per frame (-ss before -i, as index_recording already does) or decode keyframes only
  • The pipeline secrets scan passes the trimmed range
  • Before/after timing on a long recording in the PR

Getting started

  • Relevant files: src/utils/ocrScan.ts, src/utils/media.ts, src/utils/pipelineRun.ts, src/tools/findText.ts
  • Run tests: npm test (also npm run typecheck and npm run lint); see CONTRIBUTING.md
  • If you change a tool's schema or description, run npm run docs

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

Activity

  1. added
    help wanted
    performance
    effort: medium
    on Nov 29, 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

    effort: mediumhelp wantedperformancepriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions