Spaces:
Sleeping

blanchon's picture
fix first-frame anchor + atomic crash; load models once; vendor trimmed o2laf
19583ce
Raw History Blame Contribute Delete
810 Bytes
"""Reading source videos at a model's frame rate."""
from __future__ import annotations
from pathlib import Path
import numpy as np
from o2laf.inference.sampling import MAX_RGB_FRAMES
from o2laf.utils.video_util import VideoLoader, select_frame_indices
def load_source_video(path: str | Path, fps: int, max_frames: int = MAX_RGB_FRAMES) -> np.ndarray:
"""The whole of ``path`` resampled to ``fps``, up to its first ``max_frames`` frames, as uint8 ``[T,H,W,3]``."""
with VideoLoader(str(path), name=str(path)) as loader:
available = len(select_frame_indices(loader.get_frame_count(), loader.get_fps(), fps))
num_frames = min(available, int(max_frames))
frames = loader.get_clip(num_frames, target_fps=fps, random_sample=False)
return np.asarray(frames, dtype=np.uint8)