Rendering#
The rendering module is responsible for generating video and GIF outputs from frame sequences.
Rendering#
- class framecat.rendering.InputType[source]#
Bases:
object
Class to represent the different input file types supported.
- TAR#
Represents a TAR file type.
- Type:
str
- MP4#
Represents an MP4 file type.
- Type:
str
- GIF#
- Represents a GIF file type.
- Type:
str
- class framecat.rendering.RenderingParameters(overwrite: bool = True, rename_input_file: bool = True, gif_framerate: int = 30, start_time: float = 0.0, duration: float = 1000.0, width: int = -1, height: int = -1, hq_colors: bool = False, generate_lossy: bool = False, video_framerate: int = 60, video_conversion_args: tuple = ())[source]#
Bases:
object
Class to hold parameters for rendering operations.
- Parameters:
overwrite (bool) –
rename_input_file (bool) –
gif_framerate (int) –
start_time (float) –
duration (float) –
width (int) –
height (int) –
hq_colors (bool) –
generate_lossy (bool) –
video_framerate (int) –
video_conversion_args (tuple) –
- overwrite#
Whether to overwrite existing files. Defaults to True.
- Type:
bool
- rename_input_file#
Whether to rename the input file. Defaults to True.
- Type:
bool
- gif_framerate#
Frame rate for the GIF output. Defaults to 30.
- Type:
int
- start_time#
Start time for video conversion in seconds. Defaults to 0.0.
- Type:
float
- duration#
Duration for video conversion in milliseconds. Defaults to 1000.0.
- Type:
float
- width#
Width of the output GIF. Defaults to -1 (no resizing).
- Type:
int
- height#
Height of the output GIF. Defaults to -1 (no resizing).
- Type:
int
- hq_colors#
Whether to use high-quality colors for GIF. Defaults to False.
- Type:
bool
- generate_lossy#
Whether to generate a lossy GIF. Defaults to False.
- Type:
bool
- video_framerate#
Frame rate for the video output. Defaults to 60.
- Type:
int
- video_conversion_args#
- Additional arguments for video conversion. Defaults to an empty tuple.
- Type:
tuple
- framecat.rendering.compress_gif(file_path: str, output_path: str | None = None, overwrite: bool = False) str [source]#
Compresses a GIF file to reduce its size with lossy optimization.
- Parameters:
file_path (str) – Path to the input GIF file.
output_path (str, optional) – Path to save the compressed GIF. If None, defaults to
<input_file>_lossy.gif
.overwrite (bool, optional) – Whether to overwrite the output file if it exists. Defaults to False.
- Returns:
str – The path to the saved compressed GIF.
- Raises:
FileNotFoundError – If the input file does not exist.
- Return type:
str
- framecat.rendering.convert_frames_to_video(tar_file_path: str, output_path: str = 'output.mp4', framerate: int = 60, overwrite: bool = False, conversion_args: tuple = ()) str [source]#
Converts frames extracted from a TAR file into a video.
You can pass arguments for the video conversion, for example,
conversion_args=("-pix_fmt", "yuv420p")
to create videos playable in Windows.- Parameters:
tar_file_path (str) – Path to the input TAR file containing frames.
output_path (str, optional) – Path to save the output video. Defaults to “output.mp4”.
framerate (int, optional) – Frame rate for the output video. Defaults to 60.
overwrite (bool, optional) – Whether to overwrite the output file if it exists. Defaults to False.
conversion_args (tuple, optional) – Additional arguments for video conversion. Defaults to an empty tuple.
- Returns:
str – The path to the saved video.
- Raises:
FileNotFoundError – If the input TAR file does not exist.
subprocess.CalledProcessError – If the FFMPEG command fails.
- Return type:
str
- framecat.rendering.convert_video_to_gif(video_file_path: str, output_path: str = 'output.gif', framerate: int = 30, start_time: float = 0.0, duration: float = 1000.0, overwrite: bool = False, width: int = -1, height: int = -1, hq_colors: bool = False) str [source]#
Converts a video file to a GIF.
- Parameters:
video_file_path (str) – Path to the input video file.
output_path (str, optional) – Path to save the output GIF. Defaults to “output.gif”.
framerate (int, optional) – Frame rate for the GIF. Defaults to 30.
start_time (float, optional) – Start time for the conversion in seconds. Defaults to 0.0.
duration (float, optional) – Duration of the output GIF in seconds. Defaults to 1000.0.
overwrite (bool, optional) – Whether to overwrite the output file if it exists. Defaults to False.
width (int, optional) – Width of the output GIF. Defaults to -1 (no resizing).
height (int, optional) – Height of the output GIF. Defaults to -1 (no resizing).
hq_colors (bool, optional) – Whether to use high-quality colors for the GIF. Defaults to False.
- Returns:
str – The path to the saved GIF.
- Raises:
FileNotFoundError – If the input video file does not exist.
subprocess.CalledProcessError – If the FFMPEG command fails.
- Return type:
str
- framecat.rendering.get_input_type(file_path: str) InputType [source]#
Determines the input type based on the file extension.
- Parameters:
file_path (str) – Path to the input file.
- Returns:
InputType – The identified input type (TAR, MP4, or GIF).
- Raises:
ValueError – If the file extension is not recognized.
- Return type:
- framecat.rendering.get_latest_files(folder_path: str, num_files: int = 1, extension: str = 'tar') list [source]#
Retrieves the latest modified files with a specified extension from a given folder.
- Parameters:
folder_path (str) – Path to the folder to search for files.
num_files (int, optional) – Number of most recent files to return. Defaults to 1.
extension (str, optional) – File extension to filter by. Defaults to “tar”.
- Returns:
list – A list of paths to the latest modified files with the specified extension.
- Raises:
ValueError – If the provided folder path does not exist.
- Return type:
list
- framecat.rendering.rename_file(file_path: str, new_file_name: str) str [source]#
Renames a file to a new specified name.
- Parameters:
file_path (str) – Path to the file to be renamed.
new_file_name (str) – New name for the file (including extension).
- Returns:
str – The path to the renamed file.
- Return type:
str
- framecat.rendering.render_file(file_path: str, output_name: str, output_folder: str | None = None, params: ~framecat.rendering.RenderingParameters = <framecat.rendering.RenderingParameters object>) None [source]#
Renders a video or GIF from the specified file.
- Parameters:
file_path (str) – Path to the input file (TAR or MP4).
output_name (str) – Name for the output files (without extension).
output_folder (str, optional) – Directory for saving output files. Defaults to ~/Videos/framecat.
params (RenderingParameters, optional) – Parameters for rendering options.
- Returns:
None – This function does not return a value.
- Return type:
None