dsh-lovideo 0.6.5 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/PROTOCOL.md +7 -1
- package/package.json +3 -3
- package/skills/lovideo-director/SKILL.md +4 -3
- package/src/host/composer.js +10 -4
- package/src/host/llm.js +10 -1
- package/src/host/localvoice.js +6 -4
- package/src/host/narration.js +24 -8
- package/src/host/produce.js +21 -6
- package/src/host/quality.js +21 -17
- package/src/host/segment.js +99 -30
- package/src/host/tools.js +7 -6
package/docs/PROTOCOL.md
CHANGED
|
@@ -57,7 +57,13 @@
|
|
|
57
57
|
- 口播逐句配音,按网站的时序铺成段的口播轨:段长 = 段首留白 + 各句 + 句间停顿 + 段尾留白。
|
|
58
58
|
- 每段一个制作会话:第一条消息是各段共用的说明 + 风格 `SKILL.md` 全文 + 本段说明(制作上下文、`setup.py` 写好的草稿)。路径用网站沙箱的写法(`/work/proj/<段>/`、`/work/.agents/skills/<风格>/`),插件换成本机目录,所以风格的 `SKILL.md` 原样可用。
|
|
59
59
|
- 模型只用 `draw`(写文件、整文件或精确替换)和 `read`;平台按 `SKILL.md` 的渲染命令渲染、检查、交段,失败把报错交回同一个会话。一个会话最多 12 次工具调用、5 次渲染,一段最多开 2 个会话。
|
|
60
|
-
- 交段前的检查:页面风格第一次完整渲染前只画 6~9
|
|
60
|
+
- 交段前的检查:页面风格第一次完整渲染前只画 6~9 帧拼成检查图,模型能看图时看一次;渲染时核对页面正好铺满成片画面(写死尺寸、换画幅溢出的直接退回);渲染后量旁白在说时画面有没有在动。检查图和画面变化各最多退回两次(网站各一次:小模型被退回后容易把别处改坏)。
|
|
61
|
+
|
|
62
|
+
## 4.2 分镜(和网站对齐的字段,以及只在插件里有的约束)
|
|
63
|
+
|
|
64
|
+
- `lovideo_plan` 的 `facts` 存成 `plan.inputs`(`[{key,label,value}]`,写进 `job.json` 的 `confirmed.inputs`);每镜的 `screen_text` 存成 `scenes[].copy`(`{text1: …}`,写进 `segments[].copy`)。网站导演直接给 `inputs` 和按角色的 `copy`,含义相同。
|
|
65
|
+
- 和网站一样的硬性上限:画面描述 200 字、一句口播 60 字。
|
|
66
|
+
- 只在插件里有的(给小模型加的):一镜最多 6 句、一句最少 8 个字、屏幕文字每条最多 14 字、带数字的事实没用上就退回、估算时长超目标 15% 退回。制作说明里另加了六条做法(现成组件优先、位置不写死、时间跟着字、文字停留时长、照 copy 写字、一句一个动作),见 `src/host/segment.js` 的 `segmentNote`。
|
|
61
67
|
|
|
62
68
|
## 5. 时间线和剪映
|
|
63
69
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lovideo",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "lovideo 视频插件:在 DeepSeek Harness 里一句话做出任意风格的视频。导演用你选的模型,画面在你自己的电脑上渲染。",
|
|
5
5
|
"homepage": "https://lovideo.ai",
|
|
6
6
|
"repository": {
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"license": "UNLICENSED",
|
|
80
80
|
"lovideo": {
|
|
81
81
|
"whatsNew": {
|
|
82
|
-
"zh": "
|
|
83
|
-
"en": "
|
|
82
|
+
"zh": "修复部分风格开拍后画不出来的问题;交片前的画面检查更严,分镜要求的字和图少了会退回重画;成片时长更贴近你要的秒数。",
|
|
83
|
+
"en": "Fixes some styles failing to draw after you start production; stricter frame checks before each shot is accepted; finished videos now land closer to the length you asked for."
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -16,7 +16,7 @@ description: 做视频的导演做法:用 lovideo 工具把用户的一句话
|
|
|
16
16
|
## 一部片子的流程
|
|
17
17
|
|
|
18
18
|
1. **第一次用先检查**:会话里第一次做视频时调用 `lovideo_setup`。渲染环境没准备好、或要用平台风格但没登录时,告诉用户在卡片上点按钮,然后等用户说好了再继续。
|
|
19
|
-
2.
|
|
19
|
+
2. **问清楚,但别问太多**:只问片子缺了就做不成的事实(讲什么、给谁看),一次最多问两三个;其他的(画幅、语气、结构)你按内容做合理的决定。用户已经说清的不要再问。画幅和片长:用户这条消息里写明了的(「竖版」「30 秒」)照消息里的来;没写就照输入框里选的。输入框里选了风格就用那个风格;用户在消息里点名了风格也直接用,不用再推荐。片长不用专门问:用户说了就按用户的(取最近的一档),没说就 30 秒,卡片上用户可以拖动改。
|
|
20
20
|
3. **选风格**:分两步。先不带参数调用 `lovideo_styles`,它会给你全部风格的完整介绍和所有封面拼成的总览图(编号对应)——认真看图、读介绍,想清楚这部片子讲什么、给谁看、要什么语气,找画面气质和内容最贴的,不要只按「用途」字面挑。再带 `recommend`(1 到 3 个,按推荐程度排)和 `why`(每个一句理由,说画面和内容怎么对上)调用一次,卡片会显示封面和理由,每个都能点选。推荐完用一句话请用户在卡片上点一个(或直接说想要哪个),然后停下等,不要替用户选、不要直接出分镜。用户点了你会收到「[lovideo 通知] 用户在推荐卡片上选了风格」,照通知做。用户已经指定风格就直接用;用户要的风格不可用(没登录、没有这个风格、不支持要的画幅)时,说明原因让用户选,**不要悄悄换成别的风格**。
|
|
21
21
|
4. **先备内容,再出分镜**:内容是第一位的,片长只是参考。
|
|
22
22
|
- 先把要讲的东西找齐:用户给的资料(附件、文档、表格、链接)先读完再规划,不要再问用户资料里已经写了的东西;讲真实世界的事(产品、事件、科学、历史、新闻、地点)时,用 `web_search` 搜一两轮,必要时用 `web_fetch` 读原文,拿到具体的事实、数字、时间和例子。只讲搜到或资料里有的,拿不准的不讲。跟用户提到资料来源时用 Markdown 链接写出网址,没有来源就不要编一个。
|
|
@@ -44,7 +44,7 @@ description: 做视频的导演做法:用 lovideo 工具把用户的一句话
|
|
|
44
44
|
**先列事实,再排镜头。**
|
|
45
45
|
|
|
46
46
|
1. 把用户的话和资料里要讲的事实一条条摘进 `facts`,数字、名字照原样(「马龙峰海拔 4122 米」「2023 年 12 月 6 日开业」)。
|
|
47
|
-
2. 按片长算口播总字数:中文约「片长秒数 ×
|
|
47
|
+
2. 按片长算口播总字数:中文约「片长秒数 × 3.5」个字,连数字和标点一起算(30 秒约 105 字,60 秒约 210 字;英文每秒约 2.2 个词)。配音每秒约 4 个字,每个逗号还要停一下,所以别按「每秒 5 个字」估。估出来比目标长 15% 以上会被退回。
|
|
48
48
|
3. 事实放不下时,留最要紧的,其余从 `facts` 里删掉;先删修饰和重复,不删事实。带数字的事实如果留在 `facts` 里却哪儿都没用上,会被退回。
|
|
49
49
|
4. 把留下的事实分给各镜,开头一句点题,最后一句收住。结尾不要把一件大事挤在最后半句里:它值得讲,就给它留够两三句。
|
|
50
50
|
|
|
@@ -65,7 +65,8 @@ description: 做视频的导演做法:用 lovideo 工具把用户的一句话
|
|
|
65
65
|
**镜头之间要像一部片。**
|
|
66
66
|
|
|
67
67
|
- 每镜分开画,同一个东西在各镜里用同一个名字、同一种说法(主角、产品、颜色、关键数字都一致)。后一镜接着前一镜的画面时,在描述开头写明(「同一张剖面」「同一张桌面」)。
|
|
68
|
-
-
|
|
68
|
+
- **整片的画面设定 `direction` 必填**(60 到 400 个字,太短会被退回)。每一镜的制作都会看到它,各镜靠它画成同一部片子。写清四件事:贯穿各镜的主体长什么样、在画面的什么位置;主色和强调色各是什么、用在哪;字放在哪、多大;镜头怎么走、节奏快慢。照风格的制作说明写,不要和它冲突;风格没有固定样子时(比如「我的风格」里的通用画布),配色、字体、版式都要在这里定下来。
|
|
69
|
+
- 一张图贯穿全片时(一张地图、一张剖面、一个场景一镜一镜往上加东西),在 `direction` 里写明「全片是同一张××」,并说清它的布局:什么在左、什么在右、每样东西的颜色。不然各镜会画成几张不同的图。
|
|
69
70
|
- **画幅**:只用风格支持的画幅;用户选了就照用户的。竖版画面窄,一行放不下长字:屏幕文字更要短。
|
|
70
71
|
|
|
71
72
|
**配音、配乐、字幕。**
|
package/src/host/composer.js
CHANGED
|
@@ -76,15 +76,21 @@ export function setBrief(sessionId, brief) {
|
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// 输入框的画幅、片长会沿用上一次的值,用户没动它们也会带上:用户这句话里写明了的,以这句话为准。
|
|
80
|
+
// 实测:选项停在「16:9、90 秒」时,用户打字要「30 秒竖版」,导演照选项做成了 90 秒横版。
|
|
81
|
+
const SAID_WINS = '注意:上面的画幅和片长是输入框里的选项,可能只是沿用上次的。用户这条消息里如果自己写明了画幅(「竖版」「横版」「9:16」「3:4」)或片长(「30 秒」「一分钟」),以用户写的为准。'
|
|
82
|
+
|
|
79
83
|
function briefText(b) {
|
|
80
84
|
if (!b.slug) {
|
|
81
|
-
return `[lovideo 输入框]
|
|
82
|
-
+ '
|
|
83
|
-
+ '出分镜时用这个画幅和片长(lovideo_plan 的 duration
|
|
85
|
+
return `[lovideo 输入框] 用户没有在输入框里选风格;输入框里的画幅是 ${b.aspect}、片长约 ${b.duration} 秒。`
|
|
86
|
+
+ '用户这条消息里如果点名了某个风格,就直接用它,不用再推荐;没点名就先调用 lovideo_styles 看全部风格的介绍和总览图,按内容挑 1 到 3 个推荐给用户点选(只挑支持这个画幅的)。'
|
|
87
|
+
+ '出分镜时用这个画幅和片长(lovideo_plan 的 aspect 和 duration),不要再问画幅和片长;配音和配乐照常由你建议。'
|
|
88
|
+
+ SAID_WINS
|
|
84
89
|
}
|
|
85
90
|
return `[lovideo 输入框] 用户在输入框里已经选好:风格「${b.name}」(style: ${b.slug})、画幅 ${b.aspect}、片长约 ${b.duration} 秒。`
|
|
86
|
-
+ '出分镜时直接用这个风格、画幅和片长(lovideo_plan 的 duration
|
|
91
|
+
+ '出分镜时直接用这个风格、画幅和片长(lovideo_plan 的 aspect 和 duration),不要再推荐风格,也不要再问画幅和片长;'
|
|
87
92
|
+ '配音和配乐照常由你建议。用户之后在对话里明确说要换的,以对话为准。'
|
|
93
|
+
+ SAID_WINS
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
/**
|
package/src/host/llm.js
CHANGED
|
@@ -146,6 +146,8 @@ export async function imageBlock(data, mediaType = 'image/png') {
|
|
|
146
146
|
return { type: 'image', attachment: ref }
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
let effortsLogged = false
|
|
150
|
+
|
|
149
151
|
export const userMessage = content => ({ role: 'user', content: typeof content === 'string' ? [{ type: 'text', text: content }] : content })
|
|
150
152
|
|
|
151
153
|
export const toolResult = (callId, text, isError = false) => ({
|
|
@@ -162,7 +164,14 @@ export async function chat({ system, messages, tools, maxTokens = 32000, signal,
|
|
|
162
164
|
if (!llm || !info) throw new Error('DeepSeek Harness 里还没有可用的模型')
|
|
163
165
|
const call = await llm.prepareCall({ provider: info.provider, model: info.model, maxTokens }, signal, (controls, model) => {
|
|
164
166
|
const efforts = model?.reasoning?.efforts || []
|
|
165
|
-
|
|
167
|
+
if (!effortsLogged) {
|
|
168
|
+
effortsLogged = true
|
|
169
|
+
console.error(`[lovideo] ${info.model} 的推理档位:${efforts.map(e => e.id).join(' / ') || '(没有)'}`)
|
|
170
|
+
}
|
|
171
|
+
// true 最低一档;'mid' 中间一档;'high' 第二高的一档(DeepSeek 是「高」,三档的模型就是中间那档)
|
|
172
|
+
const effort = light === true ? efforts[0]?.id
|
|
173
|
+
: light === 'mid' ? efforts[Math.floor((efforts.length - 1) / 2)]?.id
|
|
174
|
+
: light === 'high' ? efforts[Math.max(0, efforts.length - 2)]?.id : undefined
|
|
166
175
|
return effort === undefined ? controls : { ...controls, reasoningEffort: effort }
|
|
167
176
|
})
|
|
168
177
|
const blocks = []
|
package/src/host/localvoice.js
CHANGED
|
@@ -262,9 +262,9 @@ export async function musicLocal({ prompt, seconds, out }) {
|
|
|
262
262
|
/* ---------- 按口播长度挑模型 ---------- */
|
|
263
263
|
|
|
264
264
|
/**
|
|
265
|
-
*
|
|
266
|
-
* 按
|
|
267
|
-
*
|
|
265
|
+
* 估计口播时长:中文每秒 4 个字,数字每一位 0.25 秒,句子中间每个逗号顿号停 0.4 秒,英文每秒约 2.6 个词。
|
|
266
|
+
* 按 130 句离线配音的实际时长拟合(2026-11-29,均方根误差 0.9 秒)。以前按每秒 4.5 个字、
|
|
267
|
+
* 不算停顿、「2022」这样一串数字当一个词,估得比实际短两成,30 秒的片子常常做成 38 到 42 秒。
|
|
268
268
|
*/
|
|
269
269
|
export function estimateSeconds(texts) {
|
|
270
270
|
let s = 0
|
|
@@ -273,7 +273,9 @@ export function estimateSeconds(texts) {
|
|
|
273
273
|
const han = (text.match(/[一-鿿]/g) || []).length
|
|
274
274
|
const digits = (text.match(/\d/g) || []).length
|
|
275
275
|
const words = text.replace(/[一-鿿\d]/g, ' ').split(/\s+/).filter(w => /[a-z]/i.test(w)).length
|
|
276
|
-
|
|
276
|
+
// 句子中间每个逗号、顿号、冒号、分号都要停一下
|
|
277
|
+
const pauses = (text.replace(/[,、:;,:;。!?!?.\s]+$/, '').match(/[,、:;,:;]/g) || []).length
|
|
278
|
+
s += han * 0.25 + digits * 0.25 + pauses * 0.4 + words / 2.6
|
|
277
279
|
}
|
|
278
280
|
return s
|
|
279
281
|
}
|
package/src/host/narration.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// 再写出风格包要读的 narration.json(每句所在段、整片起止秒、逐词时间)。
|
|
3
3
|
// 时序(网站 src/lovideo/narration/layout.ts):段首留白 150 ms、句间停顿 250 ms、段尾留白 400 ms;一句最多 60 字。
|
|
4
4
|
// 逐词时间:网站用配音服务返回的词时间;本机的配音服务大多不给,按字数在句内均分(风格包没有词时间时也是这样估的)。
|
|
5
|
-
import { rmSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { ffmpeg, mediaSeconds } from './runtime.js'
|
|
8
|
+
import { estimateSeconds } from './localvoice.js'
|
|
8
9
|
|
|
9
10
|
export const HEAD = 0.15
|
|
10
11
|
export const GAP = 0.25
|
|
@@ -72,14 +73,29 @@ export async function voiceSegment({ segId, texts, workDir, speak, signal }) {
|
|
|
72
73
|
for (const [i, text] of texts.entries()) {
|
|
73
74
|
const file = join('voice', `${segId}-s${i + 1}.wav`)
|
|
74
75
|
const raw = join(workDir, 'voice', `${segId}-s${i + 1}.raw.wav`)
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
const take = join(workDir, 'voice', `${segId}-s${i + 1}.take.wav`)
|
|
77
|
+
// 离线配音模型不稳定:同一句话有时念出两倍长(中间多出停顿或多余的声音)。实测同一句连念 4 次是
|
|
78
|
+
// 4.9、8.7、4.6、5.0 秒,片子里那次 10.6 秒,一镜因此从 19 秒拖到 32 秒。
|
|
79
|
+
// 念出来明显比估算长就重念,最多 3 次,留最短的那次。
|
|
80
|
+
const expected = estimateSeconds([text])
|
|
81
|
+
let sec = 0
|
|
82
|
+
let tries = 0
|
|
83
|
+
while (tries < 3) {
|
|
84
|
+
tries++
|
|
85
|
+
if (!((await speak(text, raw, signal)) > 0)) throw new Error(`第 ${i + 1} 句没有念出声音:${text.slice(0, 30)}`)
|
|
86
|
+
// 和网站一样:按 -40 dBFS 裁掉前后多余的静音,只留 50 ms,句子的起止才准
|
|
87
|
+
const trim = 'silenceremove=start_periods=1:start_threshold=-40dB:start_silence=0.05'
|
|
88
|
+
await ffmpeg(['-i', raw, '-af', `${trim},areverse,${trim},areverse`, '-ar', '24000', '-ac', '1', take], { signal })
|
|
89
|
+
rmSync(raw, { force: true })
|
|
90
|
+
const got = await mediaSeconds(take)
|
|
91
|
+
if (!sec || (got > 0.05 && got < sec)) {
|
|
92
|
+
renameSync(take, join(workDir, file))
|
|
93
|
+
sec = got
|
|
94
|
+
} else rmSync(take, { force: true })
|
|
95
|
+
if (sec <= expected * 1.4 + 0.6) break
|
|
96
|
+
}
|
|
81
97
|
if (!(sec > 0.05)) throw new Error(`第 ${i + 1} 句裁掉静音后没有声音:${text.slice(0, 30)}`)
|
|
82
|
-
lines.push({ id: `${segId}-s${i + 1}`, text, file, start: r3(at), end: r3(at + sec) })
|
|
98
|
+
lines.push({ id: `${segId}-s${i + 1}`, text, file, start: r3(at), end: r3(at + sec), ...(tries > 1 ? { tries } : {}) })
|
|
83
99
|
at += sec + GAP
|
|
84
100
|
}
|
|
85
101
|
const file = join('voice', `${segId}.wav`)
|
package/src/host/produce.js
CHANGED
|
@@ -14,7 +14,7 @@ import { notify } from './notices.js'
|
|
|
14
14
|
import { getWork, requireWork, updateWork, workDir } from './works.js'
|
|
15
15
|
import { resolveStyle } from './styles.js'
|
|
16
16
|
import { speak } from './tts.js'
|
|
17
|
-
import { makeSegmentSession, sharedPrompt } from './segment.js'
|
|
17
|
+
import { makeSegmentSession, referenceOf, sharedPrompt } from './segment.js'
|
|
18
18
|
import { canSeeImages } from './llm.js'
|
|
19
19
|
import { TAIL, sentencesOf, voiceSegment, writeNarrationJson } from './narration.js'
|
|
20
20
|
import { fill, parseRenderCommand, renderCommand, renderPage, startSite } from './render.js'
|
|
@@ -250,12 +250,23 @@ async function run_(id, ctl) {
|
|
|
250
250
|
const segments = segmentsOf(work)
|
|
251
251
|
const shared = sharedPrompt({ style, segments, fps, size })
|
|
252
252
|
const redraw = new Set(pending.filter(s => s.redraws).map(s => s.id))
|
|
253
|
-
|
|
254
|
-
work, seg, segments, style, spec, size, fps, proj, site, signal, workDir: workDir(id), narration, shared, agents, redraw,
|
|
253
|
+
const make = (seg, reference) => makeSegmentSession({
|
|
254
|
+
work, seg, segments, style, spec, size, fps, proj, site, signal, workDir: workDir(id), narration, shared, agents, redraw, reference,
|
|
255
255
|
update: patch => setSegment(id, seg.id, patch),
|
|
256
256
|
log: entry => updateWork(id, w => (((w.job.segments.find(x => x.id === seg.id) || {}).history ||= []).push(entry), w)),
|
|
257
257
|
countCall: () => updateWork(id, w => ((w.job.modelCalls = (w.job.modelCalls || 0) + 1), w)),
|
|
258
|
-
})
|
|
258
|
+
})
|
|
259
|
+
// 各镜分开画,不给参照就各画各的(V4.1 Flash 实测:同一张地铁图四镜画成四张不同的图,两镜配色都不一样)。
|
|
260
|
+
// 所以先做好一镜,其余的拿它的画面代码做参照,再一起并行做;已经有做好的镜头(续做、重画)就直接用最靠前的那一镜。
|
|
261
|
+
const madeBefore = () => segmentsOf(requireWork(id)).find(s => s.state === 'done' && s.file)
|
|
262
|
+
let rest = pending
|
|
263
|
+
if (!madeBefore() && pending.length > 1) {
|
|
264
|
+
await make(pending[0], null)
|
|
265
|
+
rest = pending.slice(1)
|
|
266
|
+
}
|
|
267
|
+
const lead = madeBefore()
|
|
268
|
+
const reference = lead ? referenceOf(proj, lead.id) : null
|
|
269
|
+
await pool(rest, agents, seg => make(seg, reference && reference.id !== seg.id ? reference : null))
|
|
259
270
|
} finally {
|
|
260
271
|
site.server.closeAllConnections?.()
|
|
261
272
|
site.server.close()
|
|
@@ -411,7 +422,11 @@ export function narrationText(scene) {
|
|
|
411
422
|
return (Array.isArray(n) ? n.join('') : String(n || '')).trim()
|
|
412
423
|
}
|
|
413
424
|
|
|
414
|
-
/**
|
|
425
|
+
/**
|
|
426
|
+
* 和网站沙箱同格式的 job.json(风格包的 setup.py 读它;有口播时它再读旁边的 narration.json)。
|
|
427
|
+
* params.style 是对象(网站是用户的风格偏好,键值对):风格的准备脚本会遍历它找配色等偏好,
|
|
428
|
+
* 写成字符串脚本直接报错、草稿出不来(2026-11-29 踩过:装饰艺术风格的 setup.py)。
|
|
429
|
+
*/
|
|
415
430
|
function writeJobJson(work, fps, size, hasNarration) {
|
|
416
431
|
const segs = segmentsOf(work)
|
|
417
432
|
const scenes = new Map(work.plan.scenes.map(s => [s.id, s]))
|
|
@@ -424,7 +439,7 @@ function writeJobJson(work, fps, size, hasNarration) {
|
|
|
424
439
|
confirmed: {
|
|
425
440
|
inputs: (work.plan.inputs || []).map((x, i) => ({ key: x.key || `k${i + 1}`, label: x.label || '', value: x.value })),
|
|
426
441
|
audio: null,
|
|
427
|
-
params: { aspect: work.aspect, durationSec: segs.reduce((n, s) => n + s.frames, 0) / fps, fps, width: size.width, height: size.height, subtitles: true, ...(work.plan.direction ? { style: work.plan.direction } : {}) },
|
|
442
|
+
params: { aspect: work.aspect, durationSec: segs.reduce((n, s) => n + s.frames, 0) / fps, fps, width: size.width, height: size.height, subtitles: true, ...(work.plan.direction ? { style: { direction: work.plan.direction } } : {}) },
|
|
428
443
|
},
|
|
429
444
|
narration: hasNarration ? { path: 'narration.json' } : null,
|
|
430
445
|
segments: segs.map(s => {
|
package/src/host/quality.js
CHANGED
|
@@ -17,7 +17,9 @@ const SHEET_FRAMES = 6
|
|
|
17
17
|
// 10 秒以上的段取 9 帧(3×3):一段十几二十秒有好几个节拍,6 帧会漏掉
|
|
18
18
|
const SHEET_FRAMES_LONG = 9
|
|
19
19
|
const SHEET_LONG_S = 10
|
|
20
|
-
|
|
20
|
+
// 每帧长边 640:400 的时候小字和被挡住的字在图上根本看不出来(V4.1 Flash 做的片子里,
|
|
21
|
+
// 标签压在线上、色标挤成一团、字被建筑挡住,都是这样漏过去的)
|
|
22
|
+
const SHEET_EDGE = 640
|
|
21
23
|
|
|
22
24
|
/** 检查图取哪几帧(段内帧号):把段均分成 n 份取每份中间那帧,开头和结尾都看得到 */
|
|
23
25
|
export function sheetFrames(frames, fps) {
|
|
@@ -54,19 +56,22 @@ export async function sheetFromVideo(video, picked, signal) {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
const REVIEW_RULES = `You check one segment of a short film before the viewer sees it. The image below is its contact sheet: frames spread evenly across the segment, left to right, top to bottom. The platform adds the subtitles later in the bottom band, so their absence is not a defect.
|
|
59
|
+
const REVIEW_RULES = `You check one segment of a short film before the viewer sees it. The image below is its contact sheet: frames spread evenly across the segment, left to right, top to bottom. The platform adds the subtitles later in the bottom band, so their absence is not a defect. A number still counting up or a text still being typed is not a defect.
|
|
58
60
|
|
|
59
|
-
Report only defects a viewer would notice at once:
|
|
60
|
-
- text overlapping other text or graphics so that it cannot be read;
|
|
61
|
+
Look at every frame, then compare the sheet with what the segment should show (given after the image). Report only defects a viewer would notice at once:
|
|
62
|
+
- text overlapping other text, lines or graphics, or hidden behind a shape, so that it cannot be read;
|
|
61
63
|
- text or a key graphic cut off by the frame edge;
|
|
62
64
|
- a shape, colour block or element that hides the subject or fills a large part of the frame and is clearly not meant to be there (for example a highlight, glow or particle drawn many times too large);
|
|
63
65
|
- a frame that is empty or visibly broken (a deliberate build-up at the very start is fine);
|
|
64
66
|
- garbled or missing characters;
|
|
65
67
|
- on-screen text that contradicts the approved copy;
|
|
66
|
-
- the
|
|
67
|
-
|
|
68
|
+
- something the description says must be on screen is nowhere to be seen in any frame, or is drawn so that it cannot be recognised: its main subject, a title it asks for, a shape it says must close or connect, the colours it names (for example lines that should each have their own colour are all grey);
|
|
69
|
+
- the voice-over at a frame (listed after the image) is about something new, yet nothing in that frame shows it: the picture is still on the previous sentence, or the thing being named is neither drawn nor written (the very first second of a sentence may lag);
|
|
70
|
+
- the content is squeezed into a small part of the frame while about half of the frame or more stays empty in most frames;
|
|
71
|
+
- explanatory text so small that it could not be read on a phone.
|
|
72
|
+
Taste, pacing and small alignment are not defects.
|
|
68
73
|
|
|
69
|
-
Reply with exactly OK if there is none. Otherwise reply with at most
|
|
74
|
+
Reply with exactly OK if there is none. Otherwise reply with at most 4 lines, the worst first, one defect per line: the frame number (1 is the first), what is wrong, and the fix.`
|
|
70
75
|
|
|
71
76
|
/**
|
|
72
77
|
* 看一次检查图。没有毛病返回空串,有毛病返回最多 3 行;看不了抛错。
|
|
@@ -74,24 +79,23 @@ Reply with exactly OK if there is none. Otherwise reply with at most 3 lines, on
|
|
|
74
79
|
*/
|
|
75
80
|
export async function reviewSheet(seg, png, signal) {
|
|
76
81
|
const copy = Object.entries(seg.copy || {}).filter(([, v]) => String(v).trim()).map(([k, v]) => `${k}: ${v}`).join('; ') || '(none)'
|
|
77
|
-
const
|
|
82
|
+
const said = (seg.sentences || []).join(' / ') || '(no voice-over)'
|
|
83
|
+
const about = `Segment title: ${seg.title || seg.id}\nWhat it should show, in order: ${seg.description || '(not given)'}\nOn-screen copy the user approved: ${copy}\nVoice-over, in order: ${said}${seg.direction ? `\nThe film's look: ${seg.direction}` : ''}${seg.frames?.length ? `\nWhat the voice-over is saying at each frame: ${seg.frames.map(f => `frame ${f.n} (${f.sec}s) ${f.saying ? `"${f.saying}"` : '(silence)'}`).join('; ')}` : ''}`
|
|
78
84
|
// 回答最多 3 行,但思考也算输出:上限给宽一点,不然毛病说到一半被截断(网站实测过)
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
signal,
|
|
85
|
-
})
|
|
85
|
+
const messages = [userMessage([{ type: 'text', text: REVIEW_RULES }, await imageBlock(png), { type: 'text', text: about }])]
|
|
86
|
+
const ask = light => chat({ system: 'You review contact sheets of short-film segments.', messages, maxTokens: 16000, light, signal })
|
|
87
|
+
// 中间档推理:最低一档(DeepSeek 是不思考)只会说 OK。中间档偶尔只想不答(回答是空的),这时用最低档再问一次
|
|
88
|
+
let r = await ask('mid')
|
|
89
|
+
if (!r.text.trim()) r = await ask(true)
|
|
86
90
|
const lines = r.text.split('\n').map(l => l.trim()).filter(Boolean)
|
|
87
91
|
if (!lines.length) throw new Error('看检查图没有回答')
|
|
88
92
|
if (lines[0].replace(/\.$/, '').toUpperCase() === 'OK') return ''
|
|
89
|
-
return lines.slice(0,
|
|
93
|
+
return lines.slice(0, 4).join('\n')
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
/** 交回制作会话的话:检查图里看到的毛病 */
|
|
93
97
|
export function reviewReport(segId, picked, notes) {
|
|
94
|
-
return `${segId} is not submitted yet: a reviewer looked at a contact sheet of it (segment frames ${picked.join(', ')}, left to right, top to bottom; frame 1 is the first of them) and found these defects:\n${notes}\nFix
|
|
98
|
+
return `${segId} is not submitted yet: a reviewer looked at a contact sheet of it (segment frames ${picked.join(', ')}, left to right, top to bottom; frame 1 is the first of them) and found these defects:\n${notes}\nFix all of these with one draw call (edits to the current files), and leave everything that was fine as it is. The sheet is looked at again before the segment is rendered.`
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
/* ---------- 画面有没有跟着旁白动 ---------- */
|
package/src/host/segment.js
CHANGED
|
@@ -13,8 +13,8 @@ import { fill, renderCommand, renderPage } from './render.js'
|
|
|
13
13
|
import { motionGray, motionSteps, reviewReport, reviewSheet, sheetFrames, sheetFromImages, sheetFromVideo, stillReport, stillSentences } from './quality.js'
|
|
14
14
|
|
|
15
15
|
// 一个会话最多调用几次工具(防止无限循环)、最多渲染几次;一段最多开几个会话
|
|
16
|
-
const TOOL_CALL_LIMIT =
|
|
17
|
-
const SEGMENT_RENDERS =
|
|
16
|
+
const TOOL_CALL_LIMIT = 16
|
|
17
|
+
const SEGMENT_RENDERS = 8
|
|
18
18
|
const SESSIONS = 2
|
|
19
19
|
// 草稿只贴源文件内容;数据文件只列路径
|
|
20
20
|
const DRAFT_EXT = /\.(js|mjs|ts|tsx|jsx|html|css|md|txt|py|svg|ya?ml)$/i
|
|
@@ -25,6 +25,11 @@ const OUTPUT_TAIL = 4000
|
|
|
25
25
|
const WORK = '/work'
|
|
26
26
|
const PROJ = '/work/proj'
|
|
27
27
|
|
|
28
|
+
// 写画面用第二高的一档推理(见 llm.js 的 chat):DeepSeek 的档位是 关/低/高/最高,以前取「中间」落在「低」上。
|
|
29
|
+
// V4.1 Flash 对照:同样的分镜要求,「低」档一部改了 81 次调用仍没通过检查,「高」档 24 次做成;另两部调用也更少、
|
|
30
|
+
// 画面评分不降。三档的模型(低/中/高)第二高就是中间那档,和以前一样。环境变量 LOVIDEO_SEGMENT_EFFORT=mid 可以切回去对比
|
|
31
|
+
const SEGMENT_EFFORT = process.env.LOVIDEO_SEGMENT_EFFORT === 'mid' ? 'mid' : 'high'
|
|
32
|
+
|
|
28
33
|
const SYSTEM = 'You make one segment of a short film. The first message holds the task, the style Skill and your segment brief; follow it.'
|
|
29
34
|
|
|
30
35
|
const DRAW = {
|
|
@@ -81,6 +86,8 @@ What gets a segment sent back most often, so get it right the first time (where
|
|
|
81
86
|
- Reading time. A text must stay fully on screen at least 1.5 s plus 0.22 s for each Chinese character (0.07 s for each other character) before it leaves or its shot ends: a 6-character label needs about 2.8 s, a 12-character line about 4.2 s. So few and short texts, brought in early; never a text that appears in the last two seconds of its shot.
|
|
82
87
|
- The approved on-screen texts. \`copy\` in your production context lists the texts the user approved for this segment: show each of them, spelled exactly, and take numbers from \`confirmed.inputs\` exactly; add no long text of your own.
|
|
83
88
|
- One action per sentence. Each voice-over sentence gets one clear visible action; few, large elements, not many small ones. Whatever the description names must be recognisable at a glance: simple, deliberate shapes.
|
|
89
|
+
- Draw everything the description asks for. Before you call draw, go through the description clause by clause and the \`copy\` texts one by one and check each is in your scene: a title it asks for, a shape it says must close or connect, the colours it names. Nothing the description lists may be dropped or swapped for something easier.
|
|
90
|
+
- Use the frame. The content fills most of the frame; no large empty area while everything sits small in one corner or one band. Explanatory text is big enough to read on a phone (at least about 3.5% of the frame's height); labels never sit on top of lines, of each other or behind a shape.
|
|
84
91
|
- Start from the prepared draft and keep its structure: replace its sample content with this segment's through \`edits\`; do not rewrite the file from scratch unless the draft cannot hold the scene.
|
|
85
92
|
Write compactly: no comments, no text before or after the call, nothing restated from the brief; draw repeated elements with a loop or a small helper. Compact code must still draw every beat in full.${resume ? `\n\nResume: an earlier attempt at this segment did not finish. ${PROJ}/${segId}/ holds what it left; reuse what is there.` : ''}`
|
|
86
93
|
}
|
|
@@ -93,7 +100,7 @@ function productionContext({ work, segments, seg, fps, size, narration, styleSlu
|
|
|
93
100
|
const lines = (narration?.sentences || []).filter(x => x.segment === seg.id)
|
|
94
101
|
const total = segments.reduce((n, s) => n + s.frames, 0)
|
|
95
102
|
const params = { aspect: work.aspect, fps, durationSec: r3(total / fps), subtitles: work.subtitles?.enabled !== false }
|
|
96
|
-
if (work.plan.direction) params.style = work.plan.direction
|
|
103
|
+
if (work.plan.direction) params.style = { direction: work.plan.direction }
|
|
97
104
|
return {
|
|
98
105
|
confirmed: {
|
|
99
106
|
inputs: (work.plan.inputs || []).map((x, i) => ({ key: x.key || `k${i + 1}`, label: x.label || '', value: x.value })),
|
|
@@ -161,6 +168,37 @@ function preparedText({ proj, segId, styleDir, resume }) {
|
|
|
161
168
|
return parts.join('\n\n')
|
|
162
169
|
}
|
|
163
170
|
|
|
171
|
+
/**
|
|
172
|
+
* 导演要求的屏幕文字里,画面代码里找不到的那几条。不花模型调用:小模型常常悄悄丢掉几条
|
|
173
|
+
* (V4.1 Flash 实测一镜 8 条丢了 3 条,片名大字整个没画)。
|
|
174
|
+
* 一条字可能被组件拆开写(「283 米」写成 value: 283, unit: '米'),所以按「连着的汉字、单词、数字」分块找,每块都在才算有。
|
|
175
|
+
* 代码从 segment.json 的 copy 里取字的(风格的草稿这样写)不查。
|
|
176
|
+
*/
|
|
177
|
+
export function missingCopy(proj, segId, copy) {
|
|
178
|
+
const texts = Object.values(copy || {}).map(x => String(x || '').trim()).filter(Boolean)
|
|
179
|
+
if (!texts.length) return []
|
|
180
|
+
const src = walk(join(proj, segId)).filter(f => /\.(js|mjs|ts|tsx|jsx|html|css|svg)$/i.test(f) && statSync(f).size <= 400_000).map(f => readFileSync(f, 'utf8')).join('\n')
|
|
181
|
+
if (/\bcopy\b/.test(src)) return []
|
|
182
|
+
const flat = src.replace(/\s+/g, '')
|
|
183
|
+
return texts.filter(t => {
|
|
184
|
+
const parts = t.match(/[一-鿿]{2,}|[A-Za-z]{3,}|\d+(?:\.\d+)?/g) || []
|
|
185
|
+
return parts.length > 0 && !parts.every(p => flat.includes(p))
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 这部片子已经做好的一镜(一般是第一镜)的画面代码:后面的镜头照它的版式、配色、名字和位置画,才是同一部片子 */
|
|
190
|
+
export function referenceOf(proj, segId) {
|
|
191
|
+
const files = walk(join(proj, segId)).filter(f => /\.(js|mjs|ts|tsx|jsx|html|css)$/i.test(f) && statSync(f).size <= 24_000)
|
|
192
|
+
if (!files.length) return null
|
|
193
|
+
return { id: segId, files: files.slice(0, 3).map(f => ({ path: `${PROJ}/${relative(proj, f).split(sep).join('/')}`, content: readFileSync(f, 'utf8') })) }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function referenceText(ref) {
|
|
197
|
+
if (!ref?.files?.length) return ''
|
|
198
|
+
const body = ref.files.map(f => `${f.path}:\n\`\`\`js\n${f.content.trimEnd().slice(0, 14_000)}\n\`\`\``).join('\n\n')
|
|
199
|
+
return `Segment ${ref.id} of this film is already made; its files follow (read-only, do not edit them). Your segment must look like the same film: use the same layout constants, palette, sizes, fonts, names and positions for everything that appears in both, and where your description says the picture continues from the previous segment, start from the state that segment ends in. Take its look, not its content.\n\n${body}`
|
|
200
|
+
}
|
|
201
|
+
|
|
164
202
|
/** 这一段目录里唯一的源文件(会话里的写法);没有或不止一个返回 null */
|
|
165
203
|
function onlySource(proj, segId) {
|
|
166
204
|
const files = walk(join(proj, segId)).filter(f => /\.(js|mjs|ts|tsx|jsx|html|css|py|svg)$/i.test(f) && statSync(f).size <= DRAFT_MAX * 4)
|
|
@@ -283,44 +321,53 @@ export async function makeSegmentSession(o) {
|
|
|
283
321
|
const logDir = join(proj, '.log')
|
|
284
322
|
mkdirSync(logDir, { recursive: true })
|
|
285
323
|
const lines = (narration?.sentences || []).filter(x => x.segment === seg.id)
|
|
286
|
-
|
|
324
|
+
// 检查图上每一帧是这一段的第几秒、这时口播在念哪一句:看图的人才判断得了「话讲到了、画面没跟上」
|
|
325
|
+
const sayingAt = sec => lines.find(x => sec >= x.start - seg.start / fps && sec <= x.end - seg.start / fps + 0.25)?.text || ''
|
|
326
|
+
const scene = {
|
|
327
|
+
...(work.plan.scenes.find(s => s.id === seg.id) || seg),
|
|
328
|
+
direction: work.plan.direction || '',
|
|
329
|
+
frames: sheetFrames(seg.frames, fps).map((n, i) => ({ n: i + 1, sec: Math.round((n / fps) * 10) / 10, saying: sayingAt(n / fps) })),
|
|
330
|
+
}
|
|
287
331
|
const seeImages = await canSeeImages(signal)
|
|
288
|
-
//
|
|
289
|
-
// V4.1 Flash
|
|
290
|
-
//
|
|
291
|
-
const left = { review: seeImages ?
|
|
292
|
-
let
|
|
293
|
-
let changedSinceReview = false
|
|
332
|
+
// 网站是检查图、画面变化各只查一次(Opus 改完很少改坏)。小模型被退回后常把别处改坏、或者改了这个漏了那个:
|
|
333
|
+
// V4.1 Flash 实测,查两次以后的第三版不再查,带着整帧空白、切边的字、没画的图形出了片。
|
|
334
|
+
// 所以页面风格每次完整渲染前都先看检查图(只画那几帧,便宜),看到通过为止,最多 4 次;画面变化最多退回两次。
|
|
335
|
+
const left = { review: seeImages ? 4 : 0, motion: lines.length ? 2 : 0 }
|
|
336
|
+
let needReview = true
|
|
294
337
|
let attempts = seg.attempts || 0
|
|
295
338
|
let last = null
|
|
296
339
|
|
|
340
|
+
/**
|
|
341
|
+
* 看一次检查图。接口连接失败不等于画面没问题:等一会儿再看,最多 3 次;
|
|
342
|
+
* 还是看不了才跳过,而且不算看过(下一次渲染前接着看)。返回毛病(空串是没毛病),看不了返回 null
|
|
343
|
+
*/
|
|
297
344
|
const review = async sheet => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
345
|
+
for (let k = 0; k < 3; k++) {
|
|
346
|
+
try {
|
|
347
|
+
const notes = await reviewSheet(scene, sheet, signal)
|
|
348
|
+
left.review--
|
|
349
|
+
return notes
|
|
350
|
+
} catch (e) {
|
|
351
|
+
if (signal.aborted) throw paused()
|
|
352
|
+
await log({ note: `看检查图没成功(第 ${k + 1} 次):${e.message}`.slice(0, 300) })
|
|
353
|
+
await new Promise(ok => setTimeout(ok, 6000 * (k + 1)))
|
|
354
|
+
} finally {
|
|
355
|
+
await countCall()
|
|
356
|
+
}
|
|
309
357
|
}
|
|
358
|
+
return null
|
|
310
359
|
}
|
|
311
360
|
|
|
312
361
|
/** draw 之后:渲染、检查、交段 */
|
|
313
362
|
const submit = async () => {
|
|
314
363
|
const picked = sheetFrames(seg.frames, fps)
|
|
315
|
-
const rejectReview = notes => {
|
|
316
|
-
|
|
317
|
-
return { ok: false, text: reviewReport(seg.id, picked.map(n => n + 1), notes) }
|
|
318
|
-
}
|
|
319
|
-
if (left.review > 0 && !reviewed && spec.page) {
|
|
364
|
+
const rejectReview = notes => ({ ok: false, text: reviewReport(seg.id, picked.map(n => n + 1), notes) })
|
|
365
|
+
if (left.review > 0 && needReview && spec.page) {
|
|
320
366
|
await update({ state: 'check', error: null })
|
|
321
367
|
const shots = await renderPage({ origin: site.origin, entry: fill(spec.page, vars), film, pick: picked, signal })
|
|
322
368
|
const notes = await review(await sheetFromImages(shots, signal))
|
|
323
369
|
if (notes) return rejectReview(notes)
|
|
370
|
+
if (notes === '') needReview = false
|
|
324
371
|
}
|
|
325
372
|
await update({ state: 'render', rendered: 0 })
|
|
326
373
|
let lastTick = 0
|
|
@@ -339,7 +386,7 @@ export async function makeSegmentSession(o) {
|
|
|
339
386
|
const still = stillSentences(motionSteps(gray, frameBytes), lines, seg.start / fps)
|
|
340
387
|
if (still.length) {
|
|
341
388
|
left.motion--
|
|
342
|
-
|
|
389
|
+
needReview = true
|
|
343
390
|
rmSync(out, { force: true })
|
|
344
391
|
return { ok: false, text: stillReport(seg.id, still) }
|
|
345
392
|
}
|
|
@@ -348,14 +395,15 @@ export async function makeSegmentSession(o) {
|
|
|
348
395
|
await log({ note: `画面变化没量成,照常交段:${e.message}`.slice(0, 300) })
|
|
349
396
|
}
|
|
350
397
|
}
|
|
351
|
-
//
|
|
352
|
-
if (left.review > 0 &&
|
|
398
|
+
// 段命令渲染的风格渲染完才看得到画面
|
|
399
|
+
if (left.review > 0 && needReview && !spec.page) {
|
|
353
400
|
await update({ state: 'check' })
|
|
354
401
|
const notes = await review(await sheetFromVideo(out, picked, signal))
|
|
355
402
|
if (notes) {
|
|
356
403
|
rmSync(out, { force: true })
|
|
357
404
|
return rejectReview(notes)
|
|
358
405
|
}
|
|
406
|
+
if (notes === '') needReview = false
|
|
359
407
|
}
|
|
360
408
|
await update({ state: 'done', rendered: seg.frames, file: `segs/${seg.id}.mp4`, poster: `segs/${seg.id}.jpg`, error: null })
|
|
361
409
|
return { ok: true, text: `Segment ${seg.id} is submitted.` }
|
|
@@ -367,6 +415,7 @@ export async function makeSegmentSession(o) {
|
|
|
367
415
|
segmentNote(seg.id, agents, resume, size),
|
|
368
416
|
`Production context (task data, prepared for this attempt):\n${JSON.stringify(productionContext({ work, segments, seg, fps, size, narration, styleSlug: style.slug, redraw }), null, 1)}`,
|
|
369
417
|
preparedText({ proj, segId: seg.id, styleDir: style.dir, resume }),
|
|
418
|
+
referenceText(o.reference),
|
|
370
419
|
seg.brief ? `The user asked to redraw this segment: ${seg.brief}` : '',
|
|
371
420
|
].filter(Boolean).join('\n\n')
|
|
372
421
|
const messages = [userMessage([{ type: 'text', text: shared }, { type: 'text', text: brief }])]
|
|
@@ -374,17 +423,31 @@ export async function makeSegmentSession(o) {
|
|
|
374
423
|
let renders = 0
|
|
375
424
|
let nudged = 0
|
|
376
425
|
let lastWritten = null
|
|
426
|
+
let badJson = 0
|
|
427
|
+
let netErrors = 0
|
|
428
|
+
let copyChecks = 0
|
|
377
429
|
while (calls < TOOL_CALL_LIMIT && renders < SEGMENT_RENDERS) {
|
|
378
430
|
if (signal.aborted) throw paused()
|
|
379
431
|
attempts++
|
|
380
432
|
await update({ state: 'draw', attempts, error: null })
|
|
381
433
|
let reply
|
|
382
434
|
try {
|
|
383
|
-
reply = await chat({ system: SYSTEM, messages, tools: [DRAW, READ], maxTokens: 64000, light:
|
|
435
|
+
reply = await chat({ system: SYSTEM, messages, tools: [DRAW, READ], maxTokens: 64000, light: SEGMENT_EFFORT, signal })
|
|
384
436
|
} catch (e) {
|
|
385
437
|
if (signal.aborted) throw paused()
|
|
386
438
|
last = `模型调用失败:${e.message}`
|
|
387
439
|
await log({ attempt: attempts, error: last.slice(0, 400) })
|
|
440
|
+
// 小模型偶尔在工具参数里写出坏的 JSON,整次调用报错(V4.1 Flash 一段里出现过 3 次):
|
|
441
|
+
// 这不是会话坏了,原地再要一次;连着两次才换新会话
|
|
442
|
+
if (/invalid JSON/i.test(e.message) && badJson++ < 2) continue
|
|
443
|
+
// 网络抖动、接口限流或过载:等一会儿原地再试,不算这个会话坏了(一次连接失败就放弃,整部片子会跟着失败)
|
|
444
|
+
if (/transport|network|fetch failed|timed? ?out|ECONN|ETIMEDOUT|EAI_AGAIN|socket|overload|rate.?limit|\b(429|500|502|503|504|529)\b/i.test(e.message) && netErrors++ < 4) {
|
|
445
|
+
await new Promise((ok, no) => {
|
|
446
|
+
const t = setTimeout(ok, 5000 * netErrors)
|
|
447
|
+
signal.addEventListener('abort', () => (clearTimeout(t), no(paused())), { once: true })
|
|
448
|
+
})
|
|
449
|
+
continue
|
|
450
|
+
}
|
|
388
451
|
break
|
|
389
452
|
} finally {
|
|
390
453
|
await countCall()
|
|
@@ -421,6 +484,12 @@ export async function makeSegmentSession(o) {
|
|
|
421
484
|
}
|
|
422
485
|
if (call.name !== 'draw') throw new Error(`no tool named ${call.name}; use draw or read`)
|
|
423
486
|
lastWritten = applyDraw(args, place, lastWritten || onlySource(proj, seg.id)) || lastWritten
|
|
487
|
+
// 导演要求的屏幕文字少了:不渲染,直接退回(最多拦两次,免得卡死在一条写法不同的字上)
|
|
488
|
+
const dropped = copyChecks < 2 ? missingCopy(proj, seg.id, scene.copy) : []
|
|
489
|
+
if (dropped.length) {
|
|
490
|
+
copyChecks++
|
|
491
|
+
throw new Error(`These approved on-screen texts are not in your scene: ${dropped.map(x => `"${x}"`).join(', ')}. Show each of them on screen, spelled exactly as given (a text may be split into a label and a number), each long enough to be read. Nothing was rendered`)
|
|
492
|
+
}
|
|
424
493
|
renders++
|
|
425
494
|
const r = await submit()
|
|
426
495
|
if (r.ok) {
|
package/src/host/tools.js
CHANGED
|
@@ -388,7 +388,7 @@ const SCENE = {
|
|
|
388
388
|
properties: {
|
|
389
389
|
title: { type: 'string', description: '这一镜的标题,4 到 12 个字' },
|
|
390
390
|
description: { type: 'string', description: `这一镜的画面,写给制作看(它只看得到这一镜)。最多 ${DESCRIPTION_MAX} 个字,超了整版退回。写法:按口播的句子顺序,一句口播对一个画面动作(什么东西出现、怎么动),用分号隔开;不写一长串镜头调度,不写画不完的东西。同一个东西各镜用同一个名字` },
|
|
391
|
-
narration: { type: 'array', items: { type: 'string' }, description: `这一镜的口播,一句一项,按念的顺序,最多 ${SENTENCES_MAX} 句。每句都是带具体信息的完整句子:最多 ${SENTENCE_MAX} 个字符(长句在自然停顿处拆成两项),最少 ${SENTENCE_MIN_HAN} 个汉字(「慢慢来。」这种凑数的短句并进相邻的句子),不合格整版退回。数字写阿拉伯数字。不要旁白就给空数组。全片口播总字数约等于「片长秒数 ×
|
|
391
|
+
narration: { type: 'array', items: { type: 'string' }, description: `这一镜的口播,一句一项,按念的顺序,最多 ${SENTENCES_MAX} 句。每句都是带具体信息的完整句子:最多 ${SENTENCE_MAX} 个字符(长句在自然停顿处拆成两项),最少 ${SENTENCE_MIN_HAN} 个汉字(「慢慢来。」这种凑数的短句并进相邻的句子),不合格整版退回。数字写阿拉伯数字。不要旁白就给空数组。全片口播总字数约等于「片长秒数 × 3.5」,连数字和标点一起算(10 秒约 35 字、30 秒约 105 字、60 秒约 210 字;英文每秒约 2.2 个词),按镜头分下去;30 秒以上的片子每镜至少 15 秒` },
|
|
392
392
|
screen_text: { type: 'array', maxItems: 8, items: { type: 'string' }, description: `这一镜屏幕上要出现的字:标题、标签、关键数字,每条最多 ${SCREEN_TEXT_MAX} 个字,按出现的顺序。用词和口播里的说法一致(口播说「马龙峰 4122 米」,屏幕就写「马龙峰 4122 米」)。每条字要在画面上停够时间才读得完(约 1.5 秒加每个字 0.2 秒),所以宁少勿多:一句口播最多配一两条。不需要屏幕文字就不填` },
|
|
393
393
|
seconds: { type: 'number', description: '只在没有口播时填:这一镜几秒(15 到 60)。有口播时不用填,长度由口播念完的时间决定' },
|
|
394
394
|
},
|
|
@@ -401,13 +401,13 @@ const plan = tool({
|
|
|
401
401
|
name: 'lovideo_plan',
|
|
402
402
|
description: '出分镜或改分镜(每次都给完整的分镜)。先把用户给的事实列进 facts,再排镜头,每条事实都要落到某一镜的口播或屏幕文字里。镜头少而长:大约每 15 到 25 秒一镜,一镜里按口播顺序装好几个画面变化,不要给单独一个节拍或标题卡开一镜。分镜以卡片展示给用户,卡片上有「确认开拍」按钮,卡片自己会请用户审阅,调用后这一轮就结束,不要再问要不要开拍。只在用户确认(点按钮或明确说开拍)后才调用 lovideo_produce;改分镜就带上 work_id 再调用一次本工具。成片已经做好后,用户只想改某几镜(字幕、口播、重画、裁短、调顺序)时不要用本工具,用 lovideo_revise;改分镜后重新开拍时,没改动的镜头会自动沿用。',
|
|
403
403
|
parameters: {
|
|
404
|
-
type: 'object', additionalProperties: false, required: ['title', 'style', 'duration', 'scenes', 'voice', 'music', 'subtitles'],
|
|
404
|
+
type: 'object', additionalProperties: false, required: ['title', 'style', 'aspect', 'duration', 'direction', 'scenes', 'voice', 'music', 'subtitles'],
|
|
405
405
|
properties: {
|
|
406
406
|
work_id: { type: 'string', description: '改已有作品的分镜时填;新片子不填' },
|
|
407
407
|
title: { type: 'string', description: '片名' },
|
|
408
408
|
style: { type: 'string', description: '风格 slug(来自 lovideo_styles)' },
|
|
409
|
-
aspect: { type: 'string', enum: Object.keys(ASPECTS), description: '
|
|
410
|
-
duration: { type: 'integer', minimum: FILM_DURATIONS[0], maximum: FILM_DURATIONS.at(-1), description: `目标片长(秒),${FILM_DURATIONS[0]} 到 ${FILM_DURATIONS.at(-1)}
|
|
409
|
+
aspect: { type: 'string', enum: Object.keys(ASPECTS), description: '画幅,必填:16:9 横版、9:16 竖版、3:4 竖版。用户这条消息里写了「竖版」「横版」或比例,就照用户写的(只说「竖版」是 9:16);没写就用输入框里选的;都没有再用风格的第一个画幅。改分镜时照原来的填。只能填这个风格支持的画幅' },
|
|
410
|
+
duration: { type: 'integer', minimum: FILM_DURATIONS[0], maximum: FILM_DURATIONS.at(-1), description: `目标片长(秒),${FILM_DURATIONS[0]} 到 ${FILM_DURATIONS.at(-1)}。用户这条消息里写了片长(「30 秒」「一分钟」)就照用户写的,取 ${FILM_DURATIONS.join('、')} 里最近的一档;没写就用输入框里选的秒数;都没有就 ${DEFAULT_DURATION}。这是目标不是指标:素材撑不满就做短一点,不要凑;镜头数不超过「片长 ÷ ${MIN_SHOT_SEC}」` },
|
|
411
411
|
subtitles: { type: 'boolean', description: '要不要字幕(字幕就是口播原文)。有配音时一般要;用户说不要就 false' },
|
|
412
412
|
voice: {
|
|
413
413
|
type: 'object', additionalProperties: false, required: ['use', 'why'],
|
|
@@ -427,7 +427,7 @@ const plan = tool({
|
|
|
427
427
|
},
|
|
428
428
|
},
|
|
429
429
|
facts: { type: 'array', maxItems: 16, items: { type: 'string' }, description: '这部片子要讲的事实,从用户的话和资料里一条条摘出来,数字、名字照原样(例如「马龙峰海拔 4122 米」「2023 年 12 月 6 日开业」)。出分镜前先列它,再把每一条安排进某一镜的口播或屏幕文字;带数字的事实如果哪儿都没用上,分镜会被退回(确实不讲就从这里删掉)。用户没给具体事实就不填' },
|
|
430
|
-
direction: { type: 'string', description: '
|
|
430
|
+
direction: { type: 'string', description: '整片的画面设定,必填,60 到 400 个字,用用户的语言写。每一镜由单独的制作模型画,都靠它画成同一部片子:贯穿各镜的主体长什么样、在画面的什么位置;主色、强调色各是什么、用在哪;字放在哪、多大;镜头怎么走、节奏快慢。后一镜接着前一镜的画面时在这里写明(比如「全片是同一张线路图,一镜一镜往上加线」)。照风格的制作说明写,不要和它冲突' },
|
|
431
431
|
scenes: { type: 'array', minItems: 1, maxItems: 20, items: SCENE },
|
|
432
432
|
note: { type: 'string', description: '这一版改了什么(改分镜时填,会显示在卡片上)' },
|
|
433
433
|
},
|
|
@@ -470,6 +470,7 @@ const plan = tool({
|
|
|
470
470
|
const longText = Object.values(s.copy).filter(x => [...x].length > SCREEN_TEXT_MAX)
|
|
471
471
|
if (longText.length) problems.push(`第 ${i + 1} 镜的屏幕文字太长:${longText.map(x => `「${x}」`).join('')}。每条最多 ${SCREEN_TEXT_MAX} 个字,观众来不及读长句`)
|
|
472
472
|
})
|
|
473
|
+
if ([...String(args.direction || '').trim()].length < 60) problems.push('direction(整片的画面设定)太短,至少 60 个字:写清贯穿各镜的主体长什么样、放在哪,主色和强调色,字的位置和大小,镜头怎么走。各镜分开画,全靠它画成同一部片子')
|
|
473
474
|
const facts = (Array.isArray(args.facts) ? args.facts : []).map(x => String(x || '').trim()).filter(Boolean)
|
|
474
475
|
const said = scenes.map(s => `${s.sentences.join(' ')} ${Object.values(s.copy).join(' ')}`).join(' ')
|
|
475
476
|
const unused = facts.filter(f => numbersIn(f).length && !numbersIn(f).some(n => said.includes(n)))
|
|
@@ -485,7 +486,7 @@ const plan = tool({
|
|
|
485
486
|
}
|
|
486
487
|
const est = scenes.reduce((n, s) => n + s.seconds, 0)
|
|
487
488
|
// 直接告诉导演字数预算:中文每秒约 4.5 个字,所以「片长 × 4.5」就是全片口播的字数上限(短片最容易超)
|
|
488
|
-
if (est > Math.max(duration * 1.15, duration + 3)) throw fixable(`这版分镜估计约 ${Math.round(est)} 秒,比目标片长 ${duration} 秒长。全片口播一共写约 ${Math.round(duration *
|
|
489
|
+
if (est > Math.max(duration * 1.15, duration + 3)) throw fixable(`这版分镜估计约 ${Math.round(est)} 秒,比目标片长 ${duration} 秒长。全片口播一共写约 ${Math.round(duration * 3.5)} 个字以内(配音每秒约 4 个字,逗号还要停顿,数字每一位算一个字),删掉信息量最少的句子后再出;用户给的事实尽量留着,删修饰和重复`)
|
|
489
490
|
// 比目标短很多:提醒导演还能不能补有用的内容;补不了就保持短(不在这里报错,内容优先)
|
|
490
491
|
const short = est < duration * 0.7 ? `这版约 ${Math.round(est)} 秒,比目标 ${duration} 秒短。如果用户给的资料里、或用 web_search 搜到的可靠资料里还有值得讲的具体内容,可以补进来再出一版;没有就保持现在的长度,不要凑。` : ''
|
|
491
492
|
const pickOn = (key, suggested) => (typeof userSet[key] === 'boolean' ? userSet[key] : suggested)
|