File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -532,6 +532,8 @@ def update_widgets(self):
532532 pass
533533 elif filepath .suffix .lower () in VIDEO_TYPES :
534534 video = cv2 .VideoCapture (str (filepath ))
535+ if video .get (cv2 .CAP_PROP_FRAME_COUNT ) <= 0 :
536+ raise cv2 .error ("File is invalid or has 0 frames" )
535537 video .set (cv2 .CAP_PROP_POS_FRAMES , 0 )
536538 success , frame = video .read ()
537539 frame = cv2 .cvtColor (frame , cv2 .COLOR_BGR2RGB )
Original file line number Diff line number Diff line change @@ -162,10 +162,10 @@ def render(
162162 # Videos =======================================================
163163 elif _filepath .suffix .lower () in VIDEO_TYPES :
164164 video = cv2 .VideoCapture (str (_filepath ))
165- video .set (
166- cv2 . CAP_PROP_POS_FRAMES ,
167- ( video . get ( cv2 .CAP_PROP_FRAME_COUNT ) // 2 ),
168- )
165+ frame_count = video .get ( cv2 . CAP_PROP_FRAME_COUNT )
166+ if frame_count <= 0 :
167+ raise cv2 .error ( "File is invalid or has 0 frames" )
168+ video . set ( cv2 . CAP_PROP_POS_FRAMES , frame_count // 2 )
169169 success , frame = video .read ()
170170 if not success :
171171 # Depending on the video format, compression, and frame
You can’t perform that action at this time.
0 commit comments