refactor(main.py): optimize video processing by seeking once and reading sequentially to improve performance
This commit is contained in:
@@ -1587,10 +1587,13 @@ class VideoEditor:
|
|||||||
self.render_progress_queue.put(("error", "Could not open video writer!", 1.0, 0.0))
|
self.render_progress_queue.put(("error", "Could not open video writer!", 1.0, 0.0))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Simple sequential processing - the I/O is the bottleneck anyway
|
# Optimized sequential processing - seek once, then read sequentially
|
||||||
total_output_frames = end_frame - start_frame + 1
|
total_output_frames = end_frame - start_frame + 1
|
||||||
last_progress_update = 0
|
last_progress_update = 0
|
||||||
|
|
||||||
|
# Seek once to the start frame
|
||||||
|
render_cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
|
||||||
|
|
||||||
for frame_idx in range(start_frame, end_frame + 1):
|
for frame_idx in range(start_frame, end_frame + 1):
|
||||||
# Check for cancellation
|
# Check for cancellation
|
||||||
if self.render_cancelled:
|
if self.render_cancelled:
|
||||||
@@ -1598,8 +1601,7 @@ class VideoEditor:
|
|||||||
self.render_progress_queue.put(("cancelled", "Render cancelled", 0.0, 0.0))
|
self.render_progress_queue.put(("cancelled", "Render cancelled", 0.0, 0.0))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Read frame using the separate VideoCapture
|
# Read frame sequentially
|
||||||
render_cap.set(cv2.CAP_PROP_POS_FRAMES, frame_idx)
|
|
||||||
ret, frame = render_cap.read()
|
ret, frame = render_cap.read()
|
||||||
|
|
||||||
if not ret:
|
if not ret:
|
||||||
|
Reference in New Issue
Block a user