Refactor video frame scaling logic in VideoEditor to simplify resizing process
This commit removes redundant checks for scaling dimensions and ensures that the video frame is resized correctly while maintaining the aspect ratio. The logic is streamlined to enhance clarity and efficiency in the resizing process, improving overall performance during video editing.
This commit is contained in:
@@ -2907,24 +2907,10 @@ class VideoEditor:
|
|||||||
scale_y = available_height / height
|
scale_y = available_height / height
|
||||||
scale = min(scale_x, scale_y) # Use the smaller scale to ensure video fits
|
scale = min(scale_x, scale_y) # Use the smaller scale to ensure video fits
|
||||||
|
|
||||||
# Ensure scale is never greater than 1.0 to prevent upscaling beyond screen
|
|
||||||
scale = min(scale, 1.0)
|
|
||||||
|
|
||||||
# Calculate scaled dimensions
|
# Calculate scaled dimensions
|
||||||
scaled_width = int(width * scale)
|
scaled_width = int(width * scale)
|
||||||
scaled_height = int(height * scale)
|
scaled_height = int(height * scale)
|
||||||
|
|
||||||
# Double-check that scaled dimensions fit within available space
|
|
||||||
if scaled_height > available_height:
|
|
||||||
scale = available_height / height
|
|
||||||
scaled_width = int(width * scale)
|
|
||||||
scaled_height = int(height * scale)
|
|
||||||
|
|
||||||
if scaled_width > actual_width:
|
|
||||||
scale = actual_width / width
|
|
||||||
scaled_width = int(width * scale)
|
|
||||||
scaled_height = int(height * scale)
|
|
||||||
|
|
||||||
# Resize the frame to fit the window while maintaining aspect ratio
|
# Resize the frame to fit the window while maintaining aspect ratio
|
||||||
if scale != 1.0:
|
if scale != 1.0:
|
||||||
display_frame = cv2.resize(display_frame, (scaled_width, scaled_height), interpolation=cv2.INTER_LINEAR)
|
display_frame = cv2.resize(display_frame, (scaled_width, scaled_height), interpolation=cv2.INTER_LINEAR)
|
||||||
|
Reference in New Issue
Block a user