Unverified Commit e3f1a822 authored by Prabhat Roy's avatar Prabhat Roy Committed by GitHub
Browse files

Improve test_videoapi (#5497)

parent c29a20ab
......@@ -52,14 +52,11 @@ test_videos = {
@pytest.mark.skipif(_HAS_VIDEO_OPT is False, reason="Didn't compile with ffmpeg")
class TestVideoApi:
@pytest.mark.skipif(av is None, reason="PyAV unavailable")
def test_frame_reading(self):
for test_video, config in test_videos.items():
@pytest.mark.parametrize("test_video", test_videos.keys())
def test_frame_reading(self, test_video):
full_path = os.path.join(VIDEO_DIR, test_video)
with av.open(full_path) as av_reader:
is_video = True if av_reader.streams.video else False
if is_video:
if av_reader.streams.video:
av_frames, vr_frames = [], []
av_pts, vr_pts = [], []
# get av frames
......@@ -91,9 +88,7 @@ class TestVideoApi:
# test audio reading compared to PYAV
with av.open(full_path) as av_reader:
is_audio = True if av_reader.streams.audio else False
if is_audio:
if av_reader.streams.audio:
av_frames, vr_frames = [], []
av_pts, vr_pts = [], []
# get av frames
......@@ -119,25 +114,24 @@ class TestVideoApi:
# we assure that there is never more than 1% difference in signal
assert max_delta.item() < 0.001
def test_metadata(self):
@pytest.mark.parametrize("test_video,config", test_videos.items())
def test_metadata(self, test_video, config):
"""
Test that the metadata returned via pyav corresponds to the one returned
by the new video decoder API
"""
for test_video, config in test_videos.items():
full_path = os.path.join(VIDEO_DIR, test_video)
reader = VideoReader(full_path, "video")
reader_md = reader.get_metadata()
assert config.video_fps == approx(reader_md["video"]["fps"][0], abs=0.0001)
assert config.duration == approx(reader_md["video"]["duration"][0], abs=0.5)
def test_seek_start(self):
for test_video, config in test_videos.items():
@pytest.mark.parametrize("test_video", test_videos.keys())
def test_seek_start(self, test_video):
full_path = os.path.join(VIDEO_DIR, test_video)
video_reader = VideoReader(full_path, "video")
num_frames = 0
for frame in video_reader:
for _ in video_reader:
num_frames += 1
# now seek the container to 0 and do it again
......@@ -145,7 +139,7 @@ class TestVideoApi:
# this way and it doesn't start at 0
video_reader.seek(0)
start_num_frames = 0
for frame in video_reader:
for _ in video_reader:
start_num_frames += 1
assert start_num_frames == num_frames
......@@ -153,28 +147,26 @@ class TestVideoApi:
# now seek the container to < 0 to check for unexpected behaviour
video_reader.seek(-1)
start_num_frames = 0
for frame in video_reader:
for _ in video_reader:
start_num_frames += 1
assert start_num_frames == num_frames
def test_accurateseek_middle(self):
for test_video, config in test_videos.items():
@pytest.mark.parametrize("test_video", test_videos.keys())
def test_accurateseek_middle(self, test_video):
full_path = os.path.join(VIDEO_DIR, test_video)
stream = "video"
video_reader = VideoReader(full_path, stream)
md = video_reader.get_metadata()
duration = md[stream]["duration"][0]
if duration is not None:
num_frames = 0
for frame in video_reader:
for _ in video_reader:
num_frames += 1
video_reader.seek(duration / 2)
middle_num_frames = 0
for frame in video_reader:
for _ in video_reader:
middle_num_frames += 1
assert middle_num_frames < num_frames
......@@ -199,8 +191,8 @@ class TestVideoApi:
os.remove(video_path)
@pytest.mark.skipif(av is None, reason="PyAV unavailable")
def test_keyframe_reading(self):
for test_video, config in test_videos.items():
@pytest.mark.parametrize("test_video,config", test_videos.items())
def test_keyframe_reading(self, test_video, config):
full_path = os.path.join(VIDEO_DIR, test_video)
av_reader = av.open(full_path)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment