diff --git a/main.py b/main.py index e186a25..9ef4643 100644 --- a/main.py +++ b/main.py @@ -492,20 +492,32 @@ class MediaGrader: # 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") + # Calculate actual memory usage based on frame dimensions + frame_width = int(self.current_cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + frame_height = int(self.current_cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + bytes_per_frame = frame_width * frame_height * 3 # RGB (3 bytes per pixel) + total_bytes = safe_frame_count * bytes_per_frame + total_mb = total_bytes / (1024 * 1024) + total_gb = total_mb / 1024 + + # Memory-based limits (not frame count) + if total_gb > 8: # 8GB limit + print(f"Video too large for preloading!") + print(f" Resolution: {frame_width}x{frame_height}") + print(f" Frames: {safe_frame_count} frames would use {total_gb:.1f}GB RAM") + print(f"Multi-segment mode not available for videos requiring >8GB RAM") 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") + elif total_mb > 500: # 500MB warning + print(f"Large video detected:") + print(f" Resolution: {frame_width}x{frame_height}") + print(f" Memory: {safe_frame_count} frames will use {total_mb:.0f}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)") + print(f"Will preload {safe_frame_count} frames ({frame_width}x{frame_height}) = {total_mb:.0f}MB RAM") try: print("Cleaning up existing captures...")