import_video

menpo.io.import_video(filepath, landmark_resolver=<function same_name_video>, normalise=True, importer_method='ffmpeg')[source]

Single video (and associated landmarks) importer.

If a video file is found at filepath, returns an LazyList wrapping all the frames of the video. 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).

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:
  • filepath (pathlib.Path or str) – A relative or absolute filepath to a video file.
  • 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 farmes 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.
Returns:

frames (LazyList) – An lazy list of Image or subclass thereof which wraps the frames of the video. This list can be treated as a normal list, but the frame is only read when the video is indexed or iterated.

Examples

>>> video = menpo.io.import_video('video.avi')
>>> # Lazily load the 100th frame without reading the entire video
>>> frame100 = video[100]