Update utils/utils.py
Browse files- utils/utils.py +8 -14
utils/utils.py
CHANGED
|
@@ -971,28 +971,22 @@ def save_image(image: Image.Image,
|
|
| 971 |
# DEFAULT INSTANCES
|
| 972 |
# ============================================================================
|
| 973 |
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
def get_file_manager(base_dir: Optional[str] = None) -> FileManager:
|
| 977 |
-
"""Get or create the default FileManager instance"""
|
| 978 |
-
global _default_file_manager
|
| 979 |
-
if _default_file_manager is None or base_dir is not None:
|
| 980 |
-
_default_file_manager = FileManager(base_dir)
|
| 981 |
-
return _default_file_manager
|
| 982 |
-
|
| 983 |
-
def validate_video_file(file_path: str) -> bool:
|
| 984 |
"""Validate if file is a valid video file."""
|
| 985 |
import os
|
| 986 |
import cv2
|
| 987 |
|
| 988 |
if not os.path.exists(file_path):
|
| 989 |
-
return False
|
| 990 |
|
| 991 |
try:
|
| 992 |
cap = cv2.VideoCapture(file_path)
|
| 993 |
ret = cap.isOpened()
|
| 994 |
cap.release()
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
|
|
|
|
|
|
|
|
|
| 998 |
|
|
|
|
| 971 |
# DEFAULT INSTANCES
|
| 972 |
# ============================================================================
|
| 973 |
|
| 974 |
+
def validate_video_file(file_path: str) -> tuple:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 975 |
"""Validate if file is a valid video file."""
|
| 976 |
import os
|
| 977 |
import cv2
|
| 978 |
|
| 979 |
if not os.path.exists(file_path):
|
| 980 |
+
return False, f"File not found: {file_path}"
|
| 981 |
|
| 982 |
try:
|
| 983 |
cap = cv2.VideoCapture(file_path)
|
| 984 |
ret = cap.isOpened()
|
| 985 |
cap.release()
|
| 986 |
+
if ret:
|
| 987 |
+
return True, "Video file is valid"
|
| 988 |
+
else:
|
| 989 |
+
return False, "Unable to open video file - may be corrupted"
|
| 990 |
+
except Exception as e:
|
| 991 |
+
return False, f"Error validating video: {str(e)}"
|
| 992 |
|