lib.video Module
Utilities for working with videos
- lib.video.VIDEO_EXTENSIONS = ['.avi', '.flv', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', '.webm', '.wmv', '.ts', '.vob']
List of lowercase valid Video extensions with preceding period
- class lib.video.VideoInfo(video_file: str, fast_count: bool = True, stream_index: int = 0, pts: list[int] | None = None, keyframes: list[int] | None = None)
Collects and stores information about video files
- Parameters:
video_file (str) – Full path to a video file
fast_count (bool) – Whether to obtain the count of frames quickly, but inaccurately or slowly but accurately. If pts and keyframes are provided then the count will be derived from the provided pts file. Default:
Truestream_index (int) – The stream index to select from the video file. Default: 0
pts (list[int] | None) – The Presentation Timestamps if available or
Noneto retrieve from the video. Default:Nonekeyframes (list[int] | None) – The keyframe frame indices if available or
Noneto retrieve from the video. Default:None
- property count: int
The number of frames in the video
- property duration: int
The duration of the video file in seconds
- property keyframes: npt.NDArray[np.int64]
The frame index of each key frame in the video
- property keyframes_count: int
The number of keyframes that exist in the video
- property pts: npt.NDArray[np.int64]
The Presentation Time Stamp for each frame in the video
- class lib.video.VideoMux(source_video: str, destination_video: str, codec: Literal['libx264', 'libx265'], codec_parameters: dict[str, str], mux_audio: bool = True)
A basic muxer for muxing converted faceswap frames to a video file using the original video as a reference
- Parameters:
source_video (str) – The path to the source video to use as a reference for Audio and FPS
destination_video (str) – The full path to save the final video to
codec (T.Literal['libx264', 'libx265']) – The codec to use to encode the video
codec_parameters (dict[str, str]) – The options to use for the codec
mux_audio (bool) –
Trueto mux order from the source video to the output
- encode(image: npt.NDArray[np.uint8] | None) None
Encode a frame to the video
- Parameters:
image (npt.NDArray[np.uint8] | None) – The 3 channel BGR UINT8 image to encode to the video or
Noneto finalize the video- Return type:
None
- class lib.video.VideoReader(video_file: str, fast_count: bool = True, stream_index: int = 0, pts: list[int] | None = None, keyframes: list[int] | None = None)
A wrapper around pyAV that allows obtaining frames by frame index and iterating video files
- Parameters:
video_file (str) – Full path to a video file
fast_count (bool) – Whether to obtain the count of frames quickly, but inaccurately or slowly but accurately. If pts and keyframes are provided then the count will be derived from the provided pts file. Default:
Truestream_index (int) – The stream index to select from the video file. Default: 0
pts (list[int] | None) – The Presentation Timestamps if available or
Noneto retrieve from the video. Default:Nonekeyframes (list[int] | None) – The keyframe frame indices if available or
Noneto retrieve from the video. Default:None
- __next__() VideoFrame
Obtain the next video frame object
- Return type:
The next available video frame object
- close() None
Shut down the AV Container object
- Return type:
None
- get(index: int) VideoFrame
Obtain the video frame at the given frame index
- Parameters:
index (int) – The index number of the frame to retrieve
- Return type:
The pyAV frame object for the given index
- lib.video.check_for_video(input_location: str) bool
Check whether the given input is a video file or a folder
- Parameters:
input_location (str) – Full path to an input file
- Returns:
bool
- Return type:
‘True’ if input is a video ‘False’ if it is a folder.
- Raises:
FaceswapError – If the given location is a file and does not have a valid video extension.
- lib.video.count_frames(filename, fast=False)
Count the number of frames in a video file
There is no guaranteed accurate way to get a count of video frames without iterating through a video and decoding every frame.
count_frames()can return an accurate count (albeit fairly slowly) or a possibly less accurate count, depending on thefastparameter. A progress bar is displayed.- Parameters:
filename (str) – Full path to the video to return the frame count from.
fast (bool, optional) – Whether to count the frames without decoding them. This is significantly faster but accuracy is not guaranteed. Default:
False.
- Returns:
The number of frames in the given video file.
- Return type:
int
Example
>>> filename = "/path/to/video.mp4" >>> frame_count = count_frames(filename)
- lib.video.validate_video_file(file_path: str) str
Validates that a given file exists and is a valid video format
- Parameters:
file_path (str) – The full path to the video file to validate
- Return type:
The full expanded video file path
- Raises:
FaceswapError – If the given video file is not valid
Functions
|
Return the ceiling of x as an Integral. |
|
Check whether the given input is a video file or a folder |
|
Convert time in hours, minutes, and seconds to seconds. |
|
Count the number of frames in a video file |
|
Return a list of all public objects within the given module |
|
Parse a locals dict from a class and return in a format suitable for logging :param locals_dict: A locals() dictionary from a newly initialized class |
|
Validates that a given file exists and is a valid video format |
Classes
|
Faceswap Error for handling specific errors with useful information. |
|
This class implements rational numbers. |
|
Collects and stores information about video files |
|
A basic muxer for muxing converted faceswap frames to a video file using the original video as a reference |
|
A wrapper around pyAV that allows obtaining frames by frame index and iterating video files |
|
A list-like sequence optimized for data accesses near its endpoints. |
|
Decorate an iterable object, returning an iterator which acts exactly like the original iterable, but prints a dynamically updating progressbar every time a value is requested. |
Variables
List of lowercase valid Video extensions with preceding period |
|
A standard |
Class Inheritance Diagram
