Spaces:
Sleeping
Sleeping
File size: 810 Bytes
19583ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | """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)
|