Skip to content

Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.

Treat a short layout switch as a layout switch (#242)

Nika Siradze4fdcf04c2cb0
diff --git a/backend/services/face_track_helpers.py b/backend/services/face_track_helpers.py
index 4c09829..4121f39 100644
--- a/backend/services/face_track_helpers.py
+++ b/backend/services/face_track_helpers.py
@@ -255,11 +255,27 @@ def seats_from_frames(
return left, right
+def longest_layout_run(detections: list, split: bool) -> float:
+ best = 0.0
+ start = None
+ for t, faces in detections:
+ if not faces:
+ continue
+ if (len(faces) >= 2) == split:
+ if start is None:
+ start = t
+ best = max(best, t - start)
+ else:
+ start = None
+ return best
+
+
def clip_layout_is_mixed(
detections: list,
face_map: dict | None = None,
min_share: float = 0.15,
min_frames: int = 3,
+ min_run: float = 1.0,
) -> bool:
"""Does this clip switch between a split screen and a fullscreen shot?
@@ -284,6 +300,12 @@ def clip_layout_is_mixed(
):
return True
+ if (
+ longest_layout_run(detections, split=True) >= min_run
+ and longest_layout_run(detections, split=False) >= min_run
+ ):
+ return True
+
# A clip sitting entirely inside one layout still belongs to a mixed
# episode, so the episode-wide flag stays a valid hint.
return bool(face_map and face_map.get("is_mixed_layout", False))
diff --git a/tests/test_crop_path_golden.py b/tests/test_crop_path_golden.py
index 7875670..32c9b24 100644
--- a/tests/test_crop_path_golden.py
+++ b/tests/test_crop_path_golden.py
@@ -396,6 +396,25 @@ class MixedLayoutDetectionTests(unittest.TestCase):
# through the mixed path.
self.assertFalse(self._decide(self._frames(76, 4)))
+ def test_a_short_switch_at_the_end_of_a_clip_is_still_a_layout_change(self):
+ self.assertTrue(self._decide(self._frames(0, 326) + [
+ ((326 + i) * 0.1, [{"cx": 1181}, {"cx": 2909}]) for i in range(15)
+ ]))
+
+ def test_scattered_misses_never_add_up_to_a_run(self):
+ det = []
+ for i in range(300):
+ faces = [{"cx": 2050}] if i % 10 == 0 else [{"cx": 1181}, {"cx": 2909}]
+ det.append((i * 0.1, faces))
+ self.assertFalse(self._decide(det))
+
+ def test_frames_with_no_face_do_not_break_a_run(self):
+ det = self._frames(0, 300) + [
+ ((300 + i) * 0.1, [] if i % 3 == 0 else [{"cx": 1181}, {"cx": 2909}])
+ for i in range(15)
+ ]
+ self.assertTrue(self._decide(det))
+
def test_face_map_flag_still_wins_when_the_clip_looks_uniform(self):
# A clip that sits entirely inside one layout still belongs to a mixed
# episode; the episode-wide flag remains a valid hint.