Skip to content

Commit

Permalink
Make video loading thread more robust to videos that
Browse files Browse the repository at this point in the history
report inaccurate durations.
  • Loading branch information
isaacrobinson2000 committed Aug 16, 2023
1 parent 59c2489 commit 6bc92cb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions diplomat/predictors/supervised_fpe/guilib/video_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,18 @@ def video_loader(video_hdl: cv2.VideoCapture, frame_queue: ControlDeque, time_lo
if(frame is None):
valid_frame, frame = video_hdl.read()

# If this is not a valid frame(reached end of video), or the video player has sent a command, stop and get
if(not valid_frame):
# If we didn't receive a frame (reached end of video) generate a dummy frame to load into the queue...
# This avoids a deadlock if the reported duration of the video is longer then the video actually is...
frame = np.zeros((
int(video_hdl.get(cv2.CAP_PROP_FRAME_HEIGHT)),
int(video_hdl.get(cv2.CAP_PROP_FRAME_WIDTH)),
3
), dtype=np.uint8)

# If the video player has sent a command, stop and get
# the command, and jump to the spot. Otherwise, immediately push another frame onto the queue.
if((not valid_frame) or (time_loc.poll())):
if(time_loc.poll()):
new_loc = time_check(time_loc)
if(new_loc is None):
video_hdl.release()
Expand All @@ -246,9 +255,11 @@ def video_loader(video_hdl: cv2.VideoCapture, frame_queue: ControlDeque, time_lo
frame_queue.push_right_relaxed(frame)
frame = None


# Represents (x, y, width, height)
Box = Tuple[int, int, int, int]


class VideoPlayer(wx.Control):
"""
A video player for wx Widgets, Using cv2 for solid cross-platform video support. Can play video, but no audio.
Expand Down

0 comments on commit 6bc92cb

Please sign in to comment.