ibllib.io.video

Functions for fetching video frames, meta data and file locations

Functions

assert_valid_label

Raises a value error is the provided label is not supported.

get_video_frame

Obtain numpy array corresponding to a particular video frame in video_path :param video_path: local path to mp4 file :param frame_number: video frame to be returned :return: numpy array corresponding to frame of interest.

get_video_frames_preload

Obtain numpy array corresponding to a particular video frame in video.

get_video_meta

Return a bunch of video information with the fields (‘length’, ‘fps’, ‘width’, ‘height’, ‘duration’, ‘size’) :param video_path: A path to the video.

label_from_path

Return the video label, i.e. ‘left’, ‘right’ or ‘body’ :param video_name: A file path, URL or file name for the video :return: The string label or None if the video doesn’t match.

url_from_eid

Return the video URL(s) for a given eid

get_video_frame(video_path, frame_number)[source]

Obtain numpy array corresponding to a particular video frame in video_path :param video_path: local path to mp4 file :param frame_number: video frame to be returned :return: 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. :param vid: URL or local path to mp4 file or cv2.VideoCapture instance. :param frame_numbers: video frames to be returned. If None, return all frames. :param mask: a logical mask or slice to apply to frames :param 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’) :param video_path: A path to the video. May be a file path or URL. :param one: An instance of ONE :return: 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

label_from_path(video_name)[source]

Return the video label, i.e. ‘left’, ‘right’ or ‘body’ :param video_name: A file path, URL or file name for the video :return: The string label or None if the video doesn’t match

assert_valid_label(label)[source]

Raises a value error is the provided label is not supported. :param label: A video label to verify :return: the label in lowercase