$ show Breakthrough/PySceneDetect
PySceneDetect is a production-grade Python library and CLI tool for detecting scene changes (cuts, fades, dissolves) in video files. It provides multiple detection algorithms (ContentDetector, AdaptiveDetector, ThresholdDetector, HistogramDetector, HashDetector, and TransNetV2 ONNX) and supports several video backends (OpenCV, PyAV, MoviePy). The architecture is modular: a VideoStream abstraction for decoding, a SceneDetector interface for pluggable algorithms, a SceneManager for orchestration, and output writers for CSV, EDL, FCP XML, OTIO, HTML, images, and video splitting. The CLI (built with click) offers chained subcommands for detection, splitting, and export. The repository also includes a comprehensive benchmark suite for evaluating accuracy on public shot-boundary datasets (BBC, AutoShot, ClipShots) using TRECVID-SBD metrics, making it valuable for both practical video processing and research. The codebase is well-structured, has extensive test coverage, and is actively maintained with recent releases and CI workflows.
The LLM identified 4 files worth highlighting for reuse:
Contains FrameTimecode and Timecode classes that handle frame-to-time conversion, exact rational arithmetic via Python's Fraction, and PTS-based timing for variable frame rate video. This module is self-contained and could be extracted as a standalone timecode utility for any video project requiring precise VFR-aware time manipulation.
Implements StatsManager, which caches per-frame detector metrics (e.g., content_val, delta_hue) to a CSV file. This enables incremental re-analysis without re-decoding, and the CSV export allows users to inspect or tune thresholds. The component is isolated, depends only on FrameTimecode, and demonstrates a reusable pattern for two-pass metric storage in video analysis pipelines.
Provides FanOutVideoStream, which fans a single VideoStream decode into N consumer streams, allowing multiple detectors or benchmarks to process the same frame sequence concurrently without redundant decoding. This is a non-obvious optimization pattern originally used for parameter sweeps; it is isolated and could be reused in any multi-consumer video analysis workflow.
Implements greedy 1-to-1 matching for hard cuts and point-in-interval matching for fades, producing precision/recall/F1 per video and aggregate metrics. The score_video() and evaluate() functions are dataset-agnostic and could be extracted for any shot-boundary evaluation task, requiring only ground truth and detected scene lists in a standard format.