poseinterface.clips.extract_clip#
- poseinterface.clips.extract_clip(video_path, start_frame, duration)[source]#
Extract a video clip (and its clip labels if available).
Reads the source video and saves a
.mp4clip to aClips/subdirectory next to the source video. If a sibling*_videolabels.jsonfile exists (holding labels for the entire session video, using the same schema ascliplabels.json), a matching_cliplabels.jsoncontaining only the annotations within the requested frame range is also written.- Parameters:
video_path (
str|Path) – Path to the input.mp4video. The filename should follow the conventionsub-<subjectID>_ses-<sessionID>_cam-<camID>.mp4, and if a sibling labels file exists, its filename should besub-<subjectID>_ses-<sessionID>_cam-<camID>_videolabels.json.start_frame (
int) – Index of the first frame to include in the clip (0-based).duration (
int) – Number of frames to include in the clip. Ifstart_frame + durationexceeds the video length, the duration is clamped to the remaining frames and a warning is logged.
- Return type:
- Returns:
clip_path (Path) – Path to the output clip file.
clip_json (Path | None) – Path to the
_cliplabels.jsonfile for the clip if extracted, None otherwise.
- Raises:
ValueError – If
start_frameis negative ordurationis not positive.
Notes
This function optionally consumes a
*_videolabels.jsonfile, sibling to the input video file and holding labels for the entire video. This file is an intermediate cache useful for data contributors: it follows the same schema ascliplabels.jsonbut it refers to the full video, rather than to a clip of it. The*_videolabels.jsonfile is not part of the published benchmark dataset. For further details, see the “Intermediate file: videolabels.json” section of the benchmark dataset specification.This function assumes that the
idfield in theimageslist of the source*_videolabels.jsoncorresponds to 0-based global frame indices of the full video.