AGENT SKILL

sampling-and-indexing

Standardize video sampling and frame indexing so interval instructions and mask frames stay aligned with a valid key/index scheme.

License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 0
Forks
1

01 前言 Front Matter

name
sampling-and-indexing
description
Standardize video sampling and frame indexing so interval instructions and mask frames stay aligned with a valid key/index scheme.

03 SKILL.md 正文

When to use

  • You need to decide a sampling stride/FPS and ensure all downstream outputs (interval instructions, per-frame artifacts, etc.) cover the same frame range with consistent indices.

Core steps

  • Read video metadata: frame count, fps, resolution.
  • Use the requested target FPS to define one time grid beginning at zero with timestamps strictly before the video duration; map each grid time to a source frame. For a constant-rate video, duration is total_frames / source_fps. Follow explicit task endpoint rules when provided.
  • Keep the mapped source frame IDs in sample_ids, all < total_frames. Index downstream masks and intervals by sample ordinal 0..len(sample_ids)-1, using the same schedule for both. A source tail frame belongs only when selected by the grid or explicitly required by the task; keep the grid unchanged otherwise.
  • Use a strict interval key format such as "{start}->{end}" (integers only) and the task's endpoint convention. For half-open sample intervals, the final endpoint is len(sample_ids) and each sampled ordinal appears exactly once.

Pseudocode

import cv2
VIDEO_PATH = "<path/to/video>"
cap=cv2.VideoCapture(VIDEO_PATH)
n=int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
fps=cap.get(cv2.CAP_PROP_FPS)
target_fps = ...  # use the requested rate, with 0 < target_fps <= fps
assert n > 0 and fps > 0 and 0 < target_fps <= fps
sample_ids = []
k = 0
while k / target_fps < n / fps:
    source_id = min(n - 1, int(round(k * fps / target_fps)))
    if not sample_ids or source_id != sample_ids[-1]:
        sample_ids.append(source_id)
    k += 1
# Generate all downstream outputs only for sample_ids

Self-check list

  • [ ] sample_ids strictly increasing, all < total frame count.
  • [ ] Sampling count and timestamps follow the target grid, including a clip whose duration is not a multiple of the sample period; no extra off-grid endpoint.
  • [ ] Output coverage uses sampled ordinals, independent of source frame IDs; for half-open intervals the last endpoint equals len(sample_ids).
  • [ ] JSON keys are plain start->end, no extra text.
  • [ ] Any per-frame artifact store (e.g., NPZ) contains exactly the sampled frames and no extras.

04 同仓库更多 Skills