Skip to content

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.

NameSummary
fit_framesframes [T, H, W, 3] resized to size squares by area interpolation.
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_fileA 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.
windowThe (start, stop) seconds of the window PickClip wrote under clip.
PickClipA 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.
DecodeVideoframes 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.
RowA 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.
mediaA 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.

function source

def fit_frames(frames: np.ndarray, size: int) -> np.ndarray

frames [T, H, W, 3] resized to size squares by area interpolation.

function source

def fetch(
url: str = 'url',
to: str = 'mp4',
*,
timeout: float = 30.0,
max_bytes: int = 256 * 2 ** 20,
threads: int | None = None,
) -> 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.

function source

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.

function source

def window(element: Batch, clip: str) -> tuple[float, float]

The (start, stop) seconds of the window PickClip wrote under clip.

dataclass source

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.

def declared(facts: Mapping[str, object]) -> Mapping[str, object]

Windows seconds long, as [start, stop] under to.

def random_map(element: Batch, rng: np.random.Generator) -> Batch | Rejected

dataclass source

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).

def declared(facts: Mapping[str, object]) -> Mapping[str, object]

frames RGB frames at fps, each a size square, under to.

def map(element: Batch) -> Batch | Rejected

dataclass source

class 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.

def map(element: Batch) -> Batch

function source

def media(
listing: Files,
extensions: Sequence[str] = ('.mp4', '.avi', '.mov', '.webm'),
) -> Files

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.