media module

class datumaro.components.media.MediaElement(path: str)[source]

Bases: object

__init__(path: str) None[source]
property path: str

Path to the media file

property ext: str

Media file extension

__eq__(other: object) bool[source]

Return self==value.

class datumaro.components.media.Image(data: Optional[Union[numpy.ndarray, Callable[[str], numpy.ndarray]]] = None, *, path: Optional[str] = None, size: Optional[Tuple[int, int]] = None)[source]

Bases: datumaro.components.media.MediaElement

__init__(data: Optional[Union[numpy.ndarray, Callable[[str], numpy.ndarray]]] = None, *, path: Optional[str] = None, size: Optional[Tuple[int, int]] = None)[source]
property data: numpy.ndarray

Image data in BGR HWC [0; 255] (float) format

property has_data: bool
property has_size: bool
property size: Optional[Tuple[int, int]]

Returns (H, W)

__eq__(other)[source]

Return self==value.

save(path)[source]
class datumaro.components.media.ByteImage(data: Optional[Union[bytes, Callable[[str], bytes]]] = None, *, path: Optional[str] = None, ext: Optional[str] = None, size: Optional[Tuple[int, int]] = None)[source]

Bases: datumaro.components.media.Image

__init__(data: Optional[Union[bytes, Callable[[str], bytes]]] = None, *, path: Optional[str] = None, ext: Optional[str] = None, size: Optional[Tuple[int, int]] = None)[source]
get_bytes()[source]
property ext

Media file extension

save(path)[source]
class datumaro.components.media.VideoFrame(video: datumaro.components.media.Video, index: int)[source]

Bases: datumaro.components.media.Image

__init__(video: datumaro.components.media.Video, index: int)[source]
property size: Tuple[int, int]

Returns (H, W)

property index: int
property video: datumaro.components.media.Video
class datumaro.components.media.Video(path: str, *, step: int = 1, start_frame: int = 0, end_frame: Optional[int] = None)[source]

Bases: datumaro.components.media.MediaElement, Iterable[datumaro.components.media.VideoFrame]

Provides random access to the video frames.

__init__(path: str, *, step: int = 1, start_frame: int = 0, end_frame: Optional[int] = None) None[source]
close()[source]
__getitem__(idx: int) datumaro.components.media.VideoFrame[source]
get_frame_data(idx: int) datumaro.components.media.VideoFrame[source]
__iter__() Iterator[datumaro.components.media.VideoFrame][source]

Iterates over frames lazily, if possible.

property length: Optional[int]

Returns frame count, if video provides such information.

Note that not all videos provide length / duration metainfo, so the result may be undefined.

Also note, that information may be inaccurate because of variable FPS in video or incorrect metainfo. The count is only guaranteed to be valid after video is completely read once.

The count is affected by the frame filtering options of the object, i.e. start frame, end frame and frame step.

property frame_size: Tuple[int, int]

Returns (H, W)

__eq__(other: object) bool[source]

Return self==value.