Skip to content

PRINTFILM: AI short-video marketing and AI short-drama creation platform

Fix post-subtitle burn-in and fragment video version history.

yi9e7025bac8f4
diff --git a/backend/app/services/ark.py b/backend/app/services/ark.py
index f6f86e6..7fd15eb 100644
--- a/backend/app/services/ark.py
+++ b/backend/app/services/ark.py
@@ -968,7 +968,9 @@ class ArkGateway:
if result.url.startswith("/static/"):
video_local = result.url
else:
- dest = storage.project_dir(project_id) / f"shot_{shot_no:03d}.mp4"
+ # 每次生成独立文件名,避免覆盖旧成片导致历史版本失效
+ stamp = int(time.time())
+ dest = storage.project_dir(project_id) / f"shot_{shot_no:03d}_{stamp}.mp4"
await storage.download_to(result.url, dest)
video_local = storage.publish_local(dest)
@@ -978,7 +980,11 @@ class ArkGateway:
if result.last_frame_url.startswith("/static/"):
last_local = result.last_frame_url
else:
- frame_dest = storage.project_dir(project_id) / f"shot_{shot_no:03d}_last.jpg"
+ stamp = int(time.time())
+ frame_dest = (
+ storage.project_dir(project_id)
+ / f"shot_{shot_no:03d}_{stamp}_last.jpg"
+ )
await storage.download_to(result.last_frame_url, frame_dest)
last_local = storage.publish_local(frame_dest)
except Exception: # noqa: BLE001
diff --git a/backend/app/services/drama/build_seedance_generate_body.py b/backend/app/services/drama/build_seedance_generate_body.py
index f4a661c..c748d73 100644
--- a/backend/app/services/drama/build_seedance_generate_body.py
+++ b/backend/app/services/drama/build_seedance_generate_body.py
@@ -17,6 +17,7 @@ from app.services.drama.image_styles import resolve_image_style_prompt
from app.services.seedance_segments import (
build_seedance_production_section,
rewrite_misclassified_visual_voice_lines,
+ strip_model_burn_subtitle_cues,
)
ASSET_MENTION_TOKEN_PATTERN = re.compile(r"@asset:(\d+)")
@@ -54,6 +55,26 @@ class BuildSeedanceGenerateBodyInput(TypedDict, total=False):
duration_fallback: int | None
# 上一镜尾帧公网/本地 URL;有参考媒体时作 reference_image(不可与 first_frame 混用)
continuity_first_frame_url: str | None
+ # True=模型烧录字幕;False=后期叠字(禁止画面内字幕)
+ burn_subtitles: bool
+
+
+# 从分集 params 解析是否由模型烧录字幕(subtitleMode=post → False)
+def resolve_episode_burn_subtitles(params: dict[str, Any] | None) -> bool:
+ raw = params if isinstance(params, dict) else {}
+ mode = raw.get("subtitleMode")
+ if mode == "post":
+ return False
+ if mode == "model":
+ return True
+ enabled = raw.get("subtitleEnabled")
+ if enabled is None:
+ return True
+ if isinstance(enabled, str):
+ return enabled.strip().lower() not in {"0", "false", "no", "off", ""}
+ if isinstance(enabled, (int, float)):
+ return enabled != 0
+ return bool(enabled)
@dataclass
@@ -298,13 +319,18 @@ def build_seedance_prompt_text(
reference: list[dict[str, Any]] | None,
catalog: SeedanceReferenceCatalog | None = None,
video_style_id: str | None = None,
+ *,
+ burn_subtitles: bool = True,
) -> str:
# 提交前统一纠正空镜误标,保证强制约束与正文一致
normalized = rewrite_misclassified_visual_voice_lines(content or "")
+ if not burn_subtitles:
+ # 后期模式:去掉字幕 cue /「同步字幕」前缀,避免模型仍按字烧屏
+ normalized = strip_model_burn_subtitle_cues(normalized)
resolved_catalog = catalog or build_seedance_reference_catalog(reference)
sections = [
build_visual_style_section(video_style_id),
- build_seedance_production_section(normalized),
+ build_seedance_production_section(normalized, burn_subtitles=burn_subtitles),
build_reference_index_section(
reference,
"character",
@@ -348,9 +374,17 @@ def build_seedance_content_items(
reference: list[dict[str, Any]] | None,
video_style_id: str | None = None,
continuity_first_frame_url: str | None = None,
+ *,
+ burn_subtitles: bool = True,
) -> list[dict[str, Any]]:
catalog = build_seedance_reference_catalog(reference)
- prompt_text = build_seedance_prompt_text(content, reference, catalog, video_style_id)
+ prompt_text = build_seedance_prompt_text(
+ content,
+ reference,
+ catalog,
+ video_style_id,
+ burn_subtitles=burn_subtitles,
+ )
items: list[dict[str, Any]] = []
continuity = (continuity_first_frame_url or "").strip()
@@ -442,6 +476,9 @@ def build_seedance_generate_body(input_params: BuildSeedanceGenerateBodyInput) -
catalog = build_seedance_reference_catalog(reference)
# 仅「纯首帧、无参考媒体」时省略 ratio;混用参考时必须保留 ratio、且尾帧用 reference_image
use_first_frame_mode = bool(continuity) and not (catalog.images or catalog.audios)
+ burn_subtitles = input_params.get("burn_subtitles")
+ if burn_subtitles is None:
+ burn_subtitles = True
body: dict[str, Any] = {
"model": resolve_seedance_model_endpoint(input_params.get("model_id")),
@@ -450,11 +487,12 @@ def build_seedance_generate_body(input_params: BuildSeedanceGenerateBodyInput) -
reference,
input_params.get("video_style_id"),
continuity_first_frame_url=continuity,
+ burn_subtitles=bool(burn_subtitles),
),
"duration": resolve_seedance_duration_from_content(content, fallback=fallback),
"resolution": resolve_seedance_resolution(input_params.get("resolution")),
"watermark": False,
- # Seedance 原生配音+烧录字幕;关闭则仅有画面、无对白/BGM/字幕
+ # Seedance 原生配音;字幕是否烧录由 burn_subtitles 控制提示词
"generate_audio": True,
"return_last_frame": True,
}
diff --git a/backend/app/services/drama/generation.py b/backend/app/services/drama/generation.py
index e3d6f5f..010681c 100644
--- a/backend/app/services/drama/generation.py
+++ b/backend/app/services/drama/generation.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import logging
+import re
import time
from dataclasses import dataclass
from datetime import UTC, datetime
@@ -30,6 +31,7 @@ from app.services.drama.build_seedance_generate_body import (
describe_seedance_content_slots,
drama_asset_to_payload,
read_asset_voice_audio_url,
+ resolve_episode_burn_subtitles,
)
from app.services.drama.generation_prompt import build_generation_prompt
from app.services.drama.seedream_options import resolve_seedream_model_endpoint, resolve_seedream_size
@@ -237,8 +239,32 @@ def build_failed_generation_params(
return out
-# 分镜视频版本上限(含当前成片前归档的历史 take)
-FRAGMENT_VIDEO_VERSION_LIMIT = 5
+# 分镜视频版本上限(归档的历史 take,不含「当前」)
+FRAGMENT_VIDEO_VERSION_LIMIT = 8
+
+
+def _snapshot_version_media_url(url: str, *, label: str) -> str:
+ """把当前成片复制为独立历史文件,避免下次生成覆盖同路径导致版本失效。"""
+ from shutil import copy2
+
+ from app.services import storage as storage_svc
+
+ raw = (url or "").strip()
+ if not raw:
+ return ""
+ path = storage_svc.local_path_from_url(raw)
+ if path is None or not path.exists() or not path.is_file():
+ return raw
+ stem = path.stem
+ # 已是带时间戳/历史后缀的独立文件,无需再拷
+ if "_hist_" in stem or re.search(r"_\d{10,}$", stem):
+ published = storage_svc.republish_url(storage_svc.rel_static_url(path), sync=True)
+ return published or storage_svc.rel_static_url(path)
+ dest = path.with_name(f"{stem}_hist_{label}{path.suffix}")
+ if not dest.exists():
+ copy2(path, dest)
+ rel = storage_svc.rel_static_url(dest)
+ return storage_svc.republish_url(rel, sync=True) or rel
# 归档当前成片到 params.video_versions(覆盖前调用)
@@ -246,6 +272,7 @@ def archive_fragment_video_version(fragment: DramaEpisodeFragment) -> dict[str,
video = (fragment.video or "").strip()
if not video:
return None
+ import uuid
from datetime import datetime, timezone
params = dict(fragment.params or {}) if isinstance(fragment.params, dict) else {}
@@ -255,25 +282,30 @@ def archive_fragment_video_version(fragment: DramaEpisodeFragment) -> dict[str,
if isinstance(raw, str) and raw.strip():
last_frame = raw.strip()
break
+ stamp = f"{int(datetime.now(timezone.utc).timestamp())}_{uuid.uuid4().hex[:8]}"
+ archived_video = _snapshot_version_media_url(video, label=stamp)
+ archived_cover = _snapshot_version_media_url(
+ (fragment.cover or "").strip(),
+ label=f"{stamp}_cover",
+ )
+ archived_last = (
+ _snapshot_version_media_url(last_frame, label=f"{stamp}_last") if last_frame else None
+ )
entry = {
- "id": f"v_{int(datetime.now(timezone.utc).timestamp())}_{fragment.id}",
- "video": video,
- "cover": (fragment.cover or "").strip(),
- "lastFrameUrl": last_frame or None,
+ "id": f"v_{stamp}_{fragment.id}",
+ "video": archived_video,
+ "cover": archived_cover or (fragment.cover or "").strip(),
+ "lastFrameUrl": archived_last or last_frame or None,
"createdAt": datetime.now(timezone.utc).isoformat(),
"source": "generate",
}
versions = params.get("video_versions")
if not isinstance(versions, list):
versions = []
- # 去重:同一 video URL 不重复归档
- versions = [
- v
- for v in versions
- if isinstance(v, dict) and str(v.get("video") or "").strip() != video
- ]
- versions.insert(0, entry)
- params["video_versions"] = versions[:FRAGMENT_VIDEO_VERSION_LIMIT]
+ # 保留全部历史 take;不再按 URL 去重(固定 shot_xxx.mp4 会被覆盖,URL 相同会误删版本)
+ cleaned: list[dict[str, Any]] = [v for v in versions if isinstance(v, dict)]
+ cleaned.insert(0, entry)
+ params["video_versions"] = cleaned[:FRAGMENT_VIDEO_VERSION_LIMIT]
fragment.params = params
return entry
@@ -310,13 +342,22 @@ def activate_fragment_video_version(
if isinstance(raw, str) and raw.strip():
last_frame = raw.strip()
break
+ stamp = f"{int(datetime.now(timezone.utc).timestamp())}_{fragment.id}"
remaining.insert(
0,
{
- "id": f"v_{int(datetime.now(timezone.utc).timestamp())}_{fragment.id}",
- "video": current_video,
- "cover": (fragment.cover or "").strip(),
- "lastFrameUrl": last_frame or None,
+ "id": f"v_{stamp}_replaced",
+ "video": _snapshot_version_media_url(current_video, label=f"{stamp}_cur"),
+ "cover": _snapshot_version_media_url(
+ (fragment.cover or "").strip(),
+ label=f"{stamp}_cur_cover",
+ )
+ or (fragment.cover or "").strip(),
+ "lastFrameUrl": (
+ _snapshot_version_media_url(last_frame, label=f"{stamp}_cur_last")
+ if last_frame
+ else None
+ ),
"createdAt": datetime.now(timezone.utc).isoformat(),
"source": "replaced",
},
@@ -1147,6 +1188,7 @@ async def generate_fragment_video(
break
local_last_frame: str | None = None
+ burn_subtitles = resolve_episode_burn_subtitles(episode.params if episode else None)
if ref_payloads and (catalog.images or catalog.audios):
body = build_seedance_generate_body(
{
@@ -1157,6 +1199,7 @@ async def generate_fragment_video(
"resolution": resolution,
"duration_fallback": duration,
"continuity_first_frame_url": continuity_url,
+ "burn_subtitles": burn_subtitles,
}
)
content_labels = describe_seedance_content_slots(
@@ -1209,7 +1252,10 @@ async def generate_fragment_video(
# Seedance 成片落盘后立即同步 OSS,避免库里长期留 /static
from app.services import storage as storage_svc
+ from app.services.ffmpeg_compose import extract_video_poster_frame
+ # 覆盖前先归档旧成片(复制为独立 hist 文件)
+ archive_fragment_video_version(fragment)
video_url = storage_svc.republish_url(local_video, sync=True) or local_video
# 封面必须来自成片帧,禁止用角色/场景参考图冒充
cover_url = ""
@@ -1219,9 +1265,10 @@ async def generate_fragment_video(
if candidate.exists():
video_path = candidate
if video_path and video_path.exists():
- from app.services.ffmpeg_compose import extract_video_poster_frame
-
- poster_dest = storage_svc.project_dir(project.id) / f"shot_{fragment.id}_cover.jpg"
+ poster_dest = (
+ storage_svc.project_dir(project.id)
+ / f"shot_{fragment.id}_{int(time.time())}_cover.jpg"
+ )
if extract_video_poster_frame(video_path, poster_dest):
cover_src = storage_svc.rel_static_url(poster_dest)
cover_url = storage_svc.republish_url(cover_src, sync=True) or cover_src
@@ -1230,7 +1277,6 @@ async def generate_fragment_video(
last_frame_url = storage_svc.republish_url(local_last_frame, sync=True) or local_last_frame
if not cover_url:
cover_url = last_frame_url
- archive_fragment_video_version(fragment)
fragment.video = video_url
fragment.cover = cover_url or ""
write_fragment_last_frame_url(fragment, last_frame_url)
@@ -1372,6 +1418,9 @@ async def prepare_fragment_video_for_submit(
"resolution": resolution,
"duration_fallback": duration,
"continuity_first_frame_url": continuity_url,
+ "burn_subtitles": resolve_episode_burn_subtitles(
+ episode.params if episode else None
+ ),
}
)
return FragmentVideoPrepared(
@@ -1507,7 +1556,10 @@ async def apply_fragment_video_assets(
if candidate.exists():
video_path = candidate
if video_path and video_path.exists():
- poster_dest = storage_svc.project_dir(project.id) / f"shot_{fragment.id}_cover.jpg"
+ poster_dest = (
+ storage_svc.project_dir(project.id)
+ / f"shot_{fragment.id}_{int(time.time())}_cover.jpg"
+ )
if extract_video_poster_frame(video_path, poster_dest):
cover_src = storage_svc.rel_static_url(poster_dest)
cover_url = storage_svc.republish_url(cover_src, sync=True) or cover_src
diff --git a/backend/app/services/seedance_segments.py b/backend/app/services/seedance_segments.py
index d29ea18..f67ac1d 100644
--- a/backend/app/services/seedance_segments.py
+++ b/backend/app/services/seedance_segments.py
@@ -261,14 +261,44 @@ def build_production_cues(bgm_mood: str) -> list[str]:
return [SUBTITLE_CUE, f"【BGM:{mood}】"]
+# 后期字幕模式:提交前去掉烧录 cue /「同步字幕」前缀,避免模型仍按字烧屏。
+_POST_SUBTITLE_PREFIX_MAP = (
+ ("【对白·慢速清晰·同步字幕】", "【对白·慢速清晰】"),
+ ("【旁白·慢速清晰·同步字幕】", "【旁白·慢速清晰】"),
+ ("【旁白·自然语速·同步字幕】", "【旁白·自然语速】"),
+ ("【内心独白·同步字幕】", "【内心独白】"),
+)
+
+
+def strip_model_burn_subtitle_cues(content: str) -> str:
+ """去掉模型烧录字幕提示,保留对白/旁白本身(供后期叠字)。"""
+ out: list[str] = []
+ for raw in (content or "").replace("\r\n", "\n").split("\n"):
+ stripped = raw.strip()
+ if not stripped:
+ out.append(raw)
+ continue
+ if stripped.startswith("【字幕"):
+ continue
+ line = stripped
+ for src, dest in _POST_SUBTITLE_PREFIX_MAP:
+ if line.startswith(src):
+ line = dest + line[len(src) :]
+ break
+ out.append(line)
+ return "\n".join(out).replace("\n\n\n", "\n\n").strip()
+
+
def build_seedance_production_section(
segment_script: str,
*,
ambient_only: bool = False,
+ burn_subtitles: bool = True,
) -> str:
"""组装 Seedance 音频/字幕/BGM 强制约束(科普旁白 / 漫剧画面+对白混排)。
ambient_only:科普后期 TTS 模式——模型只出操作环境音,禁止口播与 BGM。
+ burn_subtitles=False:对齐后期叠字(如 VOZEB 成片后再烧 SRT)——保留口播,禁止画面内字幕。
"""
if ambient_only:
lines = [
@@ -298,26 +328,42 @@ def build_seedance_production_section(
if "音量低于人声" not in bgm_mood:
bgm_mood = f"{bgm_mood},音量低于人声"
+ # 后期字幕:口播保留,画面禁止任何文字(字幕交给剪辑/导出 SRT)
+ no_burn = (
+ "禁止在画面内烧录字幕、标题、水印、字卡或口播文字;"
+ "口播仅出声,文字叠字由后期完成。"
+ )
+
if drama_mixed:
lines = [
"1. 配音范围:仅【旁白·…】【对白·…】标记的段落需要口播;"
"【画面·…】标记或未带配音前缀的段落为画面/动作描述,只呈现视觉与环境音,"
"禁止为其生成配音、禁止烧字幕、禁止把画面描述念出来。",
"2. 语速:旁白/对白语速自然偏慢,吐字清晰,留有呼吸与停顿;严禁加速赶词。",
- "3. 字幕:仅【旁白·…】【对白·…】口播内容烧录简体中文字幕,底部居中;"
- "同一时刻只显示一行(一句),随口播进度逐句轮换,禁止把整段对白一次性叠满屏幕;"
- "禁止重复字、叠字、口吃式重复;字幕必须与当前正在说的那一句逐字一致;"
- "画面描述段不出现字幕。",
+ (
+ f"3. 字幕:{no_burn}"
+ if not burn_subtitles
+ else (
+ "3. 字幕:仅【旁白·…】【对白·…】口播内容烧录简体中文字幕,底部居中;"
+ "同一时刻只显示一行(一句),随口播进度逐句轮换,禁止把整段对白一次性叠满屏幕;"
+ "禁止重复字、叠字、口吃式重复;字幕必须与当前正在说的那一句逐字一致;"
+ "画面描述段不出现字幕。"
+ )
+ ),
]
if has_vo:
lines.append(
"4. 旁白:【旁白·…】段落以第三人称旁白慢速清晰配音;"
- "字幕逐句轮换,与当前口播句同步。"
+ + ("仅出声,画面不叠字幕。" if not burn_subtitles else "字幕逐句轮换,与当前口播句同步。")
)
elif has_dialogue:
lines.append(
"4. 对白:【对白·…】段落按角色对白配音;"
- "字幕逐句轮换,与当前口播句同步;无对白标记时保持环境音即可。"
+ + (
+ "仅出声,画面不叠字幕;无对白标记时保持环境音即可。"
+ if not burn_subtitles
+ else "字幕逐句轮换,与当前口播句同步;无对白标记时保持环境音即可。"
+ )
)
else:
lines.append(
@@ -330,29 +376,43 @@ def build_seedance_production_section(
"6. 音效:环境音与动作音效与画面同步,层次低于人声。"
)
if "【人物介绍" in (segment_script or ""):
- lines.append(
- "7. 人物介绍叠字:【人物介绍·画面叠字·角色身旁】须贴在对应角色身旁"
- "(肩侧/身旁小字),随该角色首次入画短暂出现;"
- "禁止居中大标题、禁止底部与口播字幕抢位;"
- "禁止口播念出介绍全文。"
- )
+ if burn_subtitles:
+ lines.append(
+ "7. 人物介绍叠字:【人物介绍·画面叠字·角色身旁】须贴在对应角色身旁"
+ "(肩侧/身旁小字),随该角色首次入画短暂出现;"
+ "禁止居中大标题、禁止底部与口播字幕抢位;"
+ "禁止口播念出介绍全文。"
+ )
+ else:
+ lines.append(
+ "7. 人物介绍:本镜禁止任何人物介绍叠字/字卡;身份信息不写入画面。"
+ )
return f"{SEEDANCE_PRODUCTION_SECTION_HEADER}\n" + "\n".join(lines)
# 科普旁白模式:整镜以旁白段为主(语速自然偏快,避免拖沓)
lines = [
"1. 语速:旁白语速自然偏快、吐字清晰,节奏紧凑有呼吸感;"
"避免刻意放慢、拖腔或长时间停顿;不要压缩到含糊赶词,也不要提高播放倍速。",
- "2. 字幕:全程烧录简体中文字幕,位置底部居中,字号清晰可读;旁白须逐句同步显示,字幕与口播一致。",
+ (
+ f"2. 字幕:{no_burn}"
+ if not burn_subtitles
+ else (
+ "2. 字幕:全程烧录简体中文字幕,位置底部居中,字号清晰可读;"
+ "旁白须逐句同步显示,字幕与口播一致。"
+ )
+ ),
]
if has_vo:
lines.append(
"3. 旁白:脚本含旁白段落时以第三人称旁白配音,沉稳清晰、语速自然偏快;"
- "视频内不要自行添加嘈杂对白;旁白出现时字幕同步显示全文。"
+ "视频内不要自行添加嘈杂对白;"
+ + ("口播仅出声,画面不叠字幕。" if not burn_subtitles else "旁白出现时字幕同步显示全文。")
)
else:
lines.append(
- "3. 旁白:若脚本含旁白标记,按第三人称旁白自然偏快清晰配音,并同步烧录字幕;"
- "视频内不要自行添加嘈杂对白。"
+ "3. 旁白:若脚本含旁白标记,按第三人称旁白自然偏快清晰配音"
+ + (";口播仅出声,画面不叠字幕;" if not burn_subtitles else ",并同步烧录字幕;")
+ + "视频内不要自行添加嘈杂对白。"
)
lines.append(
f"4. 背景音乐:{bgm_mood};BGM 音量低于人声约 30%,不得盖过旁白与关键音效。"
@@ -624,6 +684,7 @@ def build_seedance_prompt(
motion_bias: str = "",
camera: str = "",
ambient_only: bool = False,
+ burn_subtitles: bool = True,
) -> str:
"""Assemble final Seedance text: style lock + production constraints + timed body."""
parts: list[str] = []
@@ -633,8 +694,17 @@ def build_seedance_prompt(
"【强制约束:视频画面风格】全片画面必须严格遵循以下风格描述,"
f"严禁偏离或混用其他画风:{style}"
)
+ script_for_rules = (
+ strip_model_burn_subtitle_cues(segment_script)
+ if not burn_subtitles and not ambient_only
+ else (segment_script or "")
+ )
parts.append(
- build_seedance_production_section(segment_script, ambient_only=ambient_only)
+ build_seedance_production_section(
+ script_for_rules,
+ ambient_only=ambient_only,
+ burn_subtitles=burn_subtitles and not ambient_only,
+ )
)
parts.append(
"【强制约束:节奏与画面】严格按时间轴段落演绎画面;"
@@ -646,7 +716,7 @@ def build_seedance_prompt(
body_src = (
seedance_timeline_without_voice(segment_script)
if ambient_only
- else (segment_script or "")
+ else script_for_rules
)
body = replace_duration_with_time_ranges(body_src)
parts.append(body.strip())
diff --git a/backend/tests/test_drama_subtitle_toggle.py b/backend/tests/test_drama_subtitle_toggle.py
index 363742b..44a845d 100644
--- a/backend/tests/test_drama_subtitle_toggle.py
+++ b/backend/tests/test_drama_subtitle_toggle.py
@@ -1,7 +1,15 @@
-"""分镜字幕开关:关闭时不再注入字幕 cue。"""
+"""分镜字幕开关:关闭时不再注入字幕 cue;后期模式禁止 Seedance 烧录。"""
from app.services.drama.build_fragments import DRAMA_SUBTITLE_CUE, plan_fragments_from_scene
+from app.services.drama.build_seedance_generate_body import (
+ build_seedance_prompt_text,
+ resolve_episode_burn_subtitles,
+)
from app.services.drama.fragment_plan_prompt import build_fragment_plan_user_prompt
+from app.services.seedance_segments import (
+ build_seedance_production_section,
+ strip_model_burn_subtitle_cues,
+)
def test_plan_fragments_from_scene_omits_subtitle_cue_when_disabled():
@@ -40,3 +48,40 @@ def test_fragment_plan_user_prompt_marks_no_subtitles():
)
assert "字幕需求:不要字幕" in prompt
assert "不要写任何“字幕 / 叠字 / 同步字幕 / 字卡”等提示" in prompt
+
+
+def test_resolve_episode_burn_subtitles_post_mode():
+ assert resolve_episode_burn_subtitles({"subtitleMode": "post"}) is False
+ assert resolve_episode_burn_subtitles({"subtitleMode": "model"}) is True
+ assert resolve_episode_burn_subtitles({"subtitleEnabled": False}) is False
+
+
+def test_strip_model_burn_subtitle_cues_keeps_dialogue():
+ raw = (
+ "【字幕:底部居中·简体中文·逐句轮换·与口播同步】\n"
+ "@duration:4\n"
+ "【对白·慢速清晰·同步字幕】禹:水患未平。"
+ )
+ cleaned = strip_model_burn_subtitle_cues(raw)
+ assert "【字幕" not in cleaned
+ assert "同步字幕" not in cleaned
+ assert "【对白·慢速清晰】禹:水患未平。" in cleaned
+
+
+def test_production_section_post_mode_forbids_burn():
+ script = "@duration:4\n【对白·慢速清晰】禹:水患未平。"
+ section = build_seedance_production_section(script, burn_subtitles=False)
+ assert "禁止在画面内烧录字幕" in section
+ assert "烧录简体中文字幕" not in section
+
+
+def test_seedance_prompt_text_post_mode_strips_cues():
+ content = (
+ "【字幕:底部居中·简体中文·逐句轮换·与口播同步】\n"
+ "@duration:4\n"
+ "【对白·慢速清晰·同步字幕】禹:水患未平。"
+ )
+ prompt = build_seedance_prompt_text(content, [], burn_subtitles=False)
+ assert "【字幕" not in prompt
+ assert "同步字幕" not in prompt
+ assert "禁止在画面内烧录字幕" in prompt
diff --git a/backend/tests/test_fragment_video_versions.py b/backend/tests/test_fragment_video_versions.py
index b469340..ea774cd 100644
--- a/backend/tests/test_fragment_video_versions.py
+++ b/backend/tests/test_fragment_video_versions.py
@@ -31,25 +31,60 @@ def test_fragment_generation_status_done_when_video_and_idle_gen():
assert st["status"] == "done"
-def test_archive_and_activate_video_version():
+def test_archive_and_activate_video_version(tmp_path, monkeypatch):
+ from pathlib import Path
+
+ from app.services.drama import generation as gen_mod
+
+ video_file = tmp_path / "shot_009.mp4"
+ video_file.write_bytes(b"old-video")
+ cover_file = tmp_path / "shot_009_cover.jpg"
+ cover_file.write_bytes(b"old-cover")
+
+ def fake_local_path(url: str):
+ name = str(url).rsplit("/", 1)[-1]
+ path = tmp_path / name
+ return path if path.exists() else None
+
+ def fake_rel(path: Path) -> str:
+ return f"/static/generated/t/{path.name}"
+
+ def fake_republish(url: str | None, *, sync: bool = True):
+ return url
+
+ monkeypatch.setattr("app.services.storage.local_path_from_url", fake_local_path)
+ monkeypatch.setattr("app.services.storage.rel_static_url", fake_rel)
+ monkeypatch.setattr("app.services.storage.republish_url", fake_republish)
+
frag = _frag(
id=9,
- video="https://cdn/old.mp4",
- cover="https://cdn/old.jpg",
- params={"lastFrameUrl": "https://cdn/old-last.jpg", "video_versions": []},
+ video="/static/generated/t/shot_009.mp4",
+ cover="/static/generated/t/shot_009_cover.jpg",
+ params={"lastFrameUrl": "", "video_versions": []},
)
archived = archive_fragment_video_version(frag) # type: ignore[arg-type]
assert archived is not None
- assert frag.params["video_versions"][0]["video"] == "https://cdn/old.mp4"
+ hist_video = frag.params["video_versions"][0]["video"]
+ assert "_hist_" in hist_video
+ assert (tmp_path / hist_video.rsplit("/", 1)[-1]).exists()
+
+ # 同 URL 再归档不应因去重丢掉上一条(覆盖场景)
+ frag.video = "/static/generated/t/shot_009.mp4"
+ archive_fragment_video_version(frag) # type: ignore[arg-type]
+ assert len(frag.params["video_versions"]) == 2
frag.video = "https://cdn/new.mp4"
frag.cover = "https://cdn/new.jpg"
frag.params["lastFrameUrl"] = "https://cdn/new-last.jpg"
version_id = frag.params["video_versions"][0]["id"]
out = activate_fragment_video_version(frag, version_id) # type: ignore[arg-type]
- assert out["video"] == "https://cdn/old.mp4"
- assert frag.video == "https://cdn/old.mp4"
- assert any(v.get("video") == "https://cdn/new.mp4" for v in frag.params["video_versions"])
+ assert out["video"] == hist_video or "_hist_" in out["video"]
+ assert frag.video == out["video"]
+
+
+def test_archive_skips_empty_video():
+ frag = _frag(id=1, video="", cover="", params={})
+ assert archive_fragment_video_version(frag) is None # type: ignore[arg-type]
def test_generation_queued_recently_within_grace():