Skip to content

y5gfunc.source.wobbly.processors.crop

crop

Crop processor implementation.

Classes:

Name Description
CropProcessor

Crop processor implementation

Attributes:

Name Type Description
core

core module-attribute

core = core

CropProcessor

CropProcessor(early: bool = True)

Bases: BaseProcessor

Crop processor implementation

Initialize crop processor

Parameters:

Name Type Description Default

early

bool

Whether this is early crop (True) or final crop (False)

True

Methods:

Name Description
process

Process crop operation

Attributes:

Name Type Description
early
keys
Source code in y5gfunc/source/wobbly/processors/crop.py
def __init__(self, early: bool = True):
    """
    Initialize crop processor

    Args:
        early: Whether this is early crop (True) or final crop (False)
    """
    self.early = early
    self.keys = WobblyKeys()

early instance-attribute

early = early

keys instance-attribute

keys = WobblyKeys()

process

Process crop operation

Parameters:

Name Type Description Default

clip

VideoNode

Input video clip

required

project

ProjectData

Project data

required

frame_props

FramePropertyMap

Frame property mapping

required

frame_mapping

FrameMap

Frame number mapping

required

presets

PresetDict

Preset function dictionary

required

Returns:

Type Description
tuple[VideoNode, FramePropertyMap, FrameMap]

Processed clip, updated frame properties and frame mapping

Source code in y5gfunc/source/wobbly/processors/crop.py
def process(
    self,
    clip: vs.VideoNode,
    project: ProjectData,
    frame_props: FramePropertyMap,
    frame_mapping: FrameMap,
    presets: PresetDict,
) -> tuple[vs.VideoNode, FramePropertyMap, FrameMap]:
    """
    Process crop operation

    Args:
        clip: Input video clip
        project: Project data
        frame_props: Frame property mapping
        frame_mapping: Frame number mapping
        presets: Preset function dictionary

    Returns:
        Processed clip, updated frame properties and frame mapping
    """
    stage_name = "early_crop" if self.early else "final_crop"

    with safe_processing(stage_name):
        Keys = self.keys
        crop_info = project.get(Keys.project.crop, {})

        # Check if crop is enabled and matches the requested phase (early or final)
        crop_enabled = crop_info.get(Keys.crop.enabled, False)
        crop_is_early = crop_info.get(Keys.crop.early, False)

        if crop_enabled and crop_is_early == self.early:
            # Get crop values
            left = crop_info.get(Keys.crop.left, 0)
            top = crop_info.get(Keys.crop.top, 0)
            right = crop_info.get(Keys.crop.right, 0)
            bottom = crop_info.get(Keys.crop.bottom, 0)

            # Create properties to record
            crop_props = {
                "WobblyCropEarly": self.early,
                "WobblyCropLeft": left,
                "WobblyCropTop": top,
                "WobblyCropRight": right,
                "WobblyCropBottom": bottom,
            }

            # Update all frame properties
            for n in frame_props:
                frame_props[n].update(crop_props)  # type: ignore[index]

            # Apply crop
            clip = core.std.CropRel(
                clip=clip, left=left, top=top, right=right, bottom=bottom
            )

    return clip, frame_props, frame_mapping