fix: resolve logo distortion, uncrop view buttons, and fix portrait video rotation garbage

This commit is contained in:
fiatcode 2026-02-28 08:43:59 +07:00
parent 61493533c0
commit 66e4472030
2 changed files with 26 additions and 15 deletions

View file

@ -52,11 +52,10 @@ class WelcomeScreen(Screen):
} }
#logo { #logo {
text-align: center;
color: $text; color: $text;
text-style: bold; text-style: bold;
margin-bottom: 2; margin-bottom: 2;
width: 100%; width: auto;
} }
.form-row { .form-row {
@ -104,6 +103,7 @@ class WelcomeScreen(Screen):
with Center(): with Center():
with Middle(): with Middle():
with Vertical(id="app-container"): with Vertical(id="app-container"):
with Center():
yield Static(LOGO, id="logo") yield Static(LOGO, id="logo")
with Horizontal(classes="form-row"): with Horizontal(classes="form-row"):
@ -362,11 +362,11 @@ class FaceSelectionScreen(Screen):
} }
.face-checkbox { .face-checkbox {
width: 80%; width: 1fr;
} }
.view-btn { .view-btn {
min-width: 8; width: auto;
margin-left: 2; margin-left: 2;
} }

View file

@ -189,6 +189,19 @@ def encode_video(
bitrate = video_info["bitrate"] bitrate = video_info["bitrate"]
total_frames = video_info["total_frames"] total_frames = video_info["total_frames"]
# Open input video to get actual frame dimensions and begin reading
cap = cv2.VideoCapture(str(input_path))
if not cap.isOpened():
raise RuntimeError(f"Could not open video: {input_path}")
# Read first frame to correctly handle rotation metadata from phone videos
ret, first_frame = cap.read()
if not ret:
raise RuntimeError("Could not read first frame to determine dimensions.")
# Override width/height from ffprobe with actual numpy array dimensions
height, width = first_frame.shape[:2]
# Build FFmpeg encode command # Build FFmpeg encode command
ffmpeg_cmd = [ ffmpeg_cmd = [
"ffmpeg", "ffmpeg",
@ -225,11 +238,6 @@ def encode_video(
] ]
) )
# Open input video
cap = cv2.VideoCapture(str(input_path))
if not cap.isOpened():
raise RuntimeError(f"Could not open video: {input_path}")
# Start FFmpeg process # Start FFmpeg process
proc = subprocess.Popen( proc = subprocess.Popen(
ffmpeg_cmd, ffmpeg_cmd,
@ -240,11 +248,8 @@ def encode_video(
try: try:
frame_idx = 0 frame_idx = 0
frame = first_frame
while True: while True:
ret, frame = cap.read()
if not ret:
break
# Get bboxes for this frame (exact or interpolated) # Get bboxes for this frame (exact or interpolated)
face_bboxes = get_bboxes_for_frame( face_bboxes = get_bboxes_for_frame(
frame_idx, frame_idx,
@ -257,12 +262,18 @@ def encode_video(
frame = apply_blur(frame, bbox, method=blur_method) frame = apply_blur(frame, bbox, method=blur_method)
# Write frame to FFmpeg # Write frame to FFmpeg
if proc.stdin:
proc.stdin.write(frame.tobytes()) proc.stdin.write(frame.tobytes())
frame_idx += 1 frame_idx += 1
if progress_callback and total_frames > 0: if progress_callback and total_frames > 0:
progress_callback(frame_idx, total_frames) progress_callback(frame_idx, total_frames)
# Read next frame
ret, frame = cap.read()
if not ret:
break
finally: finally:
cap.release() cap.release()
if proc.stdin: if proc.stdin: