quality: CRF 18 on all encode steps, Lanczos resampling on resizes
Re-encode passes (vertical render, hooks, subtitles, AI effects) ran at CRF 22-23, stacking visible generation loss across steps (#13). Bump all of them to CRF 18; post-process steps also move preset fast -> medium (the realtime reframe pipe keeps fast to not slow the streamed encode). OpenCV resizes now use INTER_LANCZOS4 for sharper scaling. Adopted from PR #14 review (the good parts, rebased on current main).
This commit is contained in:
parent
b1113d7a3f
commit
f791a74807
4 changed files with 9 additions and 9 deletions
|
|
@ -340,7 +340,7 @@ class VideoEditor:
|
|||
'ffmpeg', '-y',
|
||||
'-i', input_path,
|
||||
'-vf', filter_string,
|
||||
'-c:v', 'libx264', '-preset', 'fast', '-crf', '22',
|
||||
'-c:v', 'libx264', '-preset', 'medium', '-crf', '18',
|
||||
'-c:a', 'copy',
|
||||
output_path
|
||||
]
|
||||
|
|
|
|||
2
hooks.py
2
hooks.py
|
|
@ -222,7 +222,7 @@ def add_hook_to_video(video_path, text, output_path, position="top", font_scale=
|
|||
'-filter_complex', f"[0:v][1:v]overlay={overlay_x}:{overlay_y}"
|
||||
+ (f":enable='between(t,0,{float(duration)})'" if duration else ""),
|
||||
'-c:a', 'copy',
|
||||
'-c:v', 'libx264', '-preset', 'fast', '-crf', '22',
|
||||
'-c:v', 'libx264', '-preset', 'medium', '-crf', '18',
|
||||
output_path
|
||||
]
|
||||
|
||||
|
|
|
|||
12
main.py
12
main.py
|
|
@ -346,14 +346,14 @@ def create_general_frame(frame, output_width, output_height):
|
|||
# Crop center to aspect ratio
|
||||
bg_scale = output_height / orig_h
|
||||
bg_w = int(orig_w * bg_scale)
|
||||
bg_resized = cv2.resize(frame, (bg_w, output_height))
|
||||
bg_resized = cv2.resize(frame, (bg_w, output_height), interpolation=cv2.INTER_LANCZOS4)
|
||||
|
||||
# Crop center of background
|
||||
start_x = (bg_w - output_width) // 2
|
||||
if start_x < 0: start_x = 0
|
||||
background = bg_resized[:, start_x:start_x+output_width]
|
||||
if background.shape[1] != output_width:
|
||||
background = cv2.resize(background, (output_width, output_height))
|
||||
background = cv2.resize(background, (output_width, output_height), interpolation=cv2.INTER_LANCZOS4)
|
||||
|
||||
# Blur background
|
||||
background = cv2.GaussianBlur(background, (51, 51), 0)
|
||||
|
|
@ -361,7 +361,7 @@ def create_general_frame(frame, output_width, output_height):
|
|||
# 2. Foreground (Fit Width)
|
||||
scale = output_width / orig_w
|
||||
fg_h = int(orig_h * scale)
|
||||
foreground = cv2.resize(frame, (output_width, fg_h))
|
||||
foreground = cv2.resize(frame, (output_width, fg_h), interpolation=cv2.INTER_LANCZOS4)
|
||||
|
||||
# 3. Overlay
|
||||
y_offset = (output_height - fg_h) // 2
|
||||
|
|
@ -636,7 +636,7 @@ def process_video_to_vertical(input_video, final_output_video):
|
|||
'ffmpeg', '-y', '-f', 'rawvideo', '-vcodec', 'rawvideo',
|
||||
'-s', f'{OUTPUT_WIDTH}x{OUTPUT_HEIGHT}', '-pix_fmt', 'bgr24',
|
||||
'-r', str(fps), '-i', '-', '-c:v', 'libx264',
|
||||
'-preset', 'fast', '-crf', '23', '-an', temp_video_output
|
||||
'-preset', 'fast', '-crf', '18', '-an', temp_video_output
|
||||
]
|
||||
|
||||
ffmpeg_process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||
|
|
@ -701,9 +701,9 @@ def process_video_to_vertical(input_video, final_output_video):
|
|||
# Crop
|
||||
if y2 > y1 and x2 > x1:
|
||||
cropped = frame[y1:y2, x1:x2]
|
||||
output_frame = cv2.resize(cropped, (OUTPUT_WIDTH, OUTPUT_HEIGHT))
|
||||
output_frame = cv2.resize(cropped, (OUTPUT_WIDTH, OUTPUT_HEIGHT), interpolation=cv2.INTER_LANCZOS4)
|
||||
else:
|
||||
output_frame = cv2.resize(frame, (OUTPUT_WIDTH, OUTPUT_HEIGHT))
|
||||
output_frame = cv2.resize(frame, (OUTPUT_WIDTH, OUTPUT_HEIGHT), interpolation=cv2.INTER_LANCZOS4)
|
||||
|
||||
ffmpeg_process.stdin.write(output_frame.tobytes())
|
||||
frame_number += 1
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ def burn_subtitles(video_path, srt_path, output_path, alignment=2, fontsize=16,
|
|||
'-i', video_path,
|
||||
'-vf', f"subtitles='{safe_srt_path}':force_style='{style_string}'",
|
||||
'-c:a', 'copy',
|
||||
'-c:v', 'libx264', '-preset', 'fast', '-crf', '23',
|
||||
'-c:v', 'libx264', '-preset', 'medium', '-crf', '18',
|
||||
output_path
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue