File size: 1,604 Bytes
408b7e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
        }