mindspore.dataset.vision.VideoDecoder

View Source On AtomGit
class mindspore.dataset.vision.VideoDecoder(source)[source]

A decoder for single video streams, capable of parsing metadata and extracting frames from H264/H265-encoded content.

Parameters

source (str) – The path to the video file.

Raises
  • TypeError – If source is not string.

  • ValueError – If source does not exist or permission is denied.

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> ds.config.set_video_backend("Ascend")
>>> reader = vision.VideoDecoder(source="/path/to/filename")
get_frames_at(indices)[source]

Retrieves the frames at the specified indices.

Parameters

indices (list[int]) – List of frame indices to acquire.

Returns

numpy.ndarray, four-dimensional uint8 data for video. The format is [T, H, W, C]. T is the number of frames, H is the height, W is the width, C is the number of channels for RGB.

Raises
  • TypeError – If indices is not of type list.

  • TypeError – If an element in indices is not of type int.

  • ValueError – If an element in indices is not in the range [0, total frames).

Supported Platforms:

Ascend

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> ds.config.set_video_backend("Ascend")
>>> reader = vision.VideoDecoder(source="/path/to/filename")
>>> output_frames = reader.get_frames_at([0, 1, 2, 3])
property metadata

Getting metadata of the video stream.

Returns

dict, information about the metadata.

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> ds.config.set_video_backend("Ascend")
>>> reader = vision.VideoDecoder(source="/path/to/filename")
>>> metadata = reader.metadata