import_videos

menpo.io.import_videos(pattern, max_videos=None, shuffle=False, landmark_resolver=<function same_name_video>, normalize=None, normalise=None, importer_method='ffmpeg', exact_frame_count=True, 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 ffmpeg to perform the importing. In order to recover accurate frame counts from videos it is necessary to use ffprobe to count the frames. This involves reading the entire video in to memory which may cause a delay in loading despite the lazy nature of the video loading within Menpo. If ffprobe cannot be found, and exact_frame_count is False, Menpo falls back to ffmpeg itself which is not accurate and the user should proceed at their 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 or None, 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}’. If None, landmark importing will be skipped.
  • normalize (bool, optional) – If True, normalize 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.
  • normalise (bool, optional) – Deprecated version of normalize. Please use the normalize arg.
  • 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.
  • exact_frame_count (bool, optional) – If True, the import fails if ffmprobe is not available (reading from ffmpeg’s output returns inexact frame count)
  • 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)