Skip to content

Commit 63613c7

Browse files
committed
Added test cases, updated docstring
1 parent ede4c25 commit 63613c7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/torchcodec/_core/_metadata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ class VideoStreamMetadata(StreamMetadata):
8585
def duration_seconds(self) -> Optional[float]:
8686
"""Duration of the stream in seconds. We try to calculate the duration
8787
from the actual frames if a :term:`scan` was performed. Otherwise we
88-
fall back to ``duration_seconds_from_header``.
88+
fall back to ``duration_seconds_from_header``. If that value is None,
89+
we instead calculate the duration from ``num_frames_from_header`` and
90+
``average_fps_from_header``.
8991
"""
9092
if (
9193
self.end_stream_seconds_from_content is not None

test/test_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_calculate_num_frames_using_fps_and_duration(
173173

174174
@pytest.mark.parametrize(
175175
"duration_seconds_from_header, begin_stream_seconds_from_content, end_stream_seconds_from_content, expected_duration_seconds",
176-
[(60, 5, 20, 15), (60, 1, None, 60), (None, 0, 10, 10)],
176+
[(60, 5, 20, 15), (60, 1, None, 60), (60, None, 1, 60), (None, 0, 10, 10)],
177177
)
178178
def test_duration_seconds_fallback(
179179
duration_seconds_from_header,
@@ -204,7 +204,7 @@ def test_duration_seconds_fallback(
204204

205205
@pytest.mark.parametrize(
206206
"num_frames_from_header, average_fps_from_header, expected_duration_seconds",
207-
[(100, 10, 10), (100, None, None), (None, None, None)],
207+
[(100, 10, 10), (100, None, None), (None, 10, None), (None, None, None)],
208208
)
209209
def test_calculate_duration_seconds_using_fps_and_num_frames(
210210
num_frames_from_header, average_fps_from_header, expected_duration_seconds

0 commit comments

Comments
 (0)