Frames

class tools.alignments.media.Frames(folder: str, count: int | None = None)

Bases: MediaLoader

Object to hold the frames that are to be checked against

Attributes Summary

count

Number of faces or frames

is_video

Whether source is a video or not

Methods Summary

check_input_folder()

Ensure that the frames or faces folder exists and is valid.

load_image(filename)

Load an image

load_items()

Load the frame info into dictionary

load_video_frame(filename)

Load a requested frame from video

process_folder()

Iterate through the frames folder pulling the base filename

process_frames()

Process exported Frames

process_video()

Dummy in frames for video

save_image(output_folder, filename, image[, ...])

Save an image

sorted_items()

Return the items sorted by filename

stream([skip_list])

Load the images in folder in the order they are received from lib.image.ImagesLoader in a background thread.

valid_extension(filename)

Check whether passed in file has a valid extension

Attributes Documentation

Parameters:
  • folder (str)

  • count (int | None)

count

Number of faces or frames

is_video

Whether source is a video or not

Methods Documentation

check_input_folder() VideoCapture | None

Ensure that the frames or faces folder exists and is valid. If frames folder contains a video file return cv2 reader object

Return type:

Object for reading a video stream

load_image(filename: str) np.ndarray

Load an image

Parameters:

filename (str) – The filename of the image to load

Return type:

The loaded image

load_items() dict[str, tuple[str, str]]

Load the frame info into dictionary

Return type:

Fullname as key, tuple of frame name and extension as value

load_video_frame(filename: str) np.ndarray

Load a requested frame from video

Parameters:

filename (str) – The frame name to load

Return type:

The loaded image

process_folder() Generator[dict[str, str], None, None]

Iterate through the frames folder pulling the base filename

Yields:

The full frame name, the filename and the file extension of the frame

Return type:

Generator[dict[str, str], None, None]

process_frames() Generator[dict[str, str], None, None]

Process exported Frames

Yields:

The full frame name, the filename and the file extension of the frame

Return type:

Generator[dict[str, str], None, None]

process_video() Generator[dict[str, str], None, None]

Dummy in frames for video

Yields:

The full frame name, the filename and the file extension of the frame

Return type:

Generator[dict[str, str], None, None]

static save_image(output_folder: str, filename: str, image: np.ndarray, metadata: PNGHeader | None = None) None

Save an image

Parameters:
  • filename (str) – The filename of the image to save

  • image (np.ndarray) – The image to save

  • metadata (PNGHeader | None) – Any faceswap metadata that should be saved

  • output_folder (str)

Return type:

None

sorted_items() list[dict[str, str]]

Return the items sorted by filename

Return type:

The sorted list of frame information

stream(skip_list: list[int] | None = None) Generator[tuple[str, np.ndarray], None, None]

Load the images in folder in the order they are received from lib.image.ImagesLoader in a background thread.

Parameters:

skip_list (list[int] | None) – A list of frame indices that should not be loaded. Pass None if all images should be loaded. Default: None

Yields:
  • filename – The filename of the image that is being returned

  • image – The image that has been loaded from disk

Return type:

Generator[tuple[str, np.ndarray], None, None]

static valid_extension(filename) bool

Check whether passed in file has a valid extension

Return type:

bool

load_items() dict[str, tuple[str, str]]

Load the frame info into dictionary

Return type:

Fullname as key, tuple of frame name and extension as value

process_folder() Generator[dict[str, str], None, None]

Iterate through the frames folder pulling the base filename

Yields:

The full frame name, the filename and the file extension of the frame

Return type:

Generator[dict[str, str], None, None]

process_frames() Generator[dict[str, str], None, None]

Process exported Frames

Yields:

The full frame name, the filename and the file extension of the frame

Return type:

Generator[dict[str, str], None, None]

process_video() Generator[dict[str, str], None, None]

Dummy in frames for video

Yields:

The full frame name, the filename and the file extension of the frame

Return type:

Generator[dict[str, str], None, None]

sorted_items() list[dict[str, str]]

Return the items sorted by filename

Return type:

The sorted list of frame information