Refactor video scaling logic in VideoEditor to improve display handling
This commit updates the video scaling logic to ensure that videos are scaled down to fit the screen bounds instead of resizing the window. The previous logic for window resizing has been removed, streamlining the display process and enhancing the user experience during video editing sessions. The changes also include adjustments to maintain the aspect ratio of the video while scaling.
This commit is contained in:
@@ -3071,39 +3071,19 @@ class VideoEditor:
|
|||||||
height, width = display_frame.shape[:2]
|
height, width = display_frame.shape[:2]
|
||||||
available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT)
|
available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT)
|
||||||
|
|
||||||
# Don't downscale - keep original video quality
|
# Scale video to fit screen bounds
|
||||||
# If video is larger than window, we'll handle it by resizing the window
|
|
||||||
scale = min(self.window_width / width, available_height / height)
|
scale = min(self.window_width / width, available_height / height)
|
||||||
if scale < 1.0:
|
if scale < 1.0:
|
||||||
# Resize window to fit video instead of downscaling video
|
# Scale down video to fit screen
|
||||||
new_window_width = int(width * 1.1) # Add 10% padding
|
new_width = int(width * scale)
|
||||||
new_window_height = int(height * 1.1) + (0 if self.is_image_mode else self.TIMELINE_HEIGHT)
|
new_height = int(height * scale)
|
||||||
|
display_frame = cv2.resize(display_frame, (new_width, new_height), interpolation=cv2.INTER_LINEAR)
|
||||||
# Update window size
|
|
||||||
self.window_width = new_window_width
|
|
||||||
self.window_height = new_window_height
|
|
||||||
|
|
||||||
# Resize the OpenCV window
|
|
||||||
window_title = "Image Editor" if self.is_image_mode else "Video Editor"
|
|
||||||
cv2.resizeWindow(window_title, self.window_width, self.window_height)
|
|
||||||
|
|
||||||
# Create canvas with timeline space
|
# Create canvas with timeline space
|
||||||
canvas = np.zeros((self.window_height, self.window_width, 3), dtype=np.uint8)
|
canvas = np.zeros((self.window_height, self.window_width, 3), dtype=np.uint8)
|
||||||
|
|
||||||
# Center the frame on canvas
|
# Center the frame on canvas
|
||||||
frame_height, frame_width = display_frame.shape[:2]
|
frame_height, frame_width = display_frame.shape[:2]
|
||||||
available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT)
|
|
||||||
|
|
||||||
# Simple fullscreen fix: scale down if video is too large for screen
|
|
||||||
if self.is_fullscreen and (frame_height > available_height or frame_width > self.window_width):
|
|
||||||
scale_x = self.window_width / frame_width
|
|
||||||
scale_y = available_height / frame_height
|
|
||||||
scale = min(scale_x, scale_y)
|
|
||||||
if scale < 1.0:
|
|
||||||
new_width = int(frame_width * scale)
|
|
||||||
new_height = int(frame_height * scale)
|
|
||||||
display_frame = cv2.resize(display_frame, (new_width, new_height), interpolation=cv2.INTER_LINEAR)
|
|
||||||
frame_height, frame_width = display_frame.shape[:2]
|
|
||||||
|
|
||||||
start_y = (available_height - frame_height) // 2
|
start_y = (available_height - frame_height) // 2
|
||||||
start_x = (self.window_width - frame_width) // 2
|
start_x = (self.window_width - frame_width) // 2
|
||||||
|
Reference in New Issue
Block a user