Add S-expression based video effects pipeline with modular effect definitions, constructs, and recipe files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
1.4 KiB
Python
65 lines
1.4 KiB
Python
# /// script
|
|
# requires-python = ">=3.10"
|
|
# dependencies = ["numpy"]
|
|
# ///
|
|
"""
|
|
@effect flip
|
|
@version 1.0.0
|
|
@author artdag
|
|
|
|
@description
|
|
Flips the frame horizontally and/or vertically.
|
|
Can be used for mirror effects or beat-triggered flips.
|
|
|
|
@param horizontal bool
|
|
@default false
|
|
Flip horizontally (left-right mirror).
|
|
|
|
@param vertical bool
|
|
@default false
|
|
Flip vertically (top-bottom mirror).
|
|
|
|
@example
|
|
(effect flip :horizontal true)
|
|
|
|
@example
|
|
(effect flip :vertical true)
|
|
|
|
@example
|
|
(effect flip :horizontal true :vertical true) ; 180 degree rotation
|
|
"""
|
|
|
|
import numpy as np
|
|
|
|
|
|
def process_frame(frame: np.ndarray, params: dict, state: dict) -> tuple:
|
|
"""
|
|
Flip a video frame horizontally and/or vertically.
|
|
|
|
Args:
|
|
frame: Input frame as numpy array (H, W, 3) RGB uint8
|
|
params: Effect parameters
|
|
- horizontal: flip left-right (default False)
|
|
- vertical: flip top-bottom (default False)
|
|
state: Persistent state dict (unused)
|
|
|
|
Returns:
|
|
Tuple of (processed_frame, new_state)
|
|
"""
|
|
horizontal = params.get("horizontal", False)
|
|
vertical = params.get("vertical", False)
|
|
|
|
result = frame
|
|
|
|
if horizontal:
|
|
result = np.flip(result, axis=1)
|
|
|
|
if vertical:
|
|
result = np.flip(result, axis=0)
|
|
|
|
# Ensure contiguous array after flips
|
|
if horizontal or vertical:
|
|
result = np.ascontiguousarray(result)
|
|
|
|
return result, state
|