$ cat node-template.py

V

Video Scene Detect

// Detects scene and shot boundaries in video. Supports detection of hard cuts and gradual transitions. Returns timecodes, durations, and keyframe timestamps.

Process
#video#scene-detection#shot-detection#pyscenedetect
template.py
1import os2import sys3import json4import traceback56from gais import Gais78INPUT_DIR = "/data/input"91011def main():12    try:13        input_json = sys.stdin.read()14        execution_input = json.loads(input_json)15        inputs = execution_input.get("inputs", {})1617        video = inputs.get("video", "")18        detector = inputs.get("detector", "content")19        threshold = inputs.get("threshold", 27.0)20        min_scene_len = int(inputs.get("min_scene_len", 15))21        show_progress = inputs.get("show_progress", False)2223        if not video:24            raise ValueError("Video input is required")2526        if detector not in ("content", "adaptive"):27            raise ValueError(f"Invalid detector '{detector}'. Must be 'content' or 'adaptive'")2829        video_path = os.path.join(INPUT_DIR, video)30        if not os.path.exists(video_path):31            raise FileNotFoundError(f"Input video not found: {video_path}")3233        print(34            f"Detecting scenes: detector={detector}, threshold={threshold}, "35            f"min_scene_len={min_scene_len}",36            file=sys.stderr,37        )3839        result = Gais.detect.scenes(40            video=video_path,41            detector=detector,42            threshold=float(threshold),43            min_scene_len=min_scene_len,44            show_progress=show_progress,45        )4647        result_data = json.loads(result.content)4849        scenes = result_data.get("scenes", [])50        total_scenes = result_data.get("total_scenes", 0)51        video_duration = result_data.get("video_duration", 0.0)52        detector_used = result_data.get("detector_used", detector)53        processing_time = result_data.get("processing_time_ms", 0)5455        print(56            f"Detection complete: {total_scenes} scenes found, "57            f"duration={video_duration}s, detector={detector_used}, "58            f"processing_time={processing_time}ms",59            file=sys.stderr,60        )6162        # Flat output — keys match OUTPUT_SCHEMA63        # scenes is serialized as JSON Text for downstream Text consumers64        output = {65            "scenes": json.dumps(scenes),66            "total_scenes": total_scenes,67            "video_duration": video_duration,68            "detector_used": detector_used,69        }70        print(json.dumps(output, indent=2))7172    except Exception as e:73        error_output = {74            "error": str(e),75            "errorType": type(e).__name__,76            "traceback": traceback.format_exc(),77        }78        print(json.dumps(error_output), file=sys.stderr)79        sys.exit(1)808182if __name__ == "__main__":83    main()

$ git log --oneline

v1.5.2
HEAD
2026-05-07
v1.3.02026-04-09