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
Track a cut whose face map it scanned itself (#245)
Nika Siradze5c138e4d8571
diff --git a/backend/services/video_processor.py b/backend/services/video_processor.pyindex eace9c7..4c9075f 100644--- a/backend/services/video_processor.py+++ b/backend/services/video_processor.py@@ -372,7 +372,8 @@ def crop_to_vertical(# episode-wide face_map. Global speaker→side mappings are too coarse for# monologues and mixed-layout edits; they can pin a single-speaker clip# to the wrong person for the whole render.- if speakers_in_clip:+ scanned_here = bool(face_map) and not face_map.get("speaker_mappings")+ if speakers_in_clip or scanned_here:result = _track_and_crop(input_path, output_path,width, height, target_w, target_h,@@ -1645,8 +1646,9 @@ def _track_and_crop_inner(# Merge very short runs (<0.8s) into their neighborsif len(runs) > 1:merged_runs = [runs[0]]- for r in runs[1:]:- if (r[1] - r[0]) < 0.8:+ for i, r in enumerate(runs[1:], start=1):+ shortest = 0.4 if i == len(runs) - 1 else 0.8+ if (r[1] - r[0]) < shortest:# Absorb into previous runmerged_runs[-1] = (merged_runs[-1][0], r[1], merged_runs[-1][2])else:diff --git a/tests/test_video_processor.py b/tests/test_video_processor.pyindex 01bc26d..9563725 100644--- a/tests/test_video_processor.py+++ b/tests/test_video_processor.py@@ -705,7 +705,10 @@ class VideoProcessorTests(unittest.TestCase):strategy="face",transcript_words=[{"word": "hi", "start": 0.0, "end": 0.4, "speaker": None}],clip_start=0.0,- face_map={"clusters": [{"center_x": 100, "crop_x": 0}], "video_width": 1920},+ face_map={+ "clusters": [{"center_x": 100, "crop_x": 0}], "video_width": 1920,+ "speaker_mappings": {"SPEAKER_00": 0},+ },)self.assertEqual(result, "ok.mp4")@@ -714,6 +717,45 @@ class VideoProcessorTests(unittest.TestCase):track_crop.assert_not_called()runner.assert_called_once()+ def test_crop_to_vertical_tracks_a_cut_whose_face_map_it_scanned_itself(self):+ with mock.patch.object(vp, "get_dimensions", return_value=(1920, 1080)), \+ mock.patch.object(vp, "_use_face_map", return_value="456") as face_map_crop, \+ mock.patch.object(vp, "_track_and_crop", return_value="tracked.mp4") as track_crop, \+ mock.patch.object(vp, "_run_ffmpeg_with_fallback", return_value="ok.mp4") as runner:+ result = vp.crop_to_vertical(+ input_path="in.mp4",+ output_path="out.mp4",+ strategy="speaker",+ transcript_words=[{"word": "hi", "start": 0.0, "end": 0.4}],+ clip_start=0.0,+ face_map={+ "clusters": [{"center_x": 100, "crop_x": 0}], "video_width": 1920,+ "speaker_mappings": {},+ },+ )++ self.assertEqual(result, "tracked.mp4")+ track_crop.assert_called_once()+ face_map_crop.assert_not_called()+ runner.assert_not_called()++ def test_crop_to_vertical_falls_back_to_a_scanned_face_map_when_tracking_fails(self):+ with mock.patch.object(vp, "get_dimensions", return_value=(1920, 1080)), \+ mock.patch.object(vp, "_use_face_map", return_value="456") as face_map_crop, \+ mock.patch.object(vp, "_track_and_crop", return_value=None), \+ mock.patch.object(vp, "_run_ffmpeg_with_fallback", return_value="ok.mp4"):+ result = vp.crop_to_vertical(+ input_path="in.mp4",+ output_path="out.mp4",+ strategy="speaker",+ transcript_words=[{"word": "hi", "start": 0.0, "end": 0.4}],+ clip_start=0.0,+ face_map={"clusters": [{"center_x": 100, "crop_x": 0}], "video_width": 1920},+ )++ self.assertEqual(result, "ok.mp4")+ face_map_crop.assert_called_once()+if __name__ == "__main__":unittest.main()