kedro_datasets.video.VideoDataset

class kedro_datasets.video.VideoDataset(*, filepath, fourcc='mp4v', credentials=None, fs_args=None, metadata=None)[source]

VideoDataset loads / save video data from a given filepath as sequence of PIL.Image.Image using OpenCV.

Example usage for the YAML API:

cars:
  type: video.VideoDataset
  filepath: data/01_raw/cars.mp4

motorbikes:
  type: video.VideoDataset
  filepath: s3://your_bucket/data/02_intermediate/company/motorbikes.mp4
  credentials: dev_s3

Example usage for the Python API:

 from kedro_datasets.video import VideoDataset
 import numpy as np

 video = VideoDataset(
...     filepath="https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"
... ).load()
 frame = video[0]

Example creating a video from numpy frames using Python API:

 from kedro_datasets.video.video_dataset import VideoDataset, SequenceVideo
 import numpy as np
 from PIL import Image

 frame = np.ones((640, 480, 3), dtype=np.uint8) * 255
 imgs = []
 for i in range(255):
...     imgs.append(Image.fromarray(frame))
...     frame -= 1
...
 video = VideoDataset(filepath=tmp_path / "my_video.mp4")
 video.save(SequenceVideo(imgs, fps=25))

Example creating a video from numpy frames using a generator and the Python API:

 from kedro_datasets.video.video_dataset import VideoDataset, GeneratorVideo
 import numpy as np
 from PIL import Image

 def gen():
...     frame = np.ones((640, 480, 3), dtype=np.uint8) * 255
...     for i in range(255):
...         yield Image.fromarray(frame)
...         frame -= 1
...
 video = VideoDataset(filepath=tmp_path / "my_video.mp4")
 video.save(GeneratorVideo(gen(), fps=25, length=None))

Methods

exists()

Checks whether a data set's output already exists by calling the provided _exists() method.

from_config(name, config[, load_version, ...])

Create a data set instance using the configuration provided.

load()

Loads data by delegation to the provided load method.

release()

Release any cached data.

save(data)

Saves data by delegation to the provided save method.

__init__(*, filepath, fourcc='mp4v', credentials=None, fs_args=None, metadata=None)[source]

Creates a new instance of VideoDataset to load / save video data for given filepath.

Parameters:
  • filepath (str) – The location of the video file to load / save data.

  • fourcc (Optional[str]) – The codec to use when writing video, note that depending on how opencv is installed there might be more or less codecs avaiable. If set to None, the fourcc from the video object will be used.

  • credentials (Optional[dict[str, Any]]) – Credentials required to get access to the underlying filesystem. E.g. for GCSFileSystem it should look like {“token”: None}.

  • fs_args (Optional[dict[str, Any]]) – Extra arguments to pass into underlying filesystem class constructor (e.g. {“project”: “my-project”} for GCSFileSystem).

  • metadata (Optional[dict[str, Any]]) – Any arbitrary metadata. This is ignored by Kedro, but may be consumed by users or external plugins.

exists()

Checks whether a data set’s output already exists by calling the provided _exists() method.

Return type:

bool

Returns:

Flag indicating whether the output already exists.

Raises:

DatasetError – when underlying exists method raises error.

classmethod from_config(name, config, load_version=None, save_version=None)

Create a data set instance using the configuration provided.

Parameters:
  • name (str) – Data set name.

  • config (dict[str, Any]) – Data set config dictionary.

  • load_version (str | None) – Version string to be used for load operation if the data set is versioned. Has no effect on the data set if versioning was not enabled.

  • save_version (str | None) – Version string to be used for save operation if the data set is versioned. Has no effect on the data set if versioning was not enabled.

Return type:

AbstractDataset

Returns:

An instance of an AbstractDataset subclass.

Raises:

DatasetError – When the function fails to create the data set from its config.

load()

Loads data by delegation to the provided load method.

Return type:

TypeVar(_DO)

Returns:

Data returned by the provided load method.

Raises:

DatasetError – When underlying load method raises error.

release()

Release any cached data.

Raises:

DatasetError – when underlying release method raises error.

Return type:

None

save(data)

Saves data by delegation to the provided save method.

Parameters:

data (TypeVar(_DI)) – the value to be saved by provided save method.

Raises:
  • DatasetError – when underlying save method raises error.

  • FileNotFoundError – when save method got file instead of dir, on Windows.

  • NotADirectoryError – when save method got file instead of dir, on Unix.

Return type:

None