import os import subprocess import sys import imageio_ffmpeg FFMPEG = imageio_ffmpeg.get_ffmpeg_exe() OUT = r"C:\Users\ASUS\Documents\deepseek-harness\default-workspace\desktop-pet\video-plan" ROUGH = os.path.join(OUT, "小钠介绍_粗剪.mp4") W, H = 1920, 1200 # 片段起点(秒)——与 build_video4.py 输出一致 STARTS = [1, 6, 12, 18, 26, 34, 42, 48, 58, 63, 71, 79, 84, 89, 94, 99, 107, 111, 116, 123, 129] TITLE_END = 5.0 END_START = 136.0 CAPS = [ ("装好后,她就住在你的桌面上了", 5.0), ("右键弹出底栏:投喂 / 面板 / 互动 / 商店 / 图库 / 设置", 6.0), ("六条状态:饱食度 · 石蜡油 · 电子数 · 氧化度 · 心情 · 亲和度", 6.0), ("详细面板里能看到每一件物品的使用次数", 8.0), ("状态、皮肤、存档都能在设置里换", 8.0), ("没做过的统计也显示 0,方便查漏", 6.0), ("统计 / 总结 / 生日 / 日志 / 等级预览,一共五页", 10.0), ("等级 = 元素周期表,118 个元素", 8.0), ("每个元素一句特征,点一下还能联网补资料", 8.0), ("编辑器:改等级描述、周期表配色", 8.0), ("设置里还有存档、MOD、生日、歌词浮窗", 6.0), ("文件拖给她就会进文件袋", 5.0), ("配色可以点格子取色,另存成自己的方案", 5.0), ("接上任意 OpenAI 兼容接口", 5.0), ("填 baseURL 和模型名就能用", 8.0), ("知识库来自你拖进来的文档", 4.0), ("对话支持流式输出与 🎲 预设掷骰子", 8.0), ("官方文档写明兼容 OpenAI SDK", 5.0), ("素材、照片、文件统一管理", 6.0), ("独立资料库窗口:照片 / 文件 / 知识库", 6.0), ("设置里能改缩放、主题、主色和裁剪", 7.0), ] def ts(x: float) -> str: return "%d:%02d:%05.2f" % (int(x // 3600), int(x % 3600 // 60), x % 60) def main() -> None: lines = [ "[Script Info]", "ScriptType: v4.00+", "PlayResX: %d" % W, "PlayResY: %d" % H, "WrapStyle: 0", "ScaledBorderAndShadow: yes", "", "[V4+ Styles]", "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding", "Style: Caption,Microsoft YaHei,56,&H00F5F0E8,&H00F5F0E8,&H00000000,&H64000000,-1,0,0,0,100,100,0,0,1,3,1,2,120,120,80,1", "", "[Events]", "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text", ] # 片头 lines.append("Dialogue: 0,%s,%s,Caption,,0,0,0,,小钠 · 化学元素拟人桌宠" % (ts(0.4), ts(4.6))) srt = [] srt.append((0.4, 4.6, "小钠 · 化学元素拟人桌宠")) for i, (text, dur) in enumerate(CAPS): st = STARTS[i] + 0.2 en = STARTS[i] + max(2.0, dur - 0.2) if i + 1 < len(STARTS): en = min(en, STARTS[i + 1] - 0.1) lines.append("Dialogue: 0,%s,%s,Caption,,0,0,0,,%s" % (ts(st), ts(en), text)) srt.append((st, en, text)) lines.append("Dialogue: 0,%s,%s,Caption,,0,0,0,,谢谢观看 · 欢迎 star" % (ts(END_START + 0.4), ts(END_START + 5.5))) srt.append((END_START + 0.4, END_START + 5.5, "谢谢观看 · 欢迎 star")) ass_path = os.path.join(OUT, "字幕_成片.ass") with open(ass_path, "w", encoding="utf-8-sig") as f: f.write("\n".join(lines)) # 同步生成 SRT(给剪映导入用) def srt_ts(x: float) -> str: h = int(x // 3600) m = int(x % 3600 // 60) s = x % 60 return "%02d:%02d:%02d,%03d" % (h, m, int(s), int((s - int(s)) * 1000)) blocks = [] for i, (a, b, text) in enumerate(srt, start=1): blocks.append("%d\n%s --> %s\n%s\n" % (i, srt_ts(a), srt_ts(b), text)) with open(os.path.join(OUT, "字幕.srt"), "w", encoding="utf-8") as f: f.write("\n".join(blocks)) esc = ass_path.replace("\\", "/").replace(":", "\\:") final = os.path.join(OUT, "小钠介绍_字幕版.mp4") p = subprocess.run( [FFMPEG, "-y", "-hide_banner", "-loglevel", "error", "-i", ROUGH, "-vf", "subtitles='%s'" % esc, "-c:v", "libx264", "-preset", "veryfast", "-crf", "21", "-an", final], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) if p.returncode != 0: print(p.stdout.decode("utf-8", "ignore")[-2000:]) sys.exit(1) print("subtitle burn done") if __name__ == "__main__": main()