Skip to content

Per-timestamp frame extraction spawns ffmpeg serially (up to 1000 in a row) #290

Closed

Description

@TMHSDigital

Summary

Several tools grab frames one ffmpeg process at a time in a for ... await loop. Each spawn costs ~200 ms before decoding, and only one core is used.

Where

  • src/tools/sampleFrames.ts:186-197 (timestamps/scenes, up to MAX_FRAMES_CEILING = 1000)
  • src/tools/indexRecording.ts:118-126 (up to 120 keyframes)
  • src/tools/stepGuide.ts:132-137, 168-175
  • src/tools/contactSheet.ts:91-96
  • src/utils/images.ts:57-65 (encodeInlineImages)

Details

for (const [i, t] of ts.entries()) { ... await runFfmpeg(buildSampleAtTimestampArgs(...)) }.

Impact

Scenes mode with maxFrames 1000 on an hour-long recording takes minutes; index_recording spends 30-60 s on frame grabs before OCR starts.

Steps to reproduce

  1. sample_frames { input: <1h recording>, mode: "scenes", maxFrames: 1000 } and watch: one ffmpeg at a time

Suggested fix

Add a small shared concurrency pool (e.g. Math.max(2, os.availableParallelism()/2)) used by these loops, preserving output order. Optionally batch nearby timestamps into one ffmpeg with a select filter.

Acceptance criteria

  • Frame-extraction loops run with bounded concurrency
  • Output order and naming unchanged
  • Measured speedup noted in the PR

Getting started

  • Relevant files: src/tools/sampleFrames.ts, src/tools/indexRecording.ts, src/tools/stepGuide.ts, src/tools/contactSheet.ts, src/utils/images.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: M. audit-key: performance|src/tools/sampleFrames.ts|timestamp loop sequential spawn

Activity

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

    @TMHSDigital
    OwnerAuthor

    Fixed in fd1c1e6: mapPool (src/utils/pool.ts) runs the frame-extraction loops in sample_frames, index_recording, step_guide, contact_sheet and encodeInlineImages with bounded concurrency (a quarter of the cores, 2 to 4), keeping output order and names. Measured: 40 timestamp grabs from a 720p clip, 14.8 s serial vs 5.5 s pooled (2.7x, 12 cores). Verified with pool unit tests and the full suite (1085 passed).

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

    help wantedperformancepriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions