Improve multi-shot phase retune

This commit is contained in:
Melbar
2026-05-09 09:36:11 +02:00
parent a275b2efb6
commit c08ba97d37
8 changed files with 138 additions and 44 deletions
+30 -5
View File
@@ -22,6 +22,7 @@ from __future__ import annotations
import argparse
import base64
import json
import os
import re
import subprocess
import sys
@@ -134,6 +135,19 @@ def _run(cmd: list[str], timeout: int = 120) -> bool:
return False
def _forced_beats() -> set[int]:
raw = os.environ.get("CUTTER_REPORT_FORCE_BEATS", "")
forced: set[int] = set()
for part in re.split(r"[,;\s]+", raw):
if not part:
continue
try:
forced.add(int(part))
except ValueError:
continue
return forced
def extract_still(video_path: Path, t_s: float, out: Path) -> bool:
"""Always render fresh."""
if not video_path.exists():
@@ -410,6 +424,7 @@ def collect_rows(
stills_dir.mkdir(parents=True, exist_ok=True)
if with_clips:
clips_dir.mkdir(parents=True, exist_ok=True)
force_beats = _forced_beats()
rows: list[BeatRow] = []
for beat in beats:
@@ -454,13 +469,17 @@ def collect_rows(
if with_stills:
t_still = beat_still_time(beat["start_s"], beat["end_s"])
tjpg = stills_dir / f"beat_{bid:02d}_trailer.jpg"
if extract_still(trailer_path, t_still, tjpg):
if tjpg.exists() and bid not in force_beats:
trailer_still = tjpg
elif extract_still(trailer_path, t_still, tjpg):
trailer_still = tjpg
if rec is not None:
src_dur = max(0.04, rec["out_point_s"] - rec["in_point_s"])
s_still = rec["in_point_s"] + min(0.4, src_dur * 0.3)
sjpg = stills_dir / f"beat_{bid:02d}_source.jpg"
if extract_still(source_path, s_still, sjpg):
if sjpg.exists() and bid not in force_beats:
source_still = sjpg
elif extract_still(source_path, s_still, sjpg):
source_still = sjpg
if with_clips:
@@ -468,12 +487,16 @@ def collect_rows(
# Trailer clip (cutter-side, simple)
tmp4 = clips_dir / f"beat_{bid:02d}_trailer.mp4"
if extract_clip(trailer_path, beat["start_s"], beat_dur, tmp4):
if tmp4.exists() and bid not in force_beats:
trailer_clip = tmp4
elif extract_clip(trailer_path, beat["start_s"], beat_dur, tmp4):
trailer_clip = tmp4
if rec is not None:
smp4 = clips_dir / f"beat_{bid:02d}_source.mp4"
if num_segs >= 2:
if smp4.exists() and bid not in force_beats:
source_clip = smp4
elif num_segs >= 2:
seg_specs = [
(float(s["in_point_s"]),
max(0.04, float(s["out_point_s"]) - float(s["in_point_s"])))
@@ -502,7 +525,9 @@ def collect_rows(
"match_score": rec.get("match_score", 0.0),
"is_confirmed": rec.get("is_confirmed", False),
}]
if build_compare_clip(
if cmp4.exists() and bid not in force_beats:
compare_clip = cmp4
elif build_compare_clip(
trailer_path, beat["start_s"], beat_dur,
source_path, compare_segs,
cmp4,