Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.
Python ai-toolsauto-captionscaptionscliffmpegmcpmcp-serveropusclip-alternativepodcast-clipspodcastsshortform-videovertical-videowhisper
Pool highlight detection across a folder of clips
Nika Siradzec2c48ed8279c
diff --git a/backend/main.py b/backend/main.pyindex 09fe114..98a45a9 100644--- a/backend/main.py+++ b/backend/main.py@@ -329,22 +329,33 @@ def handle_analyze_energy(task_id: str, params: dict):def handle_detect_highlights(task_id: str, params: dict):- """Detect highlight clips from a video's fused signal curve (party/action profiles)."""- from services.saliency import detect_highlights+ """Detect highlight clips from a video's fused signal curve (party/action profiles).+ Accepts a single `video_path`, or a list of `video_paths` to pool and rank+ highlights across a whole folder of clips.+ """+ from services.saliency import detect_highlights, detect_highlights_pooled++ video_paths = params.get("video_paths")video_path = params.get("video_path", "")- if not video_path:- emit_result(task_id, "error", error="video_path is required")+ if not video_paths and not video_path:+ emit_result(task_id, "error", error="video_path or video_paths is required")return- clips = detect_highlights(- video_path=video_path,+ common = dict(profile_name=params.get("profile", "party"),- top_n=int(params.get("top_n", 8)),min_dur=float(params.get("min_dur", 8.0)),max_dur=float(params.get("max_dur", 60.0)),progress_callback=lambda pct, msg: emit_progress(task_id, "detecting", pct, msg),)+ if video_paths:+ clips = detect_highlights_pooled(+ video_paths=video_paths, top_n=int(params.get("top_n", 15)), **common+ )+ else:+ clips = detect_highlights(+ video_path=video_path, top_n=int(params.get("top_n", 8)), **common+ )emit_result(task_id, "success", data={"clips": clips, "count": len(clips)})diff --git a/backend/services/saliency.py b/backend/services/saliency.pyindex ed300c2..bcedb8c 100644--- a/backend/services/saliency.py+++ b/backend/services/saliency.py@@ -243,3 +243,39 @@ def detect_highlights(if progress_callback:progress_callback(100, f"Found {len(clips)} highlights")return clips+++def detect_highlights_pooled(+ video_paths: list[str],+ profile_name: str = "party",+ top_n: int = 15,+ min_dur: float = 8.0,+ max_dur: float = 60.0,+ progress_callback: Optional[Callable] = None,+) -> list[dict]:+ """+ Detect highlights across many videos and rank them globally — "the best N bits+ from tonight" across a folder of party clips.++ Each returned clip carries a `source_file`. Ranking is reaction-first, then by+ score, so a genuine laugh in any file outranks a merely loud moment in another.+ """+ pooled: list[dict] = []+ n = len(video_paths) or 1+ for idx, path in enumerate(video_paths):+ clips = detect_highlights(+ path, profile_name=profile_name, top_n=top_n, min_dur=min_dur, max_dur=max_dur+ )+ for c in clips:+ c["source_file"] = path+ pooled.extend(clips)+ if progress_callback:+ progress_callback(+ int((idx + 1) / n * 100), f"{path}: {len(clips)} highlights"+ )++ pooled.sort(+ key=lambda c: (1 if "reaction" in c.get("reasons", []) else 0, c.get("score", 0)),+ reverse=True,+ )+ return pooled[:top_n]diff --git a/tests/test_saliency.py b/tests/test_saliency.pyindex 91f857e..8734ec7 100644--- a/tests/test_saliency.py+++ b/tests/test_saliency.py@@ -110,5 +110,38 @@ class WindowForPeakTests(unittest.TestCase):self.assertGreaterEqual(start, 0.0)+class PooledTests(unittest.TestCase):+ def test_pools_across_files_reaction_first_with_source(self):+ fake = {+ "a.mp4": [+ {"start_second": 10, "end_second": 18, "score": 30.0, "reasons": ["energy_peak"]},+ ],+ "b.mp4": [+ {"start_second": 5, "end_second": 15, "score": 12.0, "reasons": ["reaction"]},+ ],+ }+ orig = sal.detect_highlights+ sal.detect_highlights = lambda path, **kw: [dict(c) for c in fake[path]]+ try:+ pooled = sal.detect_highlights_pooled(["a.mp4", "b.mp4"], top_n=5)+ finally:+ sal.detect_highlights = orig+ self.assertEqual(len(pooled), 2)+ # reaction outranks the higher-scored energy peak across files+ self.assertEqual(pooled[0]["reasons"], ["reaction"])+ self.assertEqual(pooled[0]["source_file"], "b.mp4")+ self.assertTrue(all("source_file" in c for c in pooled))++ def test_top_n_caps_pool(self):+ fake = [{"start_second": i, "end_second": i + 8, "score": float(i), "reasons": ["energy_peak"]} for i in range(10)]+ orig = sal.detect_highlights+ sal.detect_highlights = lambda path, **kw: [dict(c) for c in fake]+ try:+ pooled = sal.detect_highlights_pooled(["a.mp4"], top_n=3)+ finally:+ sal.detect_highlights = orig+ self.assertEqual(len(pooled), 3)++if __name__ == "__main__":unittest.main()