docarray.document.mixins.video module#

class docarray.document.mixins.video.VideoDataMixin[source]#

Bases: object

Provide helper functions for Document to support video data.

classmethod generator_from_webcam(height_width=None, show_window=True, window_title='webcam', fps=30, exit_key=27, exit_event=None, tags=None)[source]#

Create a generator that yields a Document object from the webcam.

This feature requires the opencv-python package.

Parameters:
  • height_width (Optional[Tuple[int, int]]) – the shape of the video frame, if not provided, the shape will be determined from the first frame. Note that this is restricted by the hardware of the camera.

  • show_window (bool) – if to show preview window of the webcam video

  • window_title (str) – the window title of the preview window

  • fps (int) – expected frames per second, note that this is not guaranteed, as the actual fps depends on the hardware limit

  • exit_key (int) – the key to press to exit the preview window

  • exit_event – the multiprocessing/threading/asyncio event that once set to exit the preview window

  • tags (Optional[Dict]) – the tags to attach to the document

Return type:

Generator[T, None, None]

Returns:

a generator that yields a Document object from a webcam

load_uri_to_video_tensor(only_keyframes=False, **kwargs)[source]#

Convert a uri to a video ndarray tensor.

Parameters:
Return type:

T

Returns:

Document itself after processed

save_video_tensor_to_file(file, frame_rate=30, codec='h264')[source]#

Save tensor as a video mp4/h264 file.

Parameters:
  • file (Union[str, BinaryIO]) – The file to open, which can be either a string or a file-like object.

  • frame_rate (int) – frames per second

  • codec (str) – the name of a decoder/encoder

Return type:

T

Returns:

itself after processed