dew.data.video
Video records: a directory tree of clips, a clip window drawn once, and its frames.
PickClip draws a record’s time window, DecodeVideo reads its frames and
dew.data.audio.DecodeAudio its sound over the same window, so frames and
audio come from one draw. The AV reader is imported on use.
| Name | Summary |
|---|---|
fit_frames | frames [T, H, W, 3] resized to size squares by area interpolation. |
fetch | A record step that fetches the clip at the record’s url field into to as bytes, threads at once where given, as images.fetch does an image. |
local_file | A local file a decoder reads for a record’s media value, its bytes or a local or remote path, kept while the context is open: a remote one’s copy in Dew’s mirror (dew.data.declared.mirrored), refused (Unmirrored, a ValueError a decoder’s rejects take) where the mirror has no room for it. |
window | The (start, stop) seconds of the window PickClip wrote under clip. |
PickClip | A window of seconds drawn from the record’s rng within the media in field (a video or a sound file, its bytes or a path), margin seconds clear of either end, written under to as float64 [start, stop] seconds for every decoder of the record to read; it stacks as any field does. |
DecodeVideo | frames frames at fps from the start of the window under clip, read from the video in field, each fitted into a size square, under to. |
Row | A listed media file’s record with its path (video_path, else path) moved to mp4, where the decoders read it, and its caption, caption where it states none: every other field the record holds (a label, an id) reaches the batch as it is. |
media | A listing of files (Files(url, format="files")) cut to those whose name ends in one of extensions, any case: a directory’s media, not the lists and notes beside it, listed when the store is read (Files.suffixes), so a chain over media not fetched yet is made and recorded. |
fit_frames
Section titled “fit_frames”def fit_frames(frames: np.ndarray, size: int) -> np.ndarrayframes [T, H, W, 3] resized to size squares by area interpolation.
def fetch( url: str = 'url', to: str = 'mp4', *, timeout: float = 30.0, max_bytes: int = 256 * 2 ** 20, threads: int | None = None,) -> FetchA record step that fetches the clip at the record’s url field into
to as bytes, threads at once where given, as images.fetch does an image.
local_file
Section titled “local_file”def local_file(value: bytes | str) -> Iterator[str]A local file a decoder reads for a record’s media value, its bytes or a local or remote path,
kept while the context is open: a remote one’s copy in Dew’s mirror (dew.data.declared.mirrored),
refused (Unmirrored, a ValueError a decoder’s rejects take) where the mirror has no room for it.
window
Section titled “window”def window(element: Batch, clip: str) -> tuple[float, float]The (start, stop) seconds of the window PickClip wrote under clip.
PickClip
Section titled “PickClip”class PickClip( seconds: float, *, margin: float = 0.0, field: str = 'mp4', to: str = 'clip', rejects: bool = True,)A window of seconds drawn from the record’s rng within the media in field (a video or a sound
file, its bytes or a path), margin seconds clear of either end, written under to as float64
[start, stop] seconds for every decoder of the record to read; it stacks as any field does. Media
too short for the window, or that does not read, is counted and dropped.
rejects: bool-
Whether media that does not read or is too short is dropped (
filter_map) rather than an error.
PickClip.declared
Section titled “PickClip.declared”def declared(facts: Mapping[str, object]) -> Mapping[str, object]Windows seconds long, as [start, stop] under to.
PickClip.random_map
Section titled “PickClip.random_map”def random_map(element: Batch, rng: np.random.Generator) -> Batch | RejectedDecodeVideo
Section titled “DecodeVideo”class DecodeVideo( frames: int = 16, *, fps: float = FPS, size: int = 256, min_size: int = 0, field: str = 'mp4', clip: str = 'clip', to: str = 'video', rejects: bool = True,)frames frames at fps from the start of the window under clip, read from the video in
field, each fitted into a size square, under to. The frames must fit the window: one shorter
than frames / fps raises, as no record could pass. A clip that does not decode is counted and
dropped, and so is one whose frames are under min_size on their shorter side as stored, before
they are fitted ("too_small").
rejects: bool-
Whether a clip that does not decode is dropped (
filter_map) rather than an error. external: bool-
A video a record names by path is read from storage (
dew.data.pipeline.External).
DecodeVideo.declared
Section titled “DecodeVideo.declared”def declared(facts: Mapping[str, object]) -> Mapping[str, object]frames RGB frames at fps, each a size square, under to.
DecodeVideo.map
Section titled “DecodeVideo.map”def map(element: Batch) -> Batch | Rejectedclass Row(caption: str = '')A listed media file’s record with its path (video_path, else path) moved to mp4, where the
decoders read it, and its caption, caption where it states none: every other field the record
holds (a label, an id) reaches the batch as it is.
Row.map
Section titled “Row.map”def map(element: Batch) -> Batchdef media( listing: Files, extensions: Sequence[str] = ('.mp4', '.avi', '.mov', '.webm'),) -> FilesA listing of files (Files(url, format="files")) cut to those whose name ends in one of
extensions, any case: a directory’s media, not the lists and notes beside it, listed when the
store is read (Files.suffixes), so a chain over media not fetched yet is made and recorded.