This commit is contained in:
sean-kim05 2026-07-17 12:59:40 -07:00 committed by GitHub
commit 2eac058daa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -890,7 +890,7 @@ class VideoFromComponents(VideoInput):
duration: float | None = None,
strict_duration: bool = True,
) -> VideoInput | None:
if self.get_duration() < start_time + duration:
if strict_duration and self.get_duration() < start_time + duration:
return None
#TODO Consider tracking duration and trimming at time of save?
return VideoFromFile(self.get_stream_source(), start_time=start_time, duration=duration)

View File

@ -117,6 +117,16 @@ def test_video_from_components_get_dimensions(video_components):
assert height == 2
def test_video_from_components_as_trimmed_respects_strict_duration(video_components):
"""as_trimmed honors strict_duration, matching VideoFromFile.as_trimmed."""
video = VideoFromComponents(video_components)
over = video.get_duration() + 100
# Non-strict: a window longer than the source yields a best-effort clip, not None.
assert video.as_trimmed(start_time=0, duration=over, strict_duration=False) is not None
# Strict: the same over-long window is rejected.
assert video.as_trimmed(start_time=0, duration=over, strict_duration=True) is None
def test_video_from_file_get_duration(simple_video_file):
"""Duration extracted from file metadata"""
video = VideoFromFile(simple_video_file)