feat(main.py): add safety checks for large videos to prevent excessive memory usage

This commit is contained in:
2025-09-04 21:51:25 +02:00
parent 24c8021bd3
commit fa89b41355

19
main.py
View File

@@ -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