module documentation

Video frame views.

Copyright 2017-2025, Voxel51, Inc.

Class FramesView A fiftyone.core.view.DatasetView of frames from a video fiftyone.core.dataset.Dataset.
Class FrameView A frame in a FramesView.
Function make_frames_dataset Creates a dataset that contains one sample per frame in the video collection.
Variable fouv Undocumented
Variable logger Undocumented
Function _get_non_existent_frame_numbers Undocumented
Function _init_frames Undocumented
Function _insert_docs Undocumented
Function _make_pretty_summary Undocumented
Function _parse_video_frames Undocumented
def make_frames_dataset(sample_collection, sample_frames=False, fps=None, max_fps=None, size=None, min_size=None, max_size=None, sparse=False, output_dir=None, rel_dir=None, frames_patt=None, force_sample=False, skip_failures=True, verbose=False, name=None, persistent=False, _generated=False): (source)

Creates a dataset that contains one sample per frame in the video collection.

The returned dataset will contain all frame-level fields and the tags of each video as sample-level fields, as well as a sample_id field that records the IDs of the parent sample for each frame.

By default, sample_frames is False and this method assumes that the frames of the input collection have filepath fields populated pointing to each frame image. Any frames without a filepath populated will be omitted from the frames dataset.

When sample_frames is True, this method samples each video in the collection into a directory of per-frame images and stores the filepaths in the filepath frame field of the source dataset. By default, each folder of images is written using the same basename as the input video. For example, if frames_patt = "%%06d.jpg", then videos with the following paths:

/path/to/video1.mp4
/path/to/video2.mp4
...

would be sampled as follows:

/path/to/video1/
    000001.jpg
    000002.jpg
    ...
/path/to/video2/
    000001.jpg
    000002.jpg
    ...

However, you can use the optional output_dir and rel_dir parameters to customize the location and shape of the sampled frame folders. For example, if output_dir = "/tmp" and rel_dir = "/path/to", then videos with the following paths:

/path/to/folderA/video1.mp4
/path/to/folderA/video2.mp4
/path/to/folderB/video3.mp4
...

would be sampled as follows:

/tmp/folderA/
    video1/
        000001.jpg
        000002.jpg
        ...
    video2/
        000001.jpg
        000002.jpg
        ...
/tmp/folderB/
    video3/
        000001.jpg
        000002.jpg
        ...

By default, samples will be generated for every video frame at full resolution, but this method provides a variety of parameters that can be used to customize the sampling behavior.

Note

If this method is run multiple times with sample_frames set to True, existing frames will not be resampled unless you set force_sample to True.

Parameters
sample_collectiona fiftyone.core.collections.SampleCollection
sample_frames:Falsewhether to assume that the frame images have already been sampled at locations stored in the filepath field of each frame (False), or whether to sample the video frames now according to the specified parameters (True)
fps:Nonean optional frame rate at which to sample each video's frames
max_fps:Nonean optional maximum frame rate at which to sample. Videos with frame rate exceeding this value are downsampled
size:Nonean optional (width, height) at which to sample frames. A dimension can be -1, in which case the aspect ratio is preserved. Only applicable when sample_frames=True
min_size:Nonean optional minimum (width, height) for each frame. A dimension can be -1 if no constraint should be applied. The frames are resized (aspect-preserving) if necessary to meet this constraint. Only applicable when sample_frames=True
max_size:Nonean optional maximum (width, height) for each frame. A dimension can be -1 if no constraint should be applied. The frames are resized (aspect-preserving) if necessary to meet this constraint. Only applicable when sample_frames=True
sparse:Falsewhether to only sample frame images for frame numbers for which fiftyone.core.frame.Frame instances exist in the input collection. This parameter has no effect when sample_frames==False since frames must always exist in order to have filepath information used
output_dir:Nonean optional output directory in which to write the sampled frames. By default, the frames are written in folders with the same basename of each video
rel_dir:Nonea relative directory to remove from the filepath of each video, if possible. The path is converted to an absolute path (if necessary) via fiftyone.core.storage.normalize_path. This argument can be used in conjunction with output_dir to cause the sampled frames to be written in a nested directory structure within output_dir matching the shape of the input video's folder structure
frames_patt:Nonea pattern specifying the filename/format to use to write or check or existing sampled frames, e.g., "%%06d.jpg". The default value is fiftyone.config.default_sequence_idx + fiftyone.config.default_image_ext
force_sample:Falsewhether to resample videos whose sampled frames already exist. Only applicable when sample_frames=True
skip_failures:Truewhether to gracefully continue without raising an error if a video cannot be sampled
verbose:Falsewhether to log information about the frames that will be sampled, if any
name:Nonea name for the dataset
persistent:Falsewhether the dataset should persist in the database after the session terminates
_generatedUndocumented
Returns
a fiftyone.core.dataset.Dataset

Undocumented

Undocumented

def _get_non_existent_frame_numbers(images_patt, frame_numbers): (source)

Undocumented

def _init_frames(dataset, src_collection, sample_frames, output_dir, rel_dir, frames_patt, fps, max_fps, sparse, force_sample, verbose): (source)

Undocumented

def _insert_docs(docs, src_docs, src_inds, dataset, src_dataset): (source)

Undocumented

def _make_pretty_summary(dataset): (source)

Undocumented

def _parse_video_frames(video_path, sample_frames, images_patt, support, total_frame_count, frame_rate, frame_ids_map, force_sample, sparse, fps, max_fps, verbose): (source)

Undocumented