ibllib.io.video
Functions for fetching video frames, meta data and file locations
Functions
Raises a value error is the provided label is not supported. |
|
Obtain numpy array corresponding to a particular video frame in video_path |
|
Obtain numpy array corresponding to a particular video frame in video. |
|
Return a bunch of video information with the fields ('length', 'fps', 'width', 'height', 'duration', 'size') |
|
Return the video label, e.g.. 'left', 'right' or 'body'. |
|
Return the video URL(s) for a given eid |
Classes
Provides a wrapper to stream a video from a password protected HTTP server using opencv |
- class VideoStreamer(url_vid)[source]
Bases:
object
Provides a wrapper to stream a video from a password protected HTTP server using opencv
- get_video_frame(video_path, frame_number)[source]
Obtain numpy array corresponding to a particular video frame in video_path
- Parameters:
video_path – local path to mp4 file
frame_number – video frame to be returned
- Returns:
numpy array corresponding to frame of interest. Dimensions are (w, h, 3)
- get_video_frames_preload(vid, frame_numbers=None, mask=Ellipsis, as_list=False, func=<function <lambda>>, quiet=False)[source]
Obtain numpy array corresponding to a particular video frame in video. Fetching and returning a list is about 33% faster but may be less memory controlled. NB: Any gain in speed will be lost if subsequently converted to array.
- Parameters:
vid – URL or local path to mp4 file or cv2.VideoCapture instance.
frame_numbers – video frames to be returned. If None, return all frames.
mask – a logical mask or slice to apply to frames
as_list – if true the frames are returned as a list, this is faster but may be less
memory efficient :param func: Function to be applied to each frame. Applied after masking if applicable. :param quiet: if true, suppress frame loading progress output. :return: numpy array corresponding to frame of interest, or list if as_list is True. Default dimensions are (n, w, h, 3) where n = len(frame_numbers)
- Example - Load first 1000 frames, keeping only the first colour channel:
frames = get_video_frames_preload(vid, range(1000), mask=np.s_[:, :, 0])
- get_video_meta(video_path, one=None)[source]
Return a bunch of video information with the fields (‘length’, ‘fps’, ‘width’, ‘height’, ‘duration’, ‘size’)
- Parameters:
video_path – A path to the video. May be a file path or URL.
one – An instance of ONE
- Returns:
A Bunch of video mata data
- url_from_eid(eid, label=None, one=None)[source]
Return the video URL(s) for a given eid
- Parameters:
eid – The session id
label – The video label (e.g. ‘body’) or a tuple thereof
one – An instance of ONE
- Returns:
The URL string if the label is a string, otherwise a dict of urls with labels as keys