Add multi_find: locate multiple occurrences of an event

#10
Nemo Station org

Add multi_find β€” locate multiple occurrences of an event

find() returns only the earliest occurrence of an event in a clip. This PR adds multi_find(), which walks the timeline to return up to max_events occurrences, left-to-right.

How it works

Repeatedly trims the video to the unsearched tail [cursor, end], runs find on that sub-clip (exact trained prompt, no divergence), remaps the clip-local span back to global time, then advances the cursor past it. Stops on exactly two conditions: max_events reached, or the cursor runs off the end of the video.

API

result = marlin.multi_find("video.mp4", event="a person enters the room", max_events=5)
result["spans"]    # [(2.1, 4.8), (12.0, 14.3), ...] global timestamps, earliest-first
result["stopped"]  # "max_events" | "end_of_video" | "no_span"

Notes

  • find always emits some span, so there is no built-in "event absent" signal β€” max_events is the caller-supplied upper bound. If the event occurs fewer than max_events times, trailing spans may be spurious; set max_events to a tight expected maximum.
  • Adds two helpers: _video_duration (torchcodec) and _clip_segment (frame-accurate ffmpeg trim). Adds an ffmpeg runtime dependency.
  • min_gap/min_segment guards guarantee forward progress and drop degenerate spans.

Verified for syntax/structure (py_compile); not yet run against a real video on GPU.

widow-maker changed pull request status to merged

Sign up or log in to comment