refactor(main.py): update memory estimation for video preloading based on frame dimensions

This commit is contained in:
2025-09-04 21:52:48 +02:00
parent fa89b41355
commit 30cdd9d0e5

26
main.py
View File

@@ -492,20 +492,32 @@ class MediaGrader:
# Safety check for huge videos # Safety check for huge videos
safe_frame_count = max(1, int(self.total_frames * 0.6)) 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 # Calculate actual memory usage based on frame dimensions
print(f"Video too large for preloading! {safe_frame_count} frames would use ~{estimated_mb}GB RAM") frame_width = int(self.current_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
print("Multi-segment mode not available for videos longer than ~3 minutes") 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 return
elif safe_frame_count > 1000: # Warn for videos > ~30 seconds elif total_mb > 500: # 500MB warning
print(f"Large video detected: {safe_frame_count} frames will use ~{estimated_mb}MB RAM") 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...") print("Press any key to continue or 'q' to cancel...")
# Note: In a real implementation, you'd want proper input handling here # Note: In a real implementation, you'd want proper input handling here
start_time = time.time() start_time = time.time()
print(f"Setting up {self.segment_count} segments with video preloading...") 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: try:
print("Cleaning up existing captures...") print("Cleaning up existing captures...")