INNER CODE UNIT · Python
valid_timed_video
ChenShuo2004/cs-board · webapp/server.py:572
def valid_timed_video(path: Path, expected_ms: int, tolerance_seconds: float = 0.22) -> bool:
"""Reject stale scene clips whose old renderer added time past the narration."""
if not valid_media_file(path):
return False
try:
return abs(probe_duration(path) - expected_ms / 1000.0) <= tolerance_seconds
except Exception:
return False
def fit_scene_durations(scenes: list[dict[str, Any]], audio_duration: float) -> bool:
"""Make scene timing add up exactly to the voice track without starving the final image."""
if not scenes:
return False
target_ms = max(len(scenes), round(max(0.001, audio_duration) * 1000))
minimum_ms = min(1000, target_ms // len(scenes))
remaining_ms = target_ms - minimum_ms * len(scenes)
weights = [max(1, len(str(scene.get("text", "")))) for scene in scenes]