|
27 | 27 | get_frame_at_index, |
28 | 28 | get_frame_at_pts, |
29 | 29 | get_frames_at_indices, |
| 30 | + get_frames_at_ptss, |
30 | 31 | get_frames_by_pts_in_range, |
31 | 32 | get_frames_in_range, |
32 | 33 | get_json_metadata, |
@@ -157,6 +158,37 @@ def test_get_frames_at_indices_with_sort(self, sort_indices): |
157 | 158 | with pytest.raises(AssertionError): |
158 | 159 | assert_tensor_equal(frames[0], frames[-1]) |
159 | 160 |
|
| 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 | + |
160 | 192 | def test_get_frames_in_range(self): |
161 | 193 | decoder = create_from_file(str(NASA_VIDEO.path)) |
162 | 194 | scan_all_streams_to_update_metadata(decoder) |
|
0 commit comments