Spaces:
Sleeping
Sleeping
Download O2LaF/o2laf/inference/video.py from blanchon/O2LaF-Demo: direct link, hf CLI and curl.
- Browser
- Download file 810 Bytes
-
https://huggingface.co/spaces/blanchon/O2LaF-Demo/resolve/main/O2LaF/o2laf/inference/video.py
- Command line
-
hf download hf://spaces/blanchon/O2LaF-Demo/O2LaF/o2laf/inference/video.py
-
curl -L -o video.py https://huggingface.co/spaces/blanchon/O2LaF-Demo/resolve/main/O2LaF/o2laf/inference/video.py
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) | |