feat(v0.1.1): 周期表五大分区 / 分区与单格改色 / 全屏视线跟随 / 窗口图标 / 跨平台打包
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import imageio_ffmpeg
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
FFMPEG = imageio_ffmpeg.get_ffmpeg_exe()
|
||||
SRC = r"D:\软件\剪映\video\QQ20261201-165342-HD.mp4"
|
||||
OUT = r"C:\Users\ASUS\Documents\deepseek-harness\default-workspace\desktop-pet\video-plan"
|
||||
TMP = os.path.join(OUT, "tmp")
|
||||
os.makedirs(TMP, exist_ok=True)
|
||||
|
||||
W, H = 1920, 1200
|
||||
FPS = 60
|
||||
FONT = r"C:\Windows\Fonts\msyhbd.ttc"
|
||||
FONT_R = r"C:\Windows\Fonts\msyh.ttc"
|
||||
|
||||
# (in, out, speed) 秒 —— 按 剪辑方案.md / 裁剪清单.csv
|
||||
SEGMENTS = [
|
||||
(52, 66, 1.0),
|
||||
(70, 86, 1.0),
|
||||
(90, 110, 1.5),
|
||||
(112, 138, 1.5),
|
||||
(142, 170, 1.5),
|
||||
(172, 200, 1.5),
|
||||
(204, 250, 1.8),
|
||||
(252, 290, 1.5),
|
||||
(292, 330, 2.0),
|
||||
(332, 370, 2.0),
|
||||
(372, 400, 2.0),
|
||||
(580, 610, 2.0),
|
||||
(675, 700, 2.0),
|
||||
(720, 750, 2.0),
|
||||
(820, 860, 1.5),
|
||||
(862, 890, 1.0),
|
||||
(910, 940, 2.0),
|
||||
(965, 1000, 1.5),
|
||||
(1020, 1050, 1.5),
|
||||
(1065, 1080, 1.0),
|
||||
]
|
||||
|
||||
|
||||
def run(args: list) -> None:
|
||||
p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if p.returncode != 0:
|
||||
print("FAILED:", " ".join(args)[:400])
|
||||
print(p.stdout.decode("utf-8", "ignore")[-3000:])
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def make_card(name: str, title: str, sub: str, foot: str = "") -> str:
|
||||
img = Image.new("RGB", (W, H), (12, 16, 24))
|
||||
d = ImageDraw.Draw(img)
|
||||
# 渐变
|
||||
for y in range(H):
|
||||
k = y / H
|
||||
d.line([(0, y), (W, y)], fill=(int(10 + 18 * k), int(14 + 20 * k), int(22 + 30 * k)))
|
||||
f1 = ImageFont.truetype(FONT, 108)
|
||||
f2 = ImageFont.truetype(FONT_R, 46)
|
||||
f3 = ImageFont.truetype(FONT_R, 34)
|
||||
tw = d.textlength(title, font=f1)
|
||||
d.text(((W - tw) / 2, 380), title, font=f1, fill=(255, 240, 200))
|
||||
if sub:
|
||||
sw = d.textlength(sub, font=f2)
|
||||
d.text(((W - sw) / 2, 540), sub, font=f2, fill=(190, 205, 225))
|
||||
if foot:
|
||||
fw = d.textlength(foot, font=f3)
|
||||
d.text(((W - fw) / 2, 640), foot, font=f3, fill=(120, 170, 220))
|
||||
path = os.path.join(TMP, name)
|
||||
img.save(path)
|
||||
return path
|
||||
|
||||
|
||||
def main() -> None:
|
||||
title = make_card("card_title.png", "小钠 · 化学元素拟人桌宠", "Live2D · 经济任务 · 音乐 · AI 对话 · MOD")
|
||||
end = make_card(
|
||||
"card_end.png",
|
||||
"开源 · 免费 · Windows",
|
||||
"一个会饿、会累、会被氧化的桌面伙伴",
|
||||
"github.com/Tian-XiaRi/SodiumPet",
|
||||
)
|
||||
|
||||
parts = []
|
||||
# 片头 5s
|
||||
p0 = os.path.join(TMP, "p00.mp4")
|
||||
run([
|
||||
FFMPEG, "-y", "-hide_banner", "-loglevel", "error",
|
||||
"-loop", "1", "-t", "5", "-i", title,
|
||||
"-vf", f"scale={W}:{H},format=yuv420p,fps={FPS}",
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", "20", "-an", p0,
|
||||
])
|
||||
parts.append(p0)
|
||||
|
||||
# 各段裁切 + 变速
|
||||
for i, (a, b, sp) in enumerate(SEGMENTS, start=1):
|
||||
out = os.path.join(TMP, f"p{i:02d}.mp4")
|
||||
pts = f"setpts=(PTS-STARTPTS)/{sp}" if sp != 1.0 else "setpts=PTS-STARTPTS"
|
||||
run([
|
||||
FFMPEG, "-y", "-hide_banner", "-loglevel", "error",
|
||||
"-ss", str(a), "-to", str(b), "-i", SRC,
|
||||
"-vf", f"scale={W}:{H}:flags=lanczos,{pts},fps={FPS},format=yuv420p",
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", "21", "-an", out,
|
||||
])
|
||||
parts.append(out)
|
||||
print("segment", i, "done", flush=True)
|
||||
|
||||
# 片尾 6s
|
||||
pe = os.path.join(TMP, "p99.mp4")
|
||||
run([
|
||||
FFMPEG, "-y", "-hide_banner", "-loglevel", "error",
|
||||
"-loop", "1", "-t", "6", "-i", end,
|
||||
"-vf", f"scale={W}:{H},format=yuv420p,fps={FPS}",
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", "20", "-an", pe,
|
||||
])
|
||||
parts.append(pe)
|
||||
|
||||
# 拼接
|
||||
lst = os.path.join(TMP, "list.txt")
|
||||
with open(lst, "w", encoding="utf-8") as f:
|
||||
for p in parts:
|
||||
f.write("file '" + p.replace("\\", "/") + "'\n")
|
||||
rough = os.path.join(OUT, "小钠介绍_粗剪.mp4")
|
||||
run([
|
||||
FFMPEG, "-y", "-hide_banner", "-loglevel", "error",
|
||||
"-f", "concat", "-safe", "0", "-i", lst,
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", "21",
|
||||
"-vf", f"fps={FPS},fade=t=in:st=0:d=0.6,fade=t=out:st=999:d=1",
|
||||
"-an", rough,
|
||||
])
|
||||
print("rough done:", rough, flush=True)
|
||||
|
||||
# 字幕 ASS
|
||||
subs = [
|
||||
(0.5, 5.5, "小钠 · 化学元素拟人桌宠"),
|
||||
(6.0, 11.0, "钠(Na)的拟人,住在你的 Windows 桌面上"),
|
||||
(11.2, 16.5, "会饿、会累、会被氧化,也会自己打工赚钱"),
|
||||
(17.0, 21.0, "点一下就是摸头"),
|
||||
(21.2, 26.0, "右键弹出底栏:投喂 / 面板 / 互动 / 商店 / 图库 / 设置"),
|
||||
(26.2, 31.0, "六条状态,全部是化学化的写法"),
|
||||
(31.2, 37.0, "饱食度 · 石蜡油 · 电子数 · 氧化度 · 心情 · 亲和度"),
|
||||
(37.2, 42.0, "任务解锁等级跨度很大,倍率可以自己调"),
|
||||
(42.2, 47.0, "越肝越赚,但状态掉得也越快"),
|
||||
(47.2, 52.0, "商店里有每日特价和每日礼包"),
|
||||
(52.2, 57.0, "也可以导入自己的 Live2D 模型"),
|
||||
(57.2, 62.0, "切过去就是普通桌宠的文案与图标"),
|
||||
(62.2, 67.0, "详细面板:每一件物品的使用记录"),
|
||||
(67.2, 71.0, "没做过的也显示 0,方便查漏"),
|
||||
(71.2, 77.0, "等级 = 元素周期表"),
|
||||
(77.2, 82.0, "118 个元素、电子排布、每个元素一句特征"),
|
||||
(82.2, 87.0, "编辑器:改名字、改图标、改价格、改解锁等级"),
|
||||
(87.2, 92.0, "化学风与普通风各存一份,互不覆盖"),
|
||||
(92.2, 97.0, "周期表配色可以点格子取色,另存自己的方案"),
|
||||
(97.2, 102.0, "MOD 用 JSON 就能加物品和活动"),
|
||||
(102.2, 107.0, "AI 对话:任意 OpenAI 兼容接口"),
|
||||
(107.2, 112.0, "流式回复、识图、联网搜索、知识库注入"),
|
||||
(112.2, 117.0, "🎲 预设对话会按状态掷骰子:状态好更容易加成"),
|
||||
(117.2, 122.0, "状态差更容易翻车——她真的会记仇"),
|
||||
(122.2, 127.0, "照片、文件、知识库文档,统一在资料库管理"),
|
||||
(127.2, 132.0, "本地音乐 + 歌词浮窗,切存档不影响歌单"),
|
||||
(132.2, 137.0, "开源 · 免费 · Windows 桌面宠物"),
|
||||
(137.2, 143.0, "github.com/Tian-XiaRi/SodiumPet"),
|
||||
(143.2, 148.0, "谢谢观看"),
|
||||
]
|
||||
|
||||
def ts(t: float) -> str:
|
||||
h = int(t // 3600)
|
||||
m = int(t % 3600 // 60)
|
||||
s = t % 60
|
||||
return f"{h}:{m:02d}:{s:05.2f}"
|
||||
|
||||
ass = [
|
||||
"[Script Info]",
|
||||
"ScriptType: v4.00+",
|
||||
f"PlayResX: {W}",
|
||||
f"PlayResY: {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,58,&H00F5F0E8,&H00F5F0E8,&H00000000,&H64000000,-1,0,0,0,100,100,0,0,1,3,1,2,120,120,90,1",
|
||||
"",
|
||||
"[Events]",
|
||||
"Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text",
|
||||
]
|
||||
for a, b, text in subs:
|
||||
ass.append(f"Dialogue: 0,{ts(a)},{ts(b)},Caption,,0,0,0,,{text}")
|
||||
ass_path = os.path.join(OUT, "字幕_成片.ass")
|
||||
with open(ass_path, "w", encoding="utf-8-sig") as f:
|
||||
f.write("\n".join(ass))
|
||||
|
||||
# 烧字幕(需要转义路径)
|
||||
esc = ass_path.replace("\\", "/").replace(":", "\\:")
|
||||
final = os.path.join(OUT, "小钠介绍_字幕版.mp4")
|
||||
run([
|
||||
FFMPEG, "-y", "-hide_banner", "-loglevel", "error",
|
||||
"-i", rough,
|
||||
"-vf", f"subtitles='{esc}'",
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", "21", "-an", final,
|
||||
])
|
||||
print("final done:", final, flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user