import cv2 from config import MIN_FPS_THRESHOLD class VideoService: @staticmethod def verify_integrity(video_path: str): """ Standardizes video metadata extraction and quality auditing. Includes specific FPS feedback in warnings [cite: 2026-02-27]. """ cap = cv2.VideoCapture(video_path) if not cap.isOpened(): return {"valid": False, "error": "Could not open video file."} fps = cap.get(cv2.CAP_PROP_FPS) frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # 🛡️ BRUTE FORCE FALLBACK if frame_count <= 0: frame_count = 0 while True: ret, _ = cap.read() if not ret: break frame_count += 1 cap.set(cv2.CAP_PROP_POS_FRAMES, 0) if fps < 5 or fps > 120: fps = 30.0 duration = frame_count / fps if fps > 0 else 0 # ⚖️ CLINICAL CONFIDENCE AUDIT is_suboptimal = fps < MIN_FPS_THRESHOLD status_label = "SUBOPTIMAL" if is_suboptimal else "OPTIMAL" cap.release() # 🎯 Dynamic Warning with detected FPS warning = None if is_suboptimal: warning = f"Low frame rate ({round(fps, 1)} FPS) detected. Ocular synchronization may be less precise." return { "valid": True, "fps": round(fps, 2), "frame_count": frame_count, "duration": round(duration, 2), "status": status_label, "warning": warning }