Video#

class mesmerize_core.arrays.LazyVideo(path, min_max=None, as_grayscale=False, rgb_weights=(0.299, 0.587, 0.114), **kwargs)#

LazyVideo reader, basically just a wrapper for decord.VideoReader. Should support opening anything that decord can open.

Important: requires decord to be installed: https://github.com/dmlc/decord

Parameters:
  • path (Path or str) – path to video file

  • min_max (Tuple[int, int], optional) – min and max vals of the entire video, uses min and max of 10th frame if not provided

  • as_grayscale (bool, optional) – return grayscale frames upon slicing

  • rgb_weights (Tuple[float, float, float], optional) – (r, g, b) weights used for grayscale conversion if as_graycale is True. default is (0.299, 0.587, 0.114)

  • kwargs – passed to decord.VideoReader

Examples

Lazy loading with CPU

from mesmerize_core.arrays import LazyVideo

vid = LazyVideo("path/to/video.mp4")

# use fpl to visualize

import fastplotlib as fpl

iw = fpl.ImageWidget(vid)
iw.show()

Lazy loading with GPU, decord must be compiled with CUDA options to use this

from decord import gpu
from mesmerize_core.arrays import LazyVideo

gpu_context = gpu(0)

vid = LazyVideo("path/to/video.mp4", ctx=gpu_context)
property dtype: str#

str data type

property shape: Tuple[int, int, int]#

[n_frames, x, y], RGB color dim not included in shape

property n_frames: int#

int number of frames

as_numpy()#

NOT RECOMMENDED, THIS COULD BE EXTREMELY LARGE. Converts to a standard numpy array in RAM.

Return type:

np.ndarray

property min: float#

float min value of the array if it were fully computed

property nbytes: int#

int number of bytes for the array if it were fully computed

property nbytes_gb: float#

float number of gigabytes for the array if it were fully computed

property ndim: int#

int Number of dimensions

property max: float#

float max value of the array if it were fully computed