MediaLoader
- class tools.alignments.media.MediaLoader(folder: str, count: int | None = None)
Bases:
objectClass to load images.
- Parameters:
folder (str) – The folder of images or video file to load images from
count (int | None) – If the total frame count is known it can be passed in here which will skip analyzing a video file. If the count is not passed in, it will be calculated. Default:
None
Attributes Summary
Number of faces or frames
Whether source is a video or not
Methods Summary
Ensure that the frames or faces folder exists and is valid.
load_image(filename)Load an image
Override for specific item loading
load_video_frame(filename)Load a requested frame from video
Override for specific folder processing
save_image(output_folder, filename, image[, ...])Save an image
Override for specific folder processing
stream([skip_list])Load the images in
folderin the order they are received fromlib.image.ImagesLoaderin a background thread.valid_extension(filename)Check whether passed in file has a valid extension
Attributes Documentation
- 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, list[int]] | dict[str, tuple[str, str]]
Override for specific item loading
- Return type:
dict[str, list[int]] | dict[str, tuple[str, str]]
- 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] | Generator[tuple[str, PNGHeader], None, None]
Override for specific folder processing
- Return type:
Generator[dict[str, str], None, None] | Generator[tuple[str, PNGHeader], 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]] | list[tuple[str, PNGHeader]]
Override for specific folder processing
- Return type:
list[dict[str, str]] | list[tuple[str, PNGHeader]]
- stream(skip_list: list[int] | None = None) Generator[tuple[str, np.ndarray], None, None]
Load the images in
folderin the order they are received fromlib.image.ImagesLoaderin a background thread.- Parameters:
skip_list (list[int] | None) – A list of frame indices that should not be loaded. Pass
Noneif 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
- 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
- property count: int
Number of faces or frames
- property is_video: bool
Whether source is a video or not
- 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, list[int]] | dict[str, tuple[str, str]]
Override for specific item loading
- Return type:
dict[str, list[int]] | dict[str, tuple[str, str]]
- 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] | Generator[tuple[str, PNGHeader], None, None]
Override for specific folder processing
- Return type:
Generator[dict[str, str], None, None] | Generator[tuple[str, PNGHeader], 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]] | list[tuple[str, PNGHeader]]
Override for specific folder processing
- Return type:
list[dict[str, str]] | list[tuple[str, PNGHeader]]
- stream(skip_list: list[int] | None = None) Generator[tuple[str, np.ndarray], None, None]
Load the images in
folderin the order they are received fromlib.image.ImagesLoaderin a background thread.- Parameters:
skip_list (list[int] | None) – A list of frame indices that should not be loaded. Pass
Noneif 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