Update core/app.py
Browse files- core/app.py +21 -0
core/app.py
CHANGED
|
@@ -93,6 +93,24 @@ def __init__(self):
|
|
| 93 |
|
| 94 |
logger.info(f"VideoProcessor initialized on device: {self.device_manager.get_optimal_device()}")
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
def load_models(self, progress_callback: Optional[Callable] = None) -> str:
|
| 97 |
"""Load and validate all AI models"""
|
| 98 |
with self.loading_lock:
|
|
@@ -165,6 +183,9 @@ def process_video(
|
|
| 165 |
if self.cancel_event.is_set():
|
| 166 |
return None, "Processing cancelled"
|
| 167 |
|
|
|
|
|
|
|
|
|
|
| 168 |
# Validate input file
|
| 169 |
is_valid, validation_msg = validate_video_file(video_path)
|
| 170 |
if not is_valid:
|
|
|
|
| 93 |
|
| 94 |
logger.info(f"VideoProcessor initialized on device: {self.device_manager.get_optimal_device()}")
|
| 95 |
|
| 96 |
+
def _initialize_progress_tracker(self, video_path: str, progress_callback: Optional[Callable] = None):
|
| 97 |
+
"""Initialize progress tracker with video frame count"""
|
| 98 |
+
try:
|
| 99 |
+
import cv2
|
| 100 |
+
cap = cv2.VideoCapture(video_path)
|
| 101 |
+
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 102 |
+
cap.release()
|
| 103 |
+
|
| 104 |
+
if total_frames <= 0:
|
| 105 |
+
total_frames = 100 # Fallback estimate
|
| 106 |
+
|
| 107 |
+
self.progress_tracker = ProgressTracker(total_frames, progress_callback)
|
| 108 |
+
logger.info(f"Progress tracker initialized for {total_frames} frames")
|
| 109 |
+
except Exception as e:
|
| 110 |
+
logger.warning(f"Could not initialize progress tracker: {e}")
|
| 111 |
+
# Fallback to basic tracker
|
| 112 |
+
self.progress_tracker = ProgressTracker(100, progress_callback)
|
| 113 |
+
|
| 114 |
def load_models(self, progress_callback: Optional[Callable] = None) -> str:
|
| 115 |
"""Load and validate all AI models"""
|
| 116 |
with self.loading_lock:
|
|
|
|
| 183 |
if self.cancel_event.is_set():
|
| 184 |
return None, "Processing cancelled"
|
| 185 |
|
| 186 |
+
# Initialize progress tracker with video frame count
|
| 187 |
+
self._initialize_progress_tracker(video_path, progress_callback)
|
| 188 |
+
|
| 189 |
# Validate input file
|
| 190 |
is_valid, validation_msg = validate_video_file(video_path)
|
| 191 |
if not is_valid:
|