mindspore.dataset.vision.VideoDecoder

View Source On Gitee
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 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 frame at the specified index.

Parameters

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

Returns

numpy.ndarray, four dimensions 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 channel for RGB.

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

  • TypeError – If indices value is not of type int.

  • ValueError – If indices value is not in 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