Raise error if video file has 0 frames or is in valid. (#275)

video.get(cv2.CAP_PROP_FRAME_COUNT) returns 0 or -1
This commit is contained in:
Andrew Arneson
2024-06-10 19:10:57 -06:00
committed by GitHub
parent 7054ffd227
commit e375166bfe
2 changed files with 6 additions and 4 deletions

View File

@@ -532,6 +532,8 @@ class PreviewPanel(QWidget):
pass
elif filepath.suffix.lower() in VIDEO_TYPES:
video = cv2.VideoCapture(str(filepath))
if video.get(cv2.CAP_PROP_FRAME_COUNT) <= 0:
raise cv2.error("File is invalid or has 0 frames")
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
success, frame = video.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

View File

@@ -162,10 +162,10 @@ class ThumbRenderer(QObject):
# Videos =======================================================
elif _filepath.suffix.lower() in VIDEO_TYPES:
video = cv2.VideoCapture(str(_filepath))
video.set(
cv2.CAP_PROP_POS_FRAMES,
(video.get(cv2.CAP_PROP_FRAME_COUNT) // 2),
)
frame_count = video.get(cv2.CAP_PROP_FRAME_COUNT)
if frame_count <= 0:
raise cv2.error("File is invalid or has 0 frames")
video.set(cv2.CAP_PROP_POS_FRAMES, frame_count // 2)
success, frame = video.read()
if not success:
# Depending on the video format, compression, and frame