import_video

menpo.io.import_video(filepath, landmark_resolver=<function same_name_video>, normalize=None, normalise=None, importer_method='ffmpeg', exact_frame_count=True)[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 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:
  • filepath (pathlib.Path or str) – A relative or absolute filepath to a video file.
  • 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 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.
  • 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.
  • exact_frame_count (bool, optional) – If True, the import fails if ffprobe is not available (reading from ffmpeg’s output returns inexact frame count)
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]