Skip to content

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

Add subtitle background controls

harry0703797b2a4d4bbd
diff --git a/test/services/test_subtitle_background_settings.py b/test/services/test_subtitle_background_settings.py
new file mode 100644
index 00000000..ff7c46aa
--- /dev/null
+++ b/test/services/test_subtitle_background_settings.py
@@ -0,0 +1,47 @@
+import json
+from pathlib import Path
+import unittest
+
+from app.models.schema import VideoParams
+
+
+class TestSubtitleBackgroundSettings(unittest.TestCase):
+ def test_all_locales_include_subtitle_background_labels(self):
+ """
+ WebUI 新增字幕背景开关和颜色选择器后,所有已有语言都必须包含对应
+ 翻译 key,避免某些语言界面直接显示英文内部 key。
+ """
+ i18n_dir = Path(__file__).parent.parent.parent / "webui" / "i18n"
+ required_keys = {
+ "Enable Subtitle Background",
+ "Subtitle Background Color",
+ }
+
+ for locale_file in i18n_dir.glob("*.json"):
+ with self.subTest(locale=locale_file.name):
+ data = json.loads(locale_file.read_text(encoding="utf-8"))
+ translations = data.get("Translation", {})
+ missing_keys = required_keys - translations.keys()
+
+ self.assertEqual(missing_keys, set())
+
+ def test_video_params_accepts_disabled_and_colored_subtitle_background(self):
+ """
+ UI 会根据开关向后端传递 False 或颜色字符串。这里验证 schema 仍然
+ 接受这两种值,避免后续依赖或类型调整破坏 WebUI 与合成逻辑的契约。
+ """
+ base_params = {
+ "video_subject": "subtitle background smoke",
+ }
+
+ disabled_params = VideoParams(
+ **base_params,
+ text_background_color=False,
+ )
+ colored_params = VideoParams(
+ **base_params,
+ text_background_color="#123456",
+ )
+
+ self.assertFalse(disabled_params.text_background_color)
+ self.assertEqual(colored_params.text_background_color, "#123456")
diff --git a/webui/Main.py b/webui/Main.py
index d0924e0b..a31b42b8 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -1139,15 +1139,49 @@ with right_panel:
params.stroke_color = st.color_picker(tr("Stroke Color"), "#000000")
with stroke_cols[1]:
params.stroke_width = st.slider(tr("Stroke Width"), 0.0, 10.0, 1.5)
+
+ subtitle_bg_cols = st.columns([0.4, 0.6])
+ saved_subtitle_background_enabled = config.ui.get(
+ "subtitle_background_enabled", True
+ )
+ with subtitle_bg_cols[0]:
+ subtitle_background_enabled = st.checkbox(
+ tr("Enable Subtitle Background"),
+ value=saved_subtitle_background_enabled,
+ )
+ config.ui["subtitle_background_enabled"] = subtitle_background_enabled
+ if subtitle_background_enabled:
+ with subtitle_bg_cols[1]:
+ saved_subtitle_background_color = config.ui.get(
+ "subtitle_background_color", "#000000"
+ )
+ params.text_background_color = st.color_picker(
+ tr("Subtitle Background Color"),
+ saved_subtitle_background_color,
+ )
+ config.ui["subtitle_background_color"] = params.text_background_color
+ else:
+ params.text_background_color = False
+
saved_rounded_subtitle_background = config.ui.get(
"rounded_subtitle_background", False
)
+ # 背景关闭时,圆角背景没有可渲染的底色。这里禁用控件并保留原配置,
+ # 用户下次重新开启字幕背景后,可以继续使用之前保存的圆角偏好。
params.rounded_subtitle_background = st.checkbox(
tr("Rounded Subtitle Background"),
- value=saved_rounded_subtitle_background,
+ value=(
+ saved_rounded_subtitle_background
+ if subtitle_background_enabled
+ else False
+ ),
help=tr("Rounded Subtitle Background Help"),
+ disabled=not subtitle_background_enabled,
)
- config.ui["rounded_subtitle_background"] = params.rounded_subtitle_background
+ if subtitle_background_enabled:
+ config.ui["rounded_subtitle_background"] = (
+ params.rounded_subtitle_background
+ )
with st.expander(tr("Click to show API Key management"), expanded=False):
st.subheader(tr("Manage Pexels and Pixabay API Keys"))
diff --git a/webui/i18n/de.json b/webui/i18n/de.json
index 49ca3e9c..3ea67aea 100644
--- a/webui/i18n/de.json
+++ b/webui/i18n/de.json
@@ -74,6 +74,8 @@
"Font Color": "Schriftfarbe",
"Stroke Color": "Kontur",
"Stroke Width": "Breite der Untertitelkontur",
+ "Enable Subtitle Background": "Untertitelhintergrund aktivieren",
+ "Subtitle Background Color": "Farbe des Untertitelhintergrunds",
"Rounded Subtitle Background": "Abgerundeten halbtransparenten Untertitelhintergrund aktivieren",
"Rounded Subtitle Background Help": "Standardmäßig deaktiviert. Wenn aktiviert, verwenden Untertitelhintergründe einen abgerundeten, halbtransparenten Stil, der sich besser an die Textbreite anpasst.",
"Generate Video": "Generiere Videos durch KI",
diff --git a/webui/i18n/en.json b/webui/i18n/en.json
index e289dc6d..48b83bbf 100644
--- a/webui/i18n/en.json
+++ b/webui/i18n/en.json
@@ -71,6 +71,8 @@
"Font Color": "Subtitle Font Color",
"Stroke Color": "Subtitle Outline Color",
"Stroke Width": "Subtitle Outline Width",
+ "Enable Subtitle Background": "Enable subtitle background",
+ "Subtitle Background Color": "Subtitle background color",
"Rounded Subtitle Background": "Enable rounded translucent subtitle background",
"Rounded Subtitle Background Help": "Disabled by default. When enabled, subtitle backgrounds use a rounded translucent style that better fits the text width.",
"Generate Video": "Generate Video",
diff --git a/webui/i18n/pt.json b/webui/i18n/pt.json
index 90c47c62..a9757209 100644
--- a/webui/i18n/pt.json
+++ b/webui/i18n/pt.json
@@ -62,6 +62,8 @@
"Font Color": "Cor da Fonte da Legenda",
"Stroke Color": "Cor do Contorno da Legenda",
"Stroke Width": "Largura do Contorno da Legenda",
+ "Enable Subtitle Background": "Ativar fundo da legenda",
+ "Subtitle Background Color": "Cor do fundo da legenda",
"Generate Video": "Gerar Vídeo",
"Video Script and Subject Cannot Both Be Empty": "O Tema do Vídeo e o Roteiro do Vídeo não podem estar ambos vazios",
"Generating Video": "Gerando vídeo, por favor aguarde...",
@@ -119,4 +121,4 @@
"Delete Selected Pixabay API Key": "Excluir chave de API do Pixabay selecionada",
"Pixabay API Key deleted successfully": "Chave de API do Pixabay excluída com sucesso"
}
-}
\ No newline at end of file
+}
diff --git a/webui/i18n/ru.json b/webui/i18n/ru.json
index 77b34ae1..c9175777 100644
--- a/webui/i18n/ru.json
+++ b/webui/i18n/ru.json
@@ -62,6 +62,8 @@
"Font Color": "Цвет шрифта субтитров",
"Stroke Color": "Цвет обводки субтитров",
"Stroke Width": "Ширина обводки субтитров",
+ "Enable Subtitle Background": "Включить фон субтитров",
+ "Subtitle Background Color": "Цвет фона субтитров",
"Generate Video": "Создать видео",
"Video Script and Subject Cannot Both Be Empty": "Тема и сценарий видео не могут быть пустыми одновременно",
"Generating Video": "Создание видео, пожалуйста подождите...",
diff --git a/webui/i18n/tr.json b/webui/i18n/tr.json
index 1de41d42..6aaedbfd 100644
--- a/webui/i18n/tr.json
+++ b/webui/i18n/tr.json
@@ -62,6 +62,8 @@
"Font Color": "Altyazı Font Rengi",
"Stroke Color": "Altyazı Çerçeve Rengi",
"Stroke Width": "Altyazı Çerçeve Kalınlığı",
+ "Enable Subtitle Background": "Altyazı arka planını etkinleştir",
+ "Subtitle Background Color": "Altyazı arka plan rengi",
"Generate Video": "Video Oluştur",
"Video Script and Subject Cannot Both Be Empty": "Video Konusu ve Video Senaryosu aynı anda boş olamaz",
"Generating Video": "Video oluşturuluyor, lütfen bekleyin...",
diff --git a/webui/i18n/vi.json b/webui/i18n/vi.json
index 4f852d30..363971fa 100644
--- a/webui/i18n/vi.json
+++ b/webui/i18n/vi.json
@@ -71,6 +71,8 @@
"Font Color": "Màu Chữ Phụ Đề",
"Stroke Color": "Màu Viền Phụ Đề",
"Stroke Width": "Độ Rộng Viền Phụ Đề",
+ "Enable Subtitle Background": "Bật nền phụ đề",
+ "Subtitle Background Color": "Màu nền phụ đề",
"Rounded Subtitle Background": "Bật nền phụ đề bo tròn, mờ trong suốt",
"Rounded Subtitle Background Help": "Mặc định tắt. Khi được bật, nền phụ đề sẽ dùng kiểu bo tròn mờ trong suốt, vừa khít với độ rộng của chữ.",
"Generate Video": "Tạo Video",
diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json
index 03a846f4..323934cc 100644
--- a/webui/i18n/zh.json
+++ b/webui/i18n/zh.json
@@ -71,6 +71,8 @@
"Font Color": "字幕颜色",
"Stroke Color": "描边颜色",
"Stroke Width": "描边粗细",
+ "Enable Subtitle Background": "启用字幕背景",
+ "Subtitle Background Color": "字幕背景颜色",
"Rounded Subtitle Background": "启用圆角半透明字幕背景",
"Rounded Subtitle Background Help": "默认关闭。开启后字幕背景会显示为更贴合文字宽度的圆角半透明样式。",
"Generate Video": "生成视频",