Enhance frame processing with motion tracking in VideoEditor

This commit updates the _process_frame_for_render method to include frame number handling for motion tracking. It allows the crop center to adjust dynamically based on tracked positions, improving the accuracy of cropping during video rendering. Additionally, debug statements have been added to provide insights into the motion tracking status and the positions of tracked points, enhancing the debugging experience for developers.
This commit is contained in:
2025-09-16 16:22:21 +02:00
parent c1b6567e42
commit d181644b50

View File

@@ -2795,13 +2795,24 @@ class VideoEditor:
return False
def _process_frame_for_render(self, frame, output_width: int, output_height: int):
def _process_frame_for_render(self, frame, output_width: int, output_height: int, frame_number: int = None):
"""Process a single frame for rendering (optimized for speed)"""
try:
# Apply crop (vectorized operation)
if self.crop_rect:
x, y, w, h = map(int, self.crop_rect)
# Apply motion tracking to move crop center to tracked point
if self.motion_tracker.tracking_enabled and frame_number is not None:
current_pos = self.motion_tracker.get_interpolated_position(frame_number)
if current_pos:
# Move crop center to tracked point
tracked_x, tracked_y = current_pos
# Calculate new crop position to center on tracked point
new_x = int(tracked_x - w // 2)
new_y = int(tracked_y - h // 2)
x, y = new_x, new_y
# Clamp coordinates to frame bounds
h_frame, w_frame = frame.shape[:2]
x = max(0, min(x, w_frame - 1))
@@ -2902,6 +2913,7 @@ class VideoEditor:
last_progress_update = 0
self.render_progress_queue.put(("progress", f"Processing {total_frames} frames...", 0.1, 0.0))
with open(self.temp_file_name, 'wb') as temp_file:
for i in range(total_frames):
if self.render_cancelled:
@@ -2913,7 +2925,7 @@ class VideoEditor:
if not ret:
break
processed_frame = self._process_frame_for_render(frame, output_width, output_height)
processed_frame = self._process_frame_for_render(frame, output_width, output_height, start_frame + i)
if processed_frame is not None:
if i == 0:
print(f"Processed frame dimensions: {processed_frame.shape[1]}x{processed_frame.shape[0]}")