Skip to content

Clip Makers

ClipMaker

Bases: Protocol[T_contra]

A protocol for clip makers.

make_clip

make_clip(asset: T_contra) -> Clip

Make a clip from the given asset.

Source code in src/mosaico/clip_makers/protocol.py
def make_clip(self, asset: T_contra) -> Clip:
    """
    Make a clip from the given asset.
    """
    ...

BaseClipMaker

Bases: BaseModel, Generic[T], ABC

Base class for clip makers.

duration class-attribute instance-attribute

duration: NonNegativeFloat | None = None

The duration of the clip in seconds.

video_resolution class-attribute instance-attribute

video_resolution: FrameSize | None = None

The resolution of the video.

effects class-attribute instance-attribute

effects: list[Effect] = Field(default_factory=list)

List of effects to apply to the clip.

storage_options class-attribute instance-attribute

storage_options: dict[str, Any] = Field(
    default_factory=dict
)

Storage options for the media.

make_clip

make_clip(asset: T) -> Clip

Make a clip from the given clip, duration and video resolution.

:asset: The asset to make the clip from. :duration: The duration of the clip in seconds. :video_resolution: The resolution of the video.

Returns:

Type Description
Clip

The clip.

Source code in src/mosaico/clip_makers/base.py
def make_clip(self, asset: T) -> Clip:
    """
    Make a clip from the given clip, duration and video resolution.

    :asset: The asset to make the clip from.
    :duration: The duration of the clip in seconds.
    :video_resolution: The resolution of the video.
    :return: The clip.
    """
    clip = self._make_clip(asset)

    for effect in self.effects:
        clip = effect.apply(clip)

    return clip

get_clip_maker_class

get_clip_maker_class(
    asset_type: AssetType,
) -> type[ClipMaker]

Get a clip maker class.

Parameters:

Name Type Description Default
asset_type AssetType

The assets type.

required

Returns:

Type Description
type[ClipMaker]

The clip maker class.

Raises:

Type Description
ValueError

If no clip maker is found for the given assets type and name.

Source code in src/mosaico/clip_makers/factory.py
def get_clip_maker_class(asset_type: AssetType) -> type[ClipMaker]:
    """
    Get a clip maker class.

    :param asset_type: The assets type.
    :return: The clip maker class.
    :raises ValueError: If no clip maker is found for the given assets type and name.
    """
    cm_mod_name = f"mosaico.clip_makers.{asset_type}"

    if not importlib.util.find_spec(cm_mod_name):
        raise InvalidAssetTypeError(asset_type)

    cm_mod = importlib.import_module(f"mosaico.clip_makers.{asset_type}")
    cm_class = getattr(cm_mod, asset_type.capitalize() + "ClipMaker")

    return cm_class

make_clip

make_clip(
    asset: Asset,
    duration: float | None = None,
    video_resolution: FrameSize | None = None,
    effects: Sequence[Effect] | None = None,
    storage_options: dict[str, Any] | None = None,
    **kwargs: Any
) -> Clip

Make a clip from the given asset.

Parameters:

Name Type Description Default
asset Asset

The asset.

required
duration float | None

The duration of the clip.

None
video_resolution FrameSize | None

The resolution of the video.

None

Returns:

Type Description
Clip

The clip.

Source code in src/mosaico/clip_makers/factory.py
def make_clip(
    asset: Asset,
    duration: float | None = None,
    video_resolution: FrameSize | None = None,
    effects: Sequence[Effect] | None = None,
    storage_options: dict[str, Any] | None = None,
    **kwargs: Any,
) -> Clip:
    """
    Make a clip from the given asset.

    :param asset: The asset.
    :param duration: The duration of the clip.
    :param video_resolution: The resolution of the video.
    :return: The clip.
    """
    clip_maker_cls = get_clip_maker_class(asset.type)
    clip_maker_cls = cast(type[BaseClipMaker], clip_maker_cls)
    clip_maker = clip_maker_cls(
        duration=duration,
        video_resolution=video_resolution,
        effects=list(effects) if effects is not None else [],
        storage_options=storage_options if storage_options is not None else {},
        **kwargs,
    )
    return clip_maker.make_clip(asset)