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 videowindow_title (
str
) – the window title of the preview windowfps (
int
) – expected frames per second, note that this is not guaranteed, as the actual fps depends on the hardware limitexit_key (
int
) – the key to press to exit the preview windowexit_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 ndarraytensor
.- Parameters:
only_keyframes (
bool
) – if True keep only the keyframes, if False keep all frames and store the indices of the keyframes intags
kwargs – supports all keyword arguments that are being supported by av.open() as described in: https://pyav.org/docs/stable/api/_globals.html?highlight=open#av.open
- 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 secondcodec (
str
) – the name of a decoder/encoder
- Return type:
T
- Returns:
itself after processed