Skip to content

Commit e375166

Browse files
author
Andrew Arneson
authored
Raise error if video file has 0 frames or is in valid. (#275)
video.get(cv2.CAP_PROP_FRAME_COUNT) returns 0 or -1
1 parent 7054ffd commit e375166

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

tagstudio/src/qt/widgets/preview_panel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

tagstudio/src/qt/widgets/thumb_renderer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)