import_videos

menpo.io.import_videos(pattern, max_videos=None, shuffle=False, landmark_resolver=<function same_name_video>, normalise=True, importer_method='ffmpeg', as_generator=False, verbose=False)[source]

Multiple video (and associated landmarks) importer.

For each video found yields a LazyList. By default, landmark files sharing the same filename stem will be imported and attached with a group name based on the extension of the landmark file appended with the frame number, although this behavior can be customised (see landmark_resolver).

Note that this is a function returns a LazyList. Therefore, the function will return immediately and indexing into the returned list will load an image at run time. If all images should be loaded, then simply wrap the returned LazyList in a Python list.

Warning

This method currently uses imageio to perform the importing in conjunction with the ffmpeg plugin. As of this release, and the release of imageio at the time of writing (1.5.0), the per-frame computation is not very accurate. This may cause errors when importing frames that do not actually map to valid timestamps within the image. Therefore, use this method at your own risk.

Parameters:
  • pattern (str) – A glob path pattern to search for videos. Every video found to match the glob will be imported one by one. See video_paths for more details of what videos will be found.
  • max_videos (positive int, optional) – If not None, only import the first max_videos found. Else, import all.
  • shuffle (bool, optional) – If True, the order of the returned videos will be randomised. If False, the order of the returned videos will be alphanumerically ordered.
  • landmark_resolver (function, optional) – This function will be used to find landmarks for the video. The function should take two arguments (the path to the video and the frame number) and return a dictionary of the form {'group_name': 'landmark_filepath'} Default finds landmarks with the same name as the video file, appended with ‘_{frame_number}’.
  • normalise (bool, optional) – If True, normalise the frame pixels between 0 and 1 and convert to floating point. If False, the native datatype of the image will be maintained (commonly uint8). Note that in general Menpo assumes Image instances contain floating point data - if you disable this flag you will have to manually convert the frames you import to floating point before doing most Menpo operations. This however can be useful to save on memory usage if you only wish to view or crop the frames.
  • importer_method ({'ffmpeg'}, optional) – A string representing the type of importer to use, by default ffmpeg is used.
  • as_generator (bool, optional) – If True, the function returns a generator and assets will be yielded one after another when the generator is iterated over.
  • verbose (bool, optional) – If True progress of the importing will be dynamically reported with a progress bar.
Returns:

lazy_list (LazyList or generator of LazyList) – A LazyList or generator yielding LazyList instances that wrap the video object.

Raises:

ValueError – If no videos are found at the provided glob.

Examples

Import videos at and rescale every frame of each video:

>>> videos = []
>>> for video in menpo.io.import_videos('./set_of_videos/*'):
>>>    frames = []
>>>    for frame in video:
>>>        # rescale to a sensible size as we go
>>>        frames.append(frame.rescale(0.2))
>>>    videos.append(frames)