Skip to content

Commit 9c9e462

Browse files
committed
Added test
1 parent 14e2876 commit 9c9e462

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/decoders/test_video_decoder_ops.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
get_frame_at_index,
2828
get_frame_at_pts,
2929
get_frames_at_indices,
30+
get_frames_at_ptss,
3031
get_frames_by_pts_in_range,
3132
get_frames_in_range,
3233
get_json_metadata,
@@ -157,6 +158,37 @@ def test_get_frames_at_indices_with_sort(self, sort_indices):
157158
with pytest.raises(AssertionError):
158159
assert_tensor_equal(frames[0], frames[-1])
159160

161+
@pytest.mark.parametrize("sort_ptss", (False, True))
162+
def test_get_frames_at_ptss_with_sort(self, sort_ptss):
163+
decoder = create_from_file(str(NASA_VIDEO.path))
164+
_add_video_stream(decoder)
165+
scan_all_streams_to_update_metadata(decoder)
166+
stream_index = 3
167+
168+
frame_ptss = [2, 0, 1, 0 + 1e-3, 2 + 1e-3]
169+
170+
expected_frames = [
171+
get_frame_at_pts(decoder, seconds=pts)[0] for pts in frame_ptss
172+
]
173+
174+
frames, *_ = get_frames_at_ptss(
175+
decoder,
176+
stream_index=stream_index,
177+
frame_ptss=frame_ptss,
178+
sort_ptss=sort_ptss,
179+
)
180+
for frame, expected_frame in zip(frames, expected_frames):
181+
assert_tensor_equal(frame, expected_frame)
182+
183+
# # first and last frame should be equal, at pts=2 [+ eps]. We then
184+
# modify the # first frame and assert that it's now different from the
185+
# last frame. # This ensures a copy was properly made during the
186+
# de-duplication logic.
187+
assert_tensor_equal(frames[0], frames[-1])
188+
frames[0] += 20
189+
with pytest.raises(AssertionError):
190+
assert_tensor_equal(frames[0], frames[-1])
191+
160192
def test_get_frames_in_range(self):
161193
decoder = create_from_file(str(NASA_VIDEO.path))
162194
scan_all_streams_to_update_metadata(decoder)

0 commit comments

Comments
 (0)