From fa89b41355e2d70c896c4ff61cbc5c8edb4dd452 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 4 Sep 2025 21:51:25 +0200 Subject: [PATCH] feat(main.py): add safety checks for large videos to prevent excessive memory usage --- main.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 655d569..e186a25 100644 --- a/main.py +++ b/main.py @@ -490,11 +490,24 @@ class MediaGrader: if not self.is_video(self.media_files[self.current_index]): return + # Safety check for huge videos + safe_frame_count = max(1, int(self.total_frames * 0.6)) + estimated_mb = safe_frame_count * 5 // 1024 # Rough estimate: 5MB per frame + + if safe_frame_count > 5000: # ~3 minutes at 30fps + print(f"Video too large for preloading! {safe_frame_count} frames would use ~{estimated_mb}GB RAM") + print("Multi-segment mode not available for videos longer than ~3 minutes") + return + elif safe_frame_count > 1000: # Warn for videos > ~30 seconds + print(f"Large video detected: {safe_frame_count} frames will use ~{estimated_mb}MB RAM") + print("Press any key to continue or 'q' to cancel...") + # Note: In a real implementation, you'd want proper input handling here + start_time = time.time() print(f"Setting up {self.segment_count} segments with video preloading...") + print(f"Will preload {safe_frame_count} frames (~{safe_frame_count * 5 // 1024}MB RAM)") try: - # Clean up existing segment captures print("Cleaning up existing captures...") self.cleanup_segment_captures() @@ -514,10 +527,6 @@ class MediaGrader: print("Error: Video has insufficient frames for multi-segment mode") return - # Use conservative frame range - safe_frame_count = max(1, int(self.total_frames * 0.6)) - print(f"Using safe frame count: {safe_frame_count} (60% of reported {self.total_frames})") - for i in range(self.segment_count): if self.segment_count <= 1: position_ratio = 0