-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Video handle persistence #64
Changes from 3 commits
a7d728d
44ba1d4
d56e11d
1efa15c
97fb1f8
27740b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import numpy as np | ||
from numpy.testing import assert_equal | ||
import h5py | ||
import pytest | ||
|
||
|
||
def test_video_backend_from_filename(centered_pair_low_quality_path, slp_minimal_pkg): | ||
|
@@ -55,35 +56,53 @@ def test_get_frame(centered_pair_low_quality_path): | |
assert_equal(backend[-3:-1], backend.get_frames(range(1097, 1099))) | ||
|
||
|
||
def test_mediavideo(centered_pair_low_quality_path): | ||
@pytest.mark.parametrize("keep_open", [False, True]) | ||
def test_mediavideo(centered_pair_low_quality_path, keep_open): | ||
backend = VideoBackend.from_filename( | ||
centered_pair_low_quality_path, plugin="FFMPEG" | ||
centered_pair_low_quality_path, plugin="FFMPEG", keep_open=keep_open | ||
) | ||
assert type(backend) == MediaVideo | ||
assert backend.filename == centered_pair_low_quality_path | ||
talmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert backend.shape == (1100, 384, 384, 1) | ||
assert backend[0].shape == (384, 384, 1) | ||
assert backend[:3].shape == (3, 384, 384, 1) | ||
if keep_open: | ||
assert backend._open_reader is not None | ||
assert backend[0].shape == (384, 384, 1) | ||
assert type(backend._open_reader).__name__ == "LegacyPlugin" | ||
|
||
backend = VideoBackend.from_filename(centered_pair_low_quality_path, plugin="pyav") | ||
backend = VideoBackend.from_filename( | ||
centered_pair_low_quality_path, plugin="pyav", keep_open=keep_open | ||
) | ||
assert type(backend) == MediaVideo | ||
assert backend.filename == centered_pair_low_quality_path | ||
assert backend.shape == (1100, 384, 384, 1) | ||
assert backend[0].shape == (384, 384, 1) | ||
assert backend[:3].shape == (3, 384, 384, 1) | ||
if keep_open: | ||
assert backend._open_reader is not None | ||
assert backend[0].shape == (384, 384, 1) | ||
assert type(backend._open_reader).__name__ == "PyAVPlugin" | ||
|
||
backend = VideoBackend.from_filename( | ||
centered_pair_low_quality_path, plugin="opencv" | ||
centered_pair_low_quality_path, plugin="opencv", keep_open=keep_open | ||
) | ||
assert type(backend) == MediaVideo | ||
assert backend.filename == centered_pair_low_quality_path | ||
assert backend.shape == (1100, 384, 384, 1) | ||
assert backend[0].shape == (384, 384, 1) | ||
assert backend[:3].shape == (3, 384, 384, 1) | ||
if keep_open: | ||
assert backend._open_reader is not None | ||
assert backend[0].shape == (384, 384, 1) | ||
assert type(backend._open_reader).__name__ == "VideoCapture" | ||
|
||
|
||
def test_hdf5video_rank4(centered_pair_low_quality_path, tmp_path): | ||
backend = VideoBackend.from_filename(centered_pair_low_quality_path) | ||
@pytest.mark.parametrize("keep_open", [False, True]) | ||
def test_hdf5video_rank4(centered_pair_low_quality_path, tmp_path, keep_open): | ||
backend = VideoBackend.from_filename( | ||
centered_pair_low_quality_path, keep_open=keep_open | ||
) | ||
imgs = backend[:3] | ||
assert imgs.shape == (3, 384, 384, 1) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The addition of the if keep_open:
assert backend._open_reader is not None
assert backend[0].shape == (384, 384, 1)
+ else:
+ assert backend._open_reader is None |
||
|
@@ -97,6 +116,9 @@ def test_hdf5video_rank4(centered_pair_low_quality_path, tmp_path): | |
assert backend[0].shape == (384, 384, 1) | ||
assert backend[:].shape == (3, 384, 384, 1) | ||
assert not backend.has_embedded_images | ||
if keep_open: | ||
assert backend._open_reader is not None | ||
assert backend[0].shape == (384, 384, 1) | ||
|
||
|
||
def test_hdf5video_embedded(slp_minimal_pkg): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the
_read_frame
method, the_read_frames
method has also been updated to use the cached reader ifkeep_open
isTrue
. Again, make sure that the reader is properly closed when it's no longer needed.