feat: add resolve_keyframe helper to extract sorted-keyframe lookup

Adds a pure function that returns the latest keyframe at or before a
given time (with tolerance), replacing the inline lookup pattern that
appears multiple times in main.py. Includes 6 tests covering empty
list, before-first, exact match, between, after-last, and tolerance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-14 15:48:00 +02:00
parent b9e9fa927e
commit 8e8c8b9774
2 changed files with 48 additions and 1 deletions
+15
View File
@@ -53,6 +53,21 @@ def format_time(seconds: float) -> str:
return f"{m}:{s:04.1f}"
def resolve_keyframe(
keyframes: list[tuple[float, float, str | None, bool, bool]],
t: float,
tolerance: float = 0.05,
) -> tuple[float, float, str | None, bool, bool] | None:
"""Return the latest keyframe at or before *t*, or None."""
result = None
for kf in keyframes:
if kf[0] <= t + tolerance:
result = kf
else:
break
return result
def build_ffmpeg_command(
input_path: str, start: float, output_path: str,
short_side: int | None = None,