Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

feat: support reading subtitle position from config file

duchangyu3be3c4a98f16
diff --git a/app/models/schema.py b/app/models/schema.py
index e61504e1..1cecc1d5 100644
--- a/app/models/schema.py
+++ b/app/models/schema.py
@@ -93,7 +93,7 @@ class VideoParams(BaseModel):
bgm_volume: Optional[float] = 0.2
subtitle_enabled: Optional[bool] = True
- subtitle_position: Optional[str] = "bottom" # top, bottom, center
+ subtitle_position: Optional[str] = "bottom" # top, bottom, center, custom
custom_position: float = 70.0
font_name: Optional[str] = "STHeitiMedium.ttc"
text_fore_color: Optional[str] = "#FFFFFF"
diff --git a/config.example.toml b/config.example.toml
index 5f77f42d..88978e9f 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -221,3 +221,10 @@ api_key = ""
# 是否隐藏日志信息
# Whether to hide logs in the UI
hide_log = false
+
+# 字幕位置设置 (Subtitle position settings)
+# 可选值 (Available values): "top", "center", "bottom", "custom"
+# subtitle_position = "custom"
+# 自定义位置,表示离顶部的百分比 (0-100),仅当 subtitle_position = "custom" 时生效
+# Custom position as percentage from top (0-100), only effective when subtitle_position = "custom"
+# custom_position = 70.0
diff --git a/webui/Main.py b/webui/Main.py
index 5863a484..52e6335e 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -886,24 +886,34 @@ with right_panel:
(tr("Bottom"), "bottom"),
(tr("Custom"), "custom"),
]
+ saved_subtitle_position = config.ui.get("subtitle_position", "bottom")
+ saved_position_index = 2
+ for i, (_, pos_value) in enumerate(subtitle_positions):
+ if pos_value == saved_subtitle_position:
+ saved_position_index = i
+ break
selected_index = st.selectbox(
tr("Position"),
- index=2,
+ index=saved_position_index,
options=range(len(subtitle_positions)),
format_func=lambda x: subtitle_positions[x][0],
)
params.subtitle_position = subtitle_positions[selected_index][1]
+ config.ui["subtitle_position"] = params.subtitle_position
if params.subtitle_position == "custom":
+ saved_custom_position = config.ui.get("custom_position", 70.0)
custom_position = st.text_input(
tr("Custom Position (% from top)"),
- value="70.0",
+ value=str(saved_custom_position),
key="custom_position_input",
)
try:
params.custom_position = float(custom_position)
if params.custom_position < 0 or params.custom_position > 100:
st.error(tr("Please enter a value between 0 and 100"))
+ else:
+ config.ui["custom_position"] = params.custom_position
except ValueError:
st.error(tr("Please enter a valid number"))