From 22dfce43bdfdb73d6571f153bfc7d17e4624a1ec Mon Sep 17 00:00:00 2001 From: Pablo Prietz Date: Mon, 23 Mar 2020 14:52:10 +0100 Subject: [PATCH 1/2] Use custom error if video does not have frames The old implementation raises a TypeError as av.AVError expects an additional error code. Instead of passing any error code, the new implementation raises (and catches) a custom error in the case that a video is valid but does not contain any frames. --- pupil_src/shared_modules/video_capture/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pupil_src/shared_modules/video_capture/utils.py b/pupil_src/shared_modules/video_capture/utils.py index b29026d766..2c8b453e92 100644 --- a/pupil_src/shared_modules/video_capture/utils.py +++ b/pupil_src/shared_modules/video_capture/utils.py @@ -25,6 +25,10 @@ VIDEO_TIME_EXTS = VIDEO_EXTS + ("time",) +class VideoDoesNotContainFramesError(ValueError): + pass + + class Exposure_Time(object): def __init__(self, max_ET, frame_rate, mode="manual"): self.mode = mode @@ -189,8 +193,8 @@ def check_valid(self): # 3. decode() yields None first_frame = next(cont.decode(video=0), None) if first_frame is None: - raise av.AVError("Video does not contain any frames") - except av.AVError: + raise VideoDoesNotContainFramesError() + except (av.AVError, VideoDoesNotContainFramesError): return False else: cont.seek(0) From cc1b3ee9d3c700a2024dddfa561f3712daa9f182 Mon Sep 17 00:00:00 2001 From: Pablo Prietz Date: Tue, 24 Mar 2020 10:51:38 +0100 Subject: [PATCH 2/2] Apply PR review suggestion --- pupil_src/shared_modules/video_capture/utils.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pupil_src/shared_modules/video_capture/utils.py b/pupil_src/shared_modules/video_capture/utils.py index 2c8b453e92..2bce5b2a80 100644 --- a/pupil_src/shared_modules/video_capture/utils.py +++ b/pupil_src/shared_modules/video_capture/utils.py @@ -25,10 +25,6 @@ VIDEO_TIME_EXTS = VIDEO_EXTS + ("time",) -class VideoDoesNotContainFramesError(ValueError): - pass - - class Exposure_Time(object): def __init__(self, max_ET, frame_rate, mode="manual"): self.mode = mode @@ -193,8 +189,8 @@ def check_valid(self): # 3. decode() yields None first_frame = next(cont.decode(video=0), None) if first_frame is None: - raise VideoDoesNotContainFramesError() - except (av.AVError, VideoDoesNotContainFramesError): + return False # container does not contain frames + except av.AVError: return False else: cont.seek(0)