cvkit.video_readers package

Submodules

cvkit.video_readers.cv2_reader module

class CV2VideoReader(video_path, fps, buffer_size=64)[source]

Bases: BaseVideoReaderInterface

This implementation uses OpenCV as the underlying library to implement the BaseVideoReaderInterface

Parameters:
  • video_path (str) – Path of the video.

  • fps (float) – The FPS of the video.

  • buffer_size (int) – The size of the frame pre-fetch buffer.

FLAVOR = 'opencv'

A unique identifier for BaseVideoReaderInterface Implementation.

next_frame() ndarray[source]

Returns the next frame from the buffer.

Returns:

Numpy array representing the newly fetched frame.

Return type:

Numpy.ndarray

pause() None[source]

Pause pre-fetching frames to the buffer.

random_access_image(position)[source]

Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.

Parameters:

position (int) – index of the desired frame.

Returns:

Numpy array representing the newly fetched frame at given position.

Return type:

Numpy.ndarray

release()[source]

Release file resources and clear buffer.

cvkit.video_readers.decord_reader module

cvkit.video_readers.deffcode_reader module

class DeffcodeVideoReader(video_path, fps, buffer_size=128)[source]

Bases: BaseVideoReaderInterface

This implementation uses Deffcode as the underlying library to implement the BaseVideoReaderInterface.

Parameters:
  • video_path (str) – Path of the video.

  • fps (float) – The FPS of the video.

  • buffer_size (int) – The size of the frame pre-fetch buffer.

FLAVOR = 'deffcode'

A unique identifier for BaseVideoReaderInterface Implementation.

next_frame() ndarray[source]

Returns the next frame from the buffer.

Returns:

Numpy array representing the newly fetched frame.

Return type:

Numpy.ndarray

pause() None[source]

Pause pre-fetching frames to the buffer.

random_access_image(position)[source]

Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.

Parameters:

position (int) – index of the desired frame.

Returns:

Numpy array representing the newly fetched frame at given position.

Return type:

Numpy.ndarray

release()[source]

Release file resources and clear buffer.

cvkit.video_readers.image_sequence_reader module

class ImageSequenceReader(video_path, fps, file_formats=['[jJ][pP][gG]', '[pP][nN][gG]', '[bB][mM][pP]'])[source]

Bases: BaseVideoReaderInterface

This implementation interprets a folder of images as a video stream. This can be useful when reading images from the datasets where the videos are stored as individual frames.

Parameters:
  • video_path (str) – Path to the folder containing images

  • fps (float) – FPS of the video stream

  • file_formats (list[str]) – list of valid glob patterns for supported images.

FLAVOR = 'Images'

A unique identifier for BaseVideoReaderInterface Implementation.

next_frame() ndarray[source]

Returns the next frame from the buffer.

Returns:

Numpy array representing the newly fetched frame.

Return type:

Numpy.ndarray

pause() None[source]

Pause pre-fetching frames to the buffer.

random_access_image(position)[source]

Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.

Parameters:

position (int) – index of the desired frame.

Returns:

Numpy array representing the newly fetched frame at given position.

Return type:

Numpy.ndarray

release() None[source]

Release file resources and clear buffer.

seek_pos(index: int) None[source]

Resets current buffer and seeks to the frame before the given index.

Parameters:

index (int) – The index of the frame you want to receive next.

cvkit.video_readers.video_reader_interface module

class BaseVideoReaderInterface(video_path, fps, buffer_size=128)[source]

Bases: ABC

An interface to provide intuitive access to video data. Users can implement this interface using various underlying video I/O libraries. We provide a few implementations using OpenCV, Deffcode, and Decord.

Parameters:
  • video_path (str) – Path of the video.

  • fps (float) – The FPS of the video.

  • buffer_size (int) – The size of the frame pre-fetch buffer.

FLAVOR = 'Abstract'

A unique identifier for BaseVideoReaderInterface Implementation.

get_current_frame() ndarray[source]

Returns previously fetched frame.

Returns:

Numpy array representing the frame previously fetched from the buffer.

Return type:

Numpy.ndarray

get_current_index() int[source]

Get the frame number of the newest frame fetched from the buffer.

Returns:

Frame number of current frame.

Return type:

int

get_number_of_frames() int[source]

Returns the total number of frames in the video.

Returns:

Total number of frames.

Return type:

int

abstract next_frame() ndarray[source]

Returns the next frame from the buffer.

Returns:

Numpy array representing the newly fetched frame.

Return type:

Numpy.ndarray

abstract pause() None[source]

Pause pre-fetching frames to the buffer.

abstract random_access_image(position) ndarray[source]

Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.

Parameters:

position (int) – index of the desired frame.

Returns:

Numpy array representing the newly fetched frame at given position.

Return type:

Numpy.ndarray

abstract release() None[source]

Release file resources and clear buffer.

seek_pos(index: int) None[source]

Resets current buffer and seeks to the frame before the given index.

Parameters:

index (int) – The index of the frame you want to receive next.

Module contents

initialize_video_reader(video_path, fps, reader_type)[source]

Detects underlying class based on reader_type. And generates appropriate BaseVideoReaderInterface subclass instance.

Parameters:
  • video_path (str) – Path to the target video file.

  • fps (float) – The FPS of the video.

  • reader_type (str) – A string to identify underlying video reader type. Refer to the FLAVOR attributes of each implementation.

Returns:

BaseVideoReaderInterface subclass instance.

Return type:

BaseVideoReaderInterface