From b4262e683891d28f2f6ec2f1313d993bc048d664 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Tue, 1 Feb 2022 12:07:45 +0000 Subject: [PATCH 1/2] Updated gpu decoder test to use parametrize --- test/test_video_gpu_decoder.py | 76 ++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/test/test_video_gpu_decoder.py b/test/test_video_gpu_decoder.py index 3379b2f8721..ebc30553901 100644 --- a/test/test_video_gpu_decoder.py +++ b/test/test_video_gpu_decoder.py @@ -12,30 +12,33 @@ VIDEO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "videos") -test_videos = [ - "RATRACE_wave_f_nm_np1_fr_goo_37.avi", - "TrumanShow_wave_f_nm_np1_fr_med_26.avi", - "v_SoccerJuggling_g23_c01.avi", - "v_SoccerJuggling_g24_c01.avi", - "R6llTwEh07w.mp4", - "SOX5yA1l24A.mp4", - "WUzgd7C1pWA.mp4", -] - @pytest.mark.skipif(_HAS_VIDEO_DECODER is False, reason="Didn't compile with support for gpu decoder") class TestVideoGPUDecoder: @pytest.mark.skipif(av is None, reason="PyAV unavailable") - def test_frame_reading(self): - for test_video in test_videos: - full_path = os.path.join(VIDEO_DIR, test_video) - decoder = VideoReader(full_path, device="cuda:0") - with av.open(full_path) as container: - for av_frame in container.decode(container.streams.video[0]): - av_frames = torch.tensor(av_frame.to_rgb(src_colorspace="ITU709").to_ndarray()) - vision_frames = next(decoder)["data"] - mean_delta = torch.mean(torch.abs(av_frames.float() - vision_frames.cpu().float())) - assert mean_delta < 0.75 + @pytest.mark.parametrize( + "full_path", + [ + os.path.join(VIDEO_DIR, x) + for x in [ + "RATRACE_wave_f_nm_np1_fr_goo_37.avi", + "TrumanShow_wave_f_nm_np1_fr_med_26.avi", + "v_SoccerJuggling_g23_c01.avi", + "v_SoccerJuggling_g24_c01.avi", + "R6llTwEh07w.mp4", + "SOX5yA1l24A.mp4", + "WUzgd7C1pWA.mp4", + ] + ], + ) + def test_frame_reading(self, full_path): + decoder = VideoReader(full_path, device="cuda:0") + with av.open(full_path) as container: + for av_frame in container.decode(container.streams.video[0]): + av_frames = torch.tensor(av_frame.to_rgb(src_colorspace="ITU709").to_ndarray()) + vision_frames = next(decoder)["data"] + mean_delta = torch.mean(torch.abs(av_frames.float() - vision_frames.cpu().float())) + assert mean_delta < 0.75 @pytest.mark.skipif(av is None, reason="PyAV unavailable") @pytest.mark.parametrize("keyframes", [True, False]) @@ -65,16 +68,29 @@ def test_seek_reading(self, keyframes, full_path, duration): assert mean_delta < 0.75 @pytest.mark.skipif(av is None, reason="PyAV unavailable") - def test_metadata(self): - for test_video in test_videos: - full_path = os.path.join(VIDEO_DIR, test_video) - decoder = VideoReader(full_path, device="cuda:0") - video_metadata = decoder.get_metadata()["video"] - with av.open(full_path) as container: - video = container.streams.video[0] - av_duration = float(video.duration * video.time_base) - assert math.isclose(video_metadata["duration"], av_duration, rel_tol=1e-2) - assert math.isclose(video_metadata["fps"], video.base_rate, rel_tol=1e-2) + @pytest.mark.parametrize( + "full_path", + [ + os.path.join(VIDEO_DIR, x) + for x in [ + "RATRACE_wave_f_nm_np1_fr_goo_37.avi", + "TrumanShow_wave_f_nm_np1_fr_med_26.avi", + "v_SoccerJuggling_g23_c01.avi", + "v_SoccerJuggling_g24_c01.avi", + "R6llTwEh07w.mp4", + "SOX5yA1l24A.mp4", + "WUzgd7C1pWA.mp4", + ] + ], + ) + def test_metadata(self, full_path): + decoder = VideoReader(full_path, device="cuda:0") + video_metadata = decoder.get_metadata()["video"] + with av.open(full_path) as container: + video = container.streams.video[0] + av_duration = float(video.duration * video.time_base) + assert math.isclose(video_metadata["duration"], av_duration, rel_tol=1e-2) + assert math.isclose(video_metadata["fps"], video.base_rate, rel_tol=1e-2) if __name__ == "__main__": From f3b41df075a8e01ac369106508266261072fffad Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Tue, 1 Feb 2022 12:36:12 +0000 Subject: [PATCH 2/2] Remove list comprehension --- test/test_video_gpu_decoder.py | 44 ++++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/test/test_video_gpu_decoder.py b/test/test_video_gpu_decoder.py index ebc30553901..e208c6b97d8 100644 --- a/test/test_video_gpu_decoder.py +++ b/test/test_video_gpu_decoder.py @@ -17,21 +17,19 @@ class TestVideoGPUDecoder: @pytest.mark.skipif(av is None, reason="PyAV unavailable") @pytest.mark.parametrize( - "full_path", + "video_file", [ - os.path.join(VIDEO_DIR, x) - for x in [ - "RATRACE_wave_f_nm_np1_fr_goo_37.avi", - "TrumanShow_wave_f_nm_np1_fr_med_26.avi", - "v_SoccerJuggling_g23_c01.avi", - "v_SoccerJuggling_g24_c01.avi", - "R6llTwEh07w.mp4", - "SOX5yA1l24A.mp4", - "WUzgd7C1pWA.mp4", - ] + "RATRACE_wave_f_nm_np1_fr_goo_37.avi", + "TrumanShow_wave_f_nm_np1_fr_med_26.avi", + "v_SoccerJuggling_g23_c01.avi", + "v_SoccerJuggling_g24_c01.avi", + "R6llTwEh07w.mp4", + "SOX5yA1l24A.mp4", + "WUzgd7C1pWA.mp4", ], ) - def test_frame_reading(self, full_path): + def test_frame_reading(self, video_file): + full_path = os.path.join(VIDEO_DIR, video_file) decoder = VideoReader(full_path, device="cuda:0") with av.open(full_path) as container: for av_frame in container.decode(container.streams.video[0]): @@ -69,21 +67,19 @@ def test_seek_reading(self, keyframes, full_path, duration): @pytest.mark.skipif(av is None, reason="PyAV unavailable") @pytest.mark.parametrize( - "full_path", + "video_file", [ - os.path.join(VIDEO_DIR, x) - for x in [ - "RATRACE_wave_f_nm_np1_fr_goo_37.avi", - "TrumanShow_wave_f_nm_np1_fr_med_26.avi", - "v_SoccerJuggling_g23_c01.avi", - "v_SoccerJuggling_g24_c01.avi", - "R6llTwEh07w.mp4", - "SOX5yA1l24A.mp4", - "WUzgd7C1pWA.mp4", - ] + "RATRACE_wave_f_nm_np1_fr_goo_37.avi", + "TrumanShow_wave_f_nm_np1_fr_med_26.avi", + "v_SoccerJuggling_g23_c01.avi", + "v_SoccerJuggling_g24_c01.avi", + "R6llTwEh07w.mp4", + "SOX5yA1l24A.mp4", + "WUzgd7C1pWA.mp4", ], ) - def test_metadata(self, full_path): + def test_metadata(self, video_file): + full_path = os.path.join(VIDEO_DIR, video_file) decoder = VideoReader(full_path, device="cuda:0") video_metadata = decoder.get_metadata()["video"] with av.open(full_path) as container: