morphic.converter

File format conversion engine for images (Pillow) and videos (ffmpeg).

Constants

Conversion-specific constants: which formats can be converted to which.

Uses the shared extension sets from morphic.shared.constants and builds canonical conversion mapping tables.

Converter

File conversion engine – Pillow for images, ffmpeg for videos.

morphic.converter.converter.convert_image(source, target_ext, output_dir=None)[source]

Convert an image file using Pillow.

Parameters:
  • source (str) – Path to the source image.

  • target_ext (str) – Target extension (with or without leading dot).

  • output_dir (str, optional) – Directory for the output file. Defaults to the source directory.

Returns:

Path of the converted file.

Return type:

str

morphic.converter.converter.convert_video(source, target_ext, output_dir=None, av1_crf=None)[source]

Convert a video file using ffmpeg.

Parameters:
  • source (str) – Path to the source video.

  • target_ext (str) – Target extension (with or without leading dot).

  • output_dir (str, optional) – Directory for the output file. Defaults to the source directory.

  • av1_crf (int | None)

Returns:

Path of the converted file.

Return type:

str

Raises:

RuntimeError – If ffmpeg is not installed or conversion fails.

morphic.converter.converter.convert_file(source, target_ext, output_dir=None, av1_crf=None)[source]

High-level converter – routes to image or video handler.

Parameters:
  • source (str)

  • target_ext (str)

  • output_dir (str | None)

  • av1_crf (int | None)

Return type:

str

Scanner

Folder scanner – walks directories and inventories image/video files for the format converter.

morphic.converter.scanner.get_compatible_targets(source_path)[source]

Return list of extensions the source can be converted to.

Parameters:

source_path (str)

Return type:

list[str]

morphic.converter.scanner.scan_folder(folder, include_subfolders=True, filter_type='both')[source]

Walk folder and return a summary + full file list.

Parameters:
  • folder (str) – Absolute path to the directory to scan.

  • include_subfolders (bool) – Whether to recurse into subdirectories.

  • filter_type (str) – One of "images", "videos", "both".

Returns:

{"folder", "summary", "files", "total"}

Return type:

dict