fix: 字幕居中bug修复,BGM声音太小bug修复,默认system prompt微调 - 强化旁白字数控制
- composer.py: BGM音量调整为0.45,禁用ducking压缩 - ffmpeg_utils.py: 字幕居中修复,多行字幕每行单独居中 - script_gen.py: 清理调试代码
This commit is contained in:
@@ -524,29 +524,44 @@ def add_multiple_subtitles(
|
||||
fontcolor = style.get("fontcolor", "white")
|
||||
borderw = style.get("borderw", 3)
|
||||
bordercolor = style.get("bordercolor", "black")
|
||||
x = style.get("x", "(w-text_w)/2")
|
||||
y = style.get("y", "h-200")
|
||||
base_y = style.get("y", "h-200")
|
||||
|
||||
# 默认启用背景框以提高可读性
|
||||
box = style.get("box", 1)
|
||||
boxcolor = style.get("boxcolor", "black@0.5")
|
||||
boxborderw = style.get("boxborderw", 10)
|
||||
|
||||
# 转义:反斜杠、单引号、冒号、百分号
|
||||
escaped_text = text.replace("\\", "\\\\").replace("'", "\\'").replace(":", "\\:").replace("%", "\\%")
|
||||
# 多行字幕:拆分成多个 drawtext 滤镜,每行单独居中
|
||||
lines = text.split("\n") if "\n" in text else [text]
|
||||
line_height = int(fontsize * 1.3) # 行高
|
||||
|
||||
drawtext = (
|
||||
f"drawtext=text='{escaped_text}':"
|
||||
f"fontfile='{font}':"
|
||||
f"fontsize={fontsize}:"
|
||||
f"fontcolor={fontcolor}:"
|
||||
f"borderw={borderw}:"
|
||||
f"bordercolor={bordercolor}:"
|
||||
f"box={box}:boxcolor={boxcolor}:boxborderw={boxborderw}:"
|
||||
f"x={x}:y={y}:"
|
||||
f"enable='between(t,{start},{start + duration})'"
|
||||
)
|
||||
filters.append(drawtext)
|
||||
for line_idx, line in enumerate(lines):
|
||||
if not line.strip():
|
||||
continue
|
||||
|
||||
# 转义:反斜杠、单引号、冒号、百分号
|
||||
escaped_line = line.replace("\\", "\\\\").replace("'", "\\'").replace(":", "\\:").replace("%", "\\%")
|
||||
|
||||
# 计算每行的 y 位置(从底部往上排列)
|
||||
# base_y 是最后一行的位置,往上依次排列
|
||||
line_offset = (len(lines) - 1 - line_idx) * line_height
|
||||
if isinstance(base_y, str) and base_y.startswith("h-"):
|
||||
y_expr = f"({base_y})-{line_offset}"
|
||||
else:
|
||||
y_expr = f"({base_y})-{line_offset}"
|
||||
|
||||
drawtext = (
|
||||
f"drawtext=text='{escaped_line}':"
|
||||
f"fontfile='{font}':"
|
||||
f"fontsize={fontsize}:"
|
||||
f"fontcolor={fontcolor}:"
|
||||
f"borderw={borderw}:"
|
||||
f"bordercolor={bordercolor}:"
|
||||
f"box={box}:boxcolor={boxcolor}:boxborderw={boxborderw}:"
|
||||
f"x=(w-text_w)/2:y={y_expr}:" # 每行都水平居中
|
||||
f"enable='between(t,{start},{start + duration})'"
|
||||
)
|
||||
filters.append(drawtext)
|
||||
|
||||
# 用逗号连接多个 filter
|
||||
vf = ",".join(filters)
|
||||
@@ -809,6 +824,16 @@ def add_bgm(
|
||||
bgm_volume: BGM音量
|
||||
loop: 是否循环BGM
|
||||
"""
|
||||
# 验证 BGM 文件存在
|
||||
if not bgm_path or not os.path.exists(bgm_path):
|
||||
logger.error(f"BGM file not found: {bgm_path}")
|
||||
# 直接复制原视频,不添加 BGM
|
||||
import shutil
|
||||
shutil.copy(video_path, output_path)
|
||||
return output_path
|
||||
|
||||
logger.info(f"Adding BGM: {bgm_path} (volume={bgm_volume})")
|
||||
|
||||
info = get_video_info(video_path)
|
||||
video_duration = info["duration"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user