Skip to content

y5gfunc.source.wobbly.processors.trim

trim

Trim processor implementation.

Classes:

Name Description
TrimProcessor

Trim processor implementation

Attributes:

Name Type Description
core

core module-attribute

core = core

TrimProcessor

TrimProcessor()

Bases: BaseProcessor

Trim processor implementation

Initialize trim processor

Methods:

Name Description
process

Process trim operation

Attributes:

Name Type Description
keys
Source code in y5gfunc/source/wobbly/processors/trim.py
def __init__(self):
    """Initialize trim processor"""
    self.keys = WobblyKeys()

keys instance-attribute

keys = WobblyKeys()

process

Process trim 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/trim.py
def process(
    self,
    clip: vs.VideoNode,
    project: ProjectData,
    frame_props: FramePropertyMap,
    frame_mapping: FrameMap,
    presets: PresetDict,
) -> tuple[vs.VideoNode, FramePropertyMap, FrameMap]:
    """
    Process trim 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
    """
    with safe_processing("trim_processing"):
        Keys = self.keys
        trim_list = project.get(Keys.project.trim, [])

        if not trim_list:
            return clip, frame_props, frame_mapping

        segments = []
        new_frame_props: dict[int, dict[str, Any]] = (
            {}
        )  # Store new frame property map
        new_frame_idx = 0

        for trim in trim_list:
            first, last = trim
            if first <= last and first < clip.num_frames and last < clip.num_frames:
                # Create segment
                segment = clip[first : last + 1]

                # Update frame properties and mapping
                for i in range(first, last + 1):
                    # Update trim info
                    if i in frame_props:
                        props = frame_props[i].copy()
                        props.update(
                            {"WobblyTrimStart": first, "WobblyTrimEnd": last}
                        )
                        new_frame_props[new_frame_idx] = props  # type: ignore[index]
                        # Update mapping
                        frame_mapping[new_frame_idx] = i
                        new_frame_idx += 1

                segments.append(segment)

        if segments:
            clip = core.std.Splice(clips=segments)
            frame_props = new_frame_props  # type: ignore[assignment] # Update frame property map

    return clip, frame_props, frame_mapping