@speclip/pi-talking-head 0.1.3 → 0.1.4
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/README.md +55 -16
- package/extensions/talking-head/index.ts +70 -3
- package/package.json +1 -1
- package/prompts/edit-talking-head.md +1 -1
- package/skills/talking-head-edit/SKILL.md +6 -5
- package/skills/talking-head-edit/references/cut-craft.md +1 -0
- package/src/continuity.ts +355 -0
- package/src/contracts.ts +45 -0
- package/src/project.ts +51 -5
package/README.md
CHANGED
|
@@ -71,9 +71,54 @@ talking_head_get {
|
|
|
71
71
|
|
|
72
72
|
只有调用这个工具时才会把这些证据放进当前会话上下文;安装 package 不会把整份转录常驻注入上下文。
|
|
73
73
|
|
|
74
|
-
### 3.
|
|
74
|
+
### 3. 先规划 B-roll 视觉连续性
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
在查找素材前,把最终 A-roll 和所有 B-roll 需求交给连续性规划工具:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
talking_head_broll_plan {
|
|
80
|
+
projectId: "launch-video",
|
|
81
|
+
aroll: [
|
|
82
|
+
{ id: "hook", sourceStartMs: 50, sourceEndMs: 4120 },
|
|
83
|
+
{ id: "answer", sourceStartMs: 4860, sourceEndMs: 13200 }
|
|
84
|
+
],
|
|
85
|
+
needs: [
|
|
86
|
+
{
|
|
87
|
+
id: "product-a",
|
|
88
|
+
outputStartMs: 1000,
|
|
89
|
+
outputEndMs: 3000,
|
|
90
|
+
speechText: "第一步打开设置",
|
|
91
|
+
purpose: "demonstrate",
|
|
92
|
+
searchTerms: ["设置", "打开"],
|
|
93
|
+
reason: "展示第一步"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "product-b",
|
|
97
|
+
outputStartMs: 3300,
|
|
98
|
+
outputEndMs: 5200,
|
|
99
|
+
speechText: "第二步选择设备",
|
|
100
|
+
purpose: "demonstrate",
|
|
101
|
+
searchTerms: ["设备", "选择"],
|
|
102
|
+
reason: "展示第二步"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
cutCoverBeforeMs: 250,
|
|
106
|
+
cutCoverAfterMs: 500
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
规划结果同时返回 `continuityPlanReceipt`,把当前项目 revision、A-roll、规划后的 B-roll 区间和跳点审阅结果绑定在一起。后续 `talking_head_apply` 会重新计算并核对它,不能跳过规划或把已经衔接的区间手动缩短。
|
|
111
|
+
|
|
112
|
+
规划结果处理两类问题:
|
|
113
|
+
|
|
114
|
+
- **B-roll 闪屏**:两个 B-roll 之间只露出不超过 500ms 的 A-roll 时,`plan.needs` 会把前一个需求延长到后一个需求的起点。后续分别选段后,两段 B-roll 会直接交接,不再闪回 A-roll。
|
|
115
|
+
- **气口剪辑跳转**:A-roll 相邻片段的源时间不连续时,会生成 `jumpCuts`。工具检查建议遮盖区间是否已被 B-roll 连续覆盖;未覆盖项标为 `needs-broll`,Agent 应结合口播语义补充 `purpose: "mask-cut"` 的需求,再重新规划。
|
|
116
|
+
|
|
117
|
+
规划只提供时间轴证据,不会假定每个剪辑点都必须加 B-roll。是否遮盖仍需结合实际画面判断。
|
|
118
|
+
|
|
119
|
+
### 4. 文件名优先筛选 B-roll
|
|
120
|
+
|
|
121
|
+
使用 `plan.needs` 中已经调整过的完整区间,再扫描指定素材目录:
|
|
77
122
|
|
|
78
123
|
```js
|
|
79
124
|
talking_head_broll_match {
|
|
@@ -85,15 +130,7 @@ talking_head_broll_match {
|
|
|
85
130
|
maxDepth: 12,
|
|
86
131
|
maxCandidates: 5,
|
|
87
132
|
candidateOffset: 0,
|
|
88
|
-
need:
|
|
89
|
-
id: "mouse-demo",
|
|
90
|
-
outputStartMs: 5200,
|
|
91
|
-
outputEndMs: 8200,
|
|
92
|
-
speechText: "电脑除了键盘,还需要鼠标",
|
|
93
|
-
purpose: "demonstrate",
|
|
94
|
-
searchTerms: ["鼠标", "操作"],
|
|
95
|
-
reason: "展示口播提到的具体对象和动作"
|
|
96
|
-
}
|
|
133
|
+
need: plan.needs[0]
|
|
97
134
|
}
|
|
98
135
|
```
|
|
99
136
|
|
|
@@ -121,23 +158,24 @@ talking_head_broll_select {
|
|
|
121
158
|
|
|
122
159
|
该工具会验证素材 SHA-256、manifest 分析范围、起始帧和覆盖片段尾部的证据时间戳,返回可直接交给 `talking_head_apply` 的完整 placement。placement 内含选择凭证;不要手写或删除其中字段。
|
|
123
160
|
|
|
124
|
-
###
|
|
161
|
+
### 5. 写入人工确认后的时间线
|
|
125
162
|
|
|
126
163
|
```js
|
|
127
164
|
talking_head_apply {
|
|
128
165
|
projectId: "launch-video",
|
|
129
166
|
expectedRevision: 1,
|
|
130
|
-
|
|
167
|
+
aroll: [
|
|
131
168
|
{ id: "hook", sourceStartMs: 50, sourceEndMs: 4120 },
|
|
132
169
|
{ id: "answer", sourceStartMs: 4860, sourceEndMs: 13200 }
|
|
133
170
|
],
|
|
134
|
-
broll: [
|
|
171
|
+
broll: [selectionA.placement, selectionB.placement],
|
|
172
|
+
continuityPlanReceipt
|
|
135
173
|
}
|
|
136
174
|
```
|
|
137
175
|
|
|
138
|
-
B-roll 使用成片时间轴定位,`assetStartMs` 来自联络表 manifest,并永远保留主口播音轨。`talking_head_apply`
|
|
176
|
+
B-roll 使用成片时间轴定位,`assetStartMs` 来自联络表 manifest,并永远保留主口播音轨。`talking_head_apply` 会重新校验连续性规划凭证、选段凭证、素材与 manifest 的 SHA-256;规划区间或时间点被手改、素材被替换都会拒绝写入新修订。若两个 B-roll 之间仍存在不超过 500ms 的 A-roll,也会拒绝写入并要求重新规划。当前不支持 B-roll 相互重叠,因为未定义 z-order。
|
|
139
177
|
|
|
140
|
-
###
|
|
178
|
+
### 6. 交给 pi-media 渲染
|
|
141
179
|
|
|
142
180
|
先用同一个源文件创建 `pi-media` 项目,再把上一步的 `mediaOperation` 原样传入:
|
|
143
181
|
|
|
@@ -165,6 +203,7 @@ review { path: "out/launch-final.mp4" }
|
|
|
165
203
|
| --- | --- |
|
|
166
204
|
| `talking_head_create` | 从视频和词级转录建立 revision 1,分析句子、语气词、重复和停顿并生成默认 EDL |
|
|
167
205
|
| `talking_head_get` | 读取指定 revision,分页返回整句与编辑候选,可选导出 pi-media EDL |
|
|
206
|
+
| `talking_head_broll_plan` | 衔接相邻 B-roll、识别 A-roll 跳点并报告尚未遮盖的剪辑区间 |
|
|
168
207
|
| `talking_head_broll_match` | 只用文件名和目录名匹配本地 B-roll,返回受限 shortlist 与视觉升级建议 |
|
|
169
208
|
| `talking_head_broll_select` | 用 pi-media 联络表 manifest 验证具体源时间段并生成 placement |
|
|
170
209
|
| `talking_head_apply` | 写入新的不可变口播 revision,并返回 pi-media EDL |
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { matchWorkspaceBrollAssets, selectBrollWindow } from "../../src/broll.ts";
|
|
4
|
+
import { createBrollContinuityPlanReceipt, planBrollContinuity } from "../../src/continuity.ts";
|
|
4
5
|
import { toMediaTimelineOperation } from "../../src/edl.ts";
|
|
5
6
|
import {
|
|
6
7
|
applyTimeline,
|
|
@@ -23,7 +24,7 @@ const stableId = Type.String({
|
|
|
23
24
|
pattern: "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$",
|
|
24
25
|
});
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
+
const arollSegment = Type.Object({
|
|
27
28
|
id: stableId,
|
|
28
29
|
sourceStartMs: Type.Number({ minimum: 0 }),
|
|
29
30
|
sourceEndMs: Type.Number({ exclusiveMinimum: 0 }),
|
|
@@ -66,6 +67,34 @@ const brollNeed = Type.Object({
|
|
|
66
67
|
reason: Type.String({ minLength: 1, maxLength: 1_000 }),
|
|
67
68
|
}, { additionalProperties: false });
|
|
68
69
|
|
|
70
|
+
const arollJumpCut = Type.Object({
|
|
71
|
+
fromSegmentId: stableId,
|
|
72
|
+
toSegmentId: stableId,
|
|
73
|
+
outputTimeMs: Type.Number({ minimum: 0 }),
|
|
74
|
+
sourceDeltaMs: Type.Number(),
|
|
75
|
+
suggestedOutputStartMs: Type.Number({ minimum: 0 }),
|
|
76
|
+
suggestedOutputEndMs: Type.Number({ minimum: 0 }),
|
|
77
|
+
coveredByNeedIds: Type.Array(stableId, { maxItems: 500 }),
|
|
78
|
+
status: Type.Union([Type.Literal("covered"), Type.Literal("needs-broll")]),
|
|
79
|
+
}, { additionalProperties: false });
|
|
80
|
+
|
|
81
|
+
const continuityPlanReceipt = Type.Object({
|
|
82
|
+
schemaVersion: Type.Literal(1),
|
|
83
|
+
projectId: stableId,
|
|
84
|
+
revision: Type.Integer({ minimum: 1 }),
|
|
85
|
+
arollSha256: Type.String({ pattern: "^[a-f0-9]{64}$" }),
|
|
86
|
+
shortGapMs: Type.Integer({ minimum: 0, maximum: 2_000 }),
|
|
87
|
+
cutCoverBeforeMs: Type.Integer({ minimum: 0, maximum: 2_000 }),
|
|
88
|
+
cutCoverAfterMs: Type.Integer({ minimum: 0, maximum: 2_000 }),
|
|
89
|
+
needs: Type.Array(Type.Object({
|
|
90
|
+
id: stableId,
|
|
91
|
+
outputStartMs: Type.Number({ minimum: 0 }),
|
|
92
|
+
outputEndMs: Type.Number({ exclusiveMinimum: 0 }),
|
|
93
|
+
}, { additionalProperties: false }), { maxItems: 500 }),
|
|
94
|
+
jumpCuts: Type.Array(arollJumpCut, { maxItems: 999 }),
|
|
95
|
+
planSha256: Type.String({ pattern: "^[a-f0-9]{64}$" }),
|
|
96
|
+
}, { additionalProperties: false });
|
|
97
|
+
|
|
69
98
|
export default function talkingHead(pi: ExtensionAPI): void {
|
|
70
99
|
pi.registerTool({
|
|
71
100
|
name: "talking_head_create",
|
|
@@ -168,6 +197,43 @@ export default function talkingHead(pi: ExtensionAPI): void {
|
|
|
168
197
|
},
|
|
169
198
|
});
|
|
170
199
|
|
|
200
|
+
pi.registerTool({
|
|
201
|
+
name: "talking_head_broll_plan",
|
|
202
|
+
label: "Plan B-roll visual continuity",
|
|
203
|
+
description: "Plan B-roll windows before asset matching. Bridges brief A-roll flashes between neighboring B-roll needs and reports A-roll source jump cuts that still need a mask-cut B-roll.",
|
|
204
|
+
parameters: Type.Object({
|
|
205
|
+
projectId: stableId,
|
|
206
|
+
revision: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
207
|
+
aroll: Type.Array(arollSegment, { minItems: 1, maxItems: 1_000 }),
|
|
208
|
+
needs: Type.Array(brollNeed, { maxItems: 500 }),
|
|
209
|
+
cutCoverBeforeMs: Type.Optional(Type.Integer({ minimum: 0, maximum: 2_000, default: 250 })),
|
|
210
|
+
cutCoverAfterMs: Type.Optional(Type.Integer({ minimum: 0, maximum: 2_000, default: 500 })),
|
|
211
|
+
}, { additionalProperties: false }),
|
|
212
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
213
|
+
const { snapshot } = await getTalkingHeadProject(ctx.cwd, params.projectId, params.revision);
|
|
214
|
+
const plan = planBrollContinuity({
|
|
215
|
+
aroll: params.aroll,
|
|
216
|
+
needs: params.needs,
|
|
217
|
+
...(params.cutCoverBeforeMs === undefined ? {} : { cutCoverBeforeMs: params.cutCoverBeforeMs }),
|
|
218
|
+
...(params.cutCoverAfterMs === undefined ? {} : { cutCoverAfterMs: params.cutCoverAfterMs }),
|
|
219
|
+
});
|
|
220
|
+
return result({
|
|
221
|
+
projectId: params.projectId,
|
|
222
|
+
revision: snapshot.revision,
|
|
223
|
+
plan,
|
|
224
|
+
continuityPlanReceipt: createBrollContinuityPlanReceipt(
|
|
225
|
+
params.projectId,
|
|
226
|
+
snapshot.revision,
|
|
227
|
+
params.aroll,
|
|
228
|
+
plan,
|
|
229
|
+
),
|
|
230
|
+
nextStep: plan.jumpCuts.some((cut) => cut.status === "needs-broll")
|
|
231
|
+
? "Create purpose=mask-cut needs for uncovered jump cuts, then run this planner again before asset matching."
|
|
232
|
+
: "Use plan.needs for B-roll asset matching and source-window selection.",
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
171
237
|
pi.registerTool({
|
|
172
238
|
name: "talking_head_broll_match",
|
|
173
239
|
label: "Match local B-roll assets",
|
|
@@ -242,12 +308,13 @@ export default function talkingHead(pi: ExtensionAPI): void {
|
|
|
242
308
|
pi.registerTool({
|
|
243
309
|
name: "talking_head_apply",
|
|
244
310
|
label: "Apply talking-head timeline",
|
|
245
|
-
description: "Create a new immutable talking-head revision from word-boundary A-roll ranges and optional B-roll placements. Returns a generic pi-media timeline operation ready for edit_apply.",
|
|
311
|
+
description: "Create a new immutable talking-head revision from word-boundary A-roll ranges and optional B-roll placements. B-roll requires the matching continuity plan receipt; brief A-roll flashes, unplanned ranges, and overlapping B-roll are rejected. Returns a generic pi-media timeline operation ready for edit_apply.",
|
|
246
312
|
parameters: Type.Object({
|
|
247
313
|
projectId: stableId,
|
|
248
314
|
expectedRevision: Type.Integer({ minimum: 1 }),
|
|
249
|
-
aroll: Type.Array(
|
|
315
|
+
aroll: Type.Array(arollSegment, { minItems: 1, maxItems: 1_000 }),
|
|
250
316
|
broll: Type.Array(brollPlacement, { maxItems: 500 }),
|
|
317
|
+
continuityPlanReceipt: Type.Optional(continuityPlanReceipt),
|
|
251
318
|
}, { additionalProperties: false }),
|
|
252
319
|
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
253
320
|
const current = await getTalkingHeadProject(ctx.cwd, params.projectId);
|
package/package.json
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
description: Tighten a talking-head video without destroying natural speech rhythm
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
Use the `talking-head-edit` skill to review full-sentence context, word-level pauses, filler words, adjacent repetitions, and low-confidence delivery cues; stabilize A-roll, match B-roll by filename before escalating through paged contact-sheet batches, validate the selected manifest-backed source window, and export a generic pi-media EDL for this request: $@
|
|
5
|
+
Use the `talking-head-edit` skill to review full-sentence context, word-level pauses, filler words, adjacent repetitions, and low-confidence delivery cues; stabilize A-roll, plan B-roll continuity to bridge brief A-roll flashes and mask objectionable jump cuts, match B-roll by filename before escalating through paged contact-sheet batches, validate the selected manifest-backed source window, and export a generic pi-media EDL for this request: $@
|
|
6
6
|
|
|
7
7
|
Show the proposed rhythm before writing a new revision. Never overwrite the source or an existing render.
|
|
@@ -13,15 +13,16 @@ Use `pi-speech` for word evidence, this package for editorial decisions, and `pi
|
|
|
13
13
|
4. Never delete a filler token automatically. Decide whether `啊`, `额`, `嗯`, or a repeated token is a false start, a discourse marker, or intentional emphasis from its sentence context. A text-only delivery cue is low-confidence evidence; review audio and picture before relying on emotion or performance intent.
|
|
14
14
|
5. Before changing the revision, summarize the proposed rhythm: what words and gaps will be removed, which pauses or fillers will remain, and why. Get the user's approval unless they explicitly delegated editorial judgment.
|
|
15
15
|
6. Stabilize A-roll before B-roll. For every B-roll window, record the output range, complete spoken text, one purpose (`demonstrate`, `explain`, `evidence`, `establish`, `transition`, or `mask-cut`), 1-20 concise search terms, and a concrete reason.
|
|
16
|
-
7. Call `
|
|
16
|
+
7. Call `talking_head_broll_plan` with the final proposed A-roll and all semantic B-roll needs before matching assets. Keep its `continuityPlanReceipt` unchanged. Use the returned `plan.needs`: it extends the previous B-roll across A-roll gaps of 500ms or less so neighboring B-roll clips hand off directly. Review every reported A-roll jump cut. Add a `purpose: mask-cut` need over each visually objectionable uncovered cut, using the suggested output range, then rerun the plan. Do not create meaningless B-roll solely because a cut exists; picture review remains the editorial gate.
|
|
17
|
+
8. Call `talking_head_broll_match` before generating contact sheets. Follow its bounded result:
|
|
17
18
|
- `filename-direct`: probe and visually inspect only the selected asset to choose its source window. Do not call `media_contact_sheet` for unselected assets.
|
|
18
19
|
- `filename-shortlist`: inspect only the returned shortlist and stop as soon as one asset satisfies the need. If none does and `nextCandidateOffset` is non-null, request that next page; do not repeat the first batch.
|
|
19
20
|
- `visual-fallback`: use low-cost contact sheets on the bounded shortlist because filenames supplied no useful evidence. Exhaust that batch before requesting a non-null `nextCandidateOffset`.
|
|
20
21
|
- If the scan is truncated, do not paginate it: narrow the asset directory and rescan so the candidate inventory is stable.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
9. After selecting one asset, call `media_probe`, then use `media_contact_sheet` only as densely as timing requires: one high-density pass for a short ambiguous clip, medium for a normal clip, or low over a long clip followed by high density over the narrowed range. Read `contact_sheet_manifest.json` timestamps instead of guessing times from the PNG. Verify a continuous source window at least as long as the planned output window, preferably with 500ms handles on both sides.
|
|
23
|
+
10. Call `talking_head_broll_select` with each planned need, selected asset, manifest path, exact source start, and the manifest timestamps actually reviewed. Use its complete returned `placement`, including `selectionReceipt`; do not shorten bridged output ranges or hand-author selection fields.
|
|
24
|
+
11. Call `talking_head_apply` using the same planned A-roll, every validated B-roll placement, and the unchanged `continuityPlanReceipt`. The tool rejects unplanned ranges, B-roll overlaps, and A-roll flashes of 500ms or less. Every B-roll window must have a concrete visual purpose in `reason`; keep `audio: keep-primary`.
|
|
25
|
+
12. Create/read a `pi-media` project for the same source. Pass the returned `mediaOperation` unchanged to `edit_apply`, then `render` the exact new revision and call `review`.
|
|
25
26
|
|
|
26
27
|
Never overwrite source media or outputs. If a revision conflict occurs, re-read both projects and reconcile intent. If the source, transcript, or B-roll hash changed, stop and ask whether to create a new project rather than silently adopting new bytes.
|
|
27
28
|
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
- Start with filename and directory metadata. Generate contact sheets only for the selected asset, a bounded ambiguous shortlist, or a bounded fallback batch whose names carry no meaning.
|
|
24
24
|
- For a long selected asset, locate a broad range cheaply and then generate a denser contact sheet only for that range. Use manifest timestamps, not visual timestamp transcription.
|
|
25
25
|
- Ensure the selected source window covers the complete spoken beat. Prefer extra source handles so a later timing adjustment does not require rescanning.
|
|
26
|
+
- If neighboring B-roll windows expose 500ms or less of A-roll, plan a direct handoff by extending the previous B-roll need before source-window selection. Do not let a few frames of A-roll flash between overlays.
|
|
26
27
|
- Cover visible jump cuts when appropriate, but do not hide continuity errors that change meaning.
|
|
27
28
|
- Keep the primary voice track. B-roll audio replacement is outside the current contract.
|
|
28
29
|
- Record the search query and editorial reason so a later agent can replace the asset without guessing intent.
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
ArollJumpCut,
|
|
4
|
+
ArollSegment,
|
|
5
|
+
BrollContinuityBridge,
|
|
6
|
+
BrollContinuityPlan,
|
|
7
|
+
BrollContinuityPlanReceipt,
|
|
8
|
+
BrollNeed,
|
|
9
|
+
} from "./contracts.ts";
|
|
10
|
+
import { timelineDuration } from "./transcript.ts";
|
|
11
|
+
|
|
12
|
+
export interface PlanBrollContinuityInput {
|
|
13
|
+
aroll: ArollSegment[];
|
|
14
|
+
needs: BrollNeed[];
|
|
15
|
+
shortGapMs?: number;
|
|
16
|
+
cutCoverBeforeMs?: number;
|
|
17
|
+
cutCoverAfterMs?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface BrollOutputWindow {
|
|
21
|
+
id: string;
|
|
22
|
+
outputStartMs: number;
|
|
23
|
+
outputEndMs: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ShortArollFlashGap {
|
|
27
|
+
fromBrollId: string;
|
|
28
|
+
toBrollId: string;
|
|
29
|
+
startMs: number;
|
|
30
|
+
endMs: number;
|
|
31
|
+
durationMs: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface OverlappingBrollWindows {
|
|
35
|
+
underBrollId: string;
|
|
36
|
+
overBrollId: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function boundedMilliseconds(value: number | undefined, fallback: number, name: string, maximum: number): number {
|
|
40
|
+
const selected = value ?? fallback;
|
|
41
|
+
if (!Number.isInteger(selected) || selected < 0 || selected > maximum) {
|
|
42
|
+
throw new Error(`${name} must be an integer within 0-${maximum}`);
|
|
43
|
+
}
|
|
44
|
+
return selected;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function findShortArollFlashGaps(
|
|
48
|
+
windows: BrollOutputWindow[],
|
|
49
|
+
shortGapMs = 500,
|
|
50
|
+
): ShortArollFlashGap[] {
|
|
51
|
+
const threshold = boundedMilliseconds(shortGapMs, 500, "shortGapMs", 2_000);
|
|
52
|
+
const sorted = [...windows].sort((left, right) => (
|
|
53
|
+
left.outputStartMs - right.outputStartMs
|
|
54
|
+
|| left.outputEndMs - right.outputEndMs
|
|
55
|
+
|| (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)
|
|
56
|
+
));
|
|
57
|
+
const gaps: ShortArollFlashGap[] = [];
|
|
58
|
+
let frontier = sorted[0];
|
|
59
|
+
let coveredUntilMs = frontier?.outputEndMs ?? 0;
|
|
60
|
+
for (let index = 1; index < sorted.length; index += 1) {
|
|
61
|
+
const next = sorted[index]!;
|
|
62
|
+
if (next.outputStartMs <= coveredUntilMs) {
|
|
63
|
+
if (next.outputEndMs > coveredUntilMs) {
|
|
64
|
+
frontier = next;
|
|
65
|
+
coveredUntilMs = next.outputEndMs;
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const durationMs = next.outputStartMs - coveredUntilMs;
|
|
70
|
+
if (durationMs > threshold) {
|
|
71
|
+
frontier = next;
|
|
72
|
+
coveredUntilMs = next.outputEndMs;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
gaps.push({
|
|
76
|
+
fromBrollId: frontier!.id,
|
|
77
|
+
toBrollId: next.id,
|
|
78
|
+
startMs: coveredUntilMs,
|
|
79
|
+
endMs: next.outputStartMs,
|
|
80
|
+
durationMs,
|
|
81
|
+
});
|
|
82
|
+
frontier = next;
|
|
83
|
+
coveredUntilMs = next.outputEndMs;
|
|
84
|
+
}
|
|
85
|
+
return gaps;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function findOverlappingBrollWindows(windows: BrollOutputWindow[]): OverlappingBrollWindows[] {
|
|
89
|
+
const sorted = [...windows].sort((left, right) => (
|
|
90
|
+
left.outputStartMs - right.outputStartMs
|
|
91
|
+
|| right.outputEndMs - left.outputEndMs
|
|
92
|
+
|| (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)
|
|
93
|
+
));
|
|
94
|
+
const overlaps: OverlappingBrollWindows[] = [];
|
|
95
|
+
let frontier = sorted[0];
|
|
96
|
+
for (let index = 1; index < sorted.length; index += 1) {
|
|
97
|
+
const next = sorted[index]!;
|
|
98
|
+
if (frontier && next.outputStartMs < frontier.outputEndMs) {
|
|
99
|
+
overlaps.push({ underBrollId: frontier.id, overBrollId: next.id });
|
|
100
|
+
if (next.outputEndMs > frontier.outputEndMs) frontier = next;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
frontier = next;
|
|
104
|
+
}
|
|
105
|
+
return overlaps;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function validateSegments(aroll: ArollSegment[]): void {
|
|
109
|
+
if (aroll.length === 0 || aroll.length > 1_000) throw new Error("A-roll must contain 1-1000 segments");
|
|
110
|
+
const ids = new Set<string>();
|
|
111
|
+
for (const segment of aroll) {
|
|
112
|
+
if (ids.has(segment.id)) throw new Error(`Duplicate A-roll segment ID: ${segment.id}`);
|
|
113
|
+
ids.add(segment.id);
|
|
114
|
+
if (!Number.isFinite(segment.sourceStartMs) || !Number.isFinite(segment.sourceEndMs)
|
|
115
|
+
|| segment.sourceStartMs < 0 || segment.sourceEndMs <= segment.sourceStartMs) {
|
|
116
|
+
throw new Error(`Invalid A-roll segment range: ${segment.id}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function validateNeeds(needs: BrollNeed[], outputDurationMs: number): void {
|
|
122
|
+
if (needs.length > 500) throw new Error("B-roll plan must contain at most 500 needs");
|
|
123
|
+
const ids = new Set<string>();
|
|
124
|
+
for (const need of needs) {
|
|
125
|
+
if (ids.has(need.id)) throw new Error(`Duplicate B-roll need ID: ${need.id}`);
|
|
126
|
+
ids.add(need.id);
|
|
127
|
+
if (!Number.isFinite(need.outputStartMs) || !Number.isFinite(need.outputEndMs)
|
|
128
|
+
|| need.outputStartMs < 0 || need.outputEndMs <= need.outputStartMs
|
|
129
|
+
|| need.outputEndMs > outputDurationMs) {
|
|
130
|
+
throw new Error(`Invalid B-roll need output range: ${need.id}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const overlap = findOverlappingBrollWindows(needs)[0];
|
|
134
|
+
if (overlap) throw new Error(`B-roll needs ${overlap.underBrollId} and ${overlap.overBrollId} overlap; z-order is not supported`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function bridgeShortGaps(needs: BrollNeed[], shortGapMs: number): {
|
|
138
|
+
needs: BrollNeed[];
|
|
139
|
+
bridges: BrollContinuityBridge[];
|
|
140
|
+
} {
|
|
141
|
+
const sorted = structuredClone(needs).sort((left, right) => (
|
|
142
|
+
left.outputStartMs - right.outputStartMs
|
|
143
|
+
|| left.outputEndMs - right.outputEndMs
|
|
144
|
+
|| (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)
|
|
145
|
+
));
|
|
146
|
+
const bridges: BrollContinuityBridge[] = [];
|
|
147
|
+
let frontier = sorted[0];
|
|
148
|
+
let coveredUntilMs = frontier?.outputEndMs ?? 0;
|
|
149
|
+
for (let index = 1; index < sorted.length; index += 1) {
|
|
150
|
+
const next = sorted[index]!;
|
|
151
|
+
if (next.outputStartMs <= coveredUntilMs) {
|
|
152
|
+
if (next.outputEndMs > coveredUntilMs) {
|
|
153
|
+
frontier = next;
|
|
154
|
+
coveredUntilMs = next.outputEndMs;
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const durationMs = next.outputStartMs - coveredUntilMs;
|
|
159
|
+
if (durationMs > shortGapMs) {
|
|
160
|
+
frontier = next;
|
|
161
|
+
coveredUntilMs = next.outputEndMs;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
bridges.push({
|
|
165
|
+
fromNeedId: frontier!.id,
|
|
166
|
+
toNeedId: next.id,
|
|
167
|
+
gapStartMs: coveredUntilMs,
|
|
168
|
+
gapEndMs: next.outputStartMs,
|
|
169
|
+
durationMs,
|
|
170
|
+
strategy: "extend-previous-broll",
|
|
171
|
+
});
|
|
172
|
+
frontier!.outputEndMs = next.outputStartMs;
|
|
173
|
+
frontier = next;
|
|
174
|
+
coveredUntilMs = next.outputEndMs;
|
|
175
|
+
}
|
|
176
|
+
return { needs: sorted, bridges };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function coverageForRange(needs: BrollOutputWindow[], startMs: number, endMs: number): {
|
|
180
|
+
covered: boolean;
|
|
181
|
+
needIds: string[];
|
|
182
|
+
} {
|
|
183
|
+
const overlapping = needs.filter((need) => need.outputEndMs > startMs && need.outputStartMs < endMs).sort((left, right) => (
|
|
184
|
+
left.outputStartMs - right.outputStartMs
|
|
185
|
+
|| left.outputEndMs - right.outputEndMs
|
|
186
|
+
|| (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)
|
|
187
|
+
));
|
|
188
|
+
let cursor = startMs;
|
|
189
|
+
const needIds: string[] = [];
|
|
190
|
+
for (const need of overlapping) {
|
|
191
|
+
if (need.outputStartMs > cursor) return { covered: false, needIds };
|
|
192
|
+
needIds.push(need.id);
|
|
193
|
+
cursor = Math.max(cursor, need.outputEndMs);
|
|
194
|
+
if (cursor >= endMs) return { covered: true, needIds };
|
|
195
|
+
}
|
|
196
|
+
return { covered: false, needIds };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function analyzeArollJumpCuts(
|
|
200
|
+
aroll: ArollSegment[],
|
|
201
|
+
needs: BrollOutputWindow[],
|
|
202
|
+
outputDurationMs: number,
|
|
203
|
+
cutCoverBeforeMs: number,
|
|
204
|
+
cutCoverAfterMs: number,
|
|
205
|
+
): ArollJumpCut[] {
|
|
206
|
+
const jumpCuts: ArollJumpCut[] = [];
|
|
207
|
+
let outputTimeMs = 0;
|
|
208
|
+
for (let index = 0; index < aroll.length - 1; index += 1) {
|
|
209
|
+
const current = aroll[index]!;
|
|
210
|
+
const next = aroll[index + 1]!;
|
|
211
|
+
outputTimeMs += current.sourceEndMs - current.sourceStartMs;
|
|
212
|
+
const sourceDeltaMs = next.sourceStartMs - current.sourceEndMs;
|
|
213
|
+
if (sourceDeltaMs === 0) continue;
|
|
214
|
+
const suggestedOutputStartMs = Math.max(0, outputTimeMs - cutCoverBeforeMs);
|
|
215
|
+
const suggestedOutputEndMs = Math.min(outputDurationMs, outputTimeMs + cutCoverAfterMs);
|
|
216
|
+
const coverage = coverageForRange(needs, suggestedOutputStartMs, suggestedOutputEndMs);
|
|
217
|
+
jumpCuts.push({
|
|
218
|
+
fromSegmentId: current.id,
|
|
219
|
+
toSegmentId: next.id,
|
|
220
|
+
outputTimeMs,
|
|
221
|
+
sourceDeltaMs,
|
|
222
|
+
suggestedOutputStartMs,
|
|
223
|
+
suggestedOutputEndMs,
|
|
224
|
+
coveredByNeedIds: coverage.needIds,
|
|
225
|
+
status: coverage.covered ? "covered" : "needs-broll",
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return jumpCuts;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function planBrollContinuity(input: PlanBrollContinuityInput): BrollContinuityPlan {
|
|
232
|
+
validateSegments(input.aroll);
|
|
233
|
+
const outputDurationMs = timelineDuration(input.aroll);
|
|
234
|
+
validateNeeds(input.needs, outputDurationMs);
|
|
235
|
+
const shortGapMs = boundedMilliseconds(input.shortGapMs, 500, "shortGapMs", 2_000);
|
|
236
|
+
const cutCoverBeforeMs = boundedMilliseconds(input.cutCoverBeforeMs, 250, "cutCoverBeforeMs", 2_000);
|
|
237
|
+
const cutCoverAfterMs = boundedMilliseconds(input.cutCoverAfterMs, 500, "cutCoverAfterMs", 2_000);
|
|
238
|
+
if (cutCoverBeforeMs === 0 && cutCoverAfterMs === 0) {
|
|
239
|
+
throw new Error("cutCoverBeforeMs and cutCoverAfterMs cannot both be zero");
|
|
240
|
+
}
|
|
241
|
+
const bridged = bridgeShortGaps(input.needs, shortGapMs);
|
|
242
|
+
return {
|
|
243
|
+
outputDurationMs,
|
|
244
|
+
shortGapMs,
|
|
245
|
+
cutCoverBeforeMs,
|
|
246
|
+
cutCoverAfterMs,
|
|
247
|
+
needs: bridged.needs,
|
|
248
|
+
bridges: bridged.bridges,
|
|
249
|
+
jumpCuts: analyzeArollJumpCuts(
|
|
250
|
+
input.aroll,
|
|
251
|
+
bridged.needs,
|
|
252
|
+
outputDurationMs,
|
|
253
|
+
cutCoverBeforeMs,
|
|
254
|
+
cutCoverAfterMs,
|
|
255
|
+
),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function planReceiptPayload(receipt: Omit<BrollContinuityPlanReceipt, "planSha256">): string {
|
|
260
|
+
return canonicalJson(receipt);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function canonicalJson(value: unknown): string {
|
|
264
|
+
if (value === null || typeof value !== "object") {
|
|
265
|
+
const serialized = JSON.stringify(value);
|
|
266
|
+
if (serialized === undefined) throw new Error("Cannot canonicalize an undefined value");
|
|
267
|
+
return serialized;
|
|
268
|
+
}
|
|
269
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
270
|
+
const object = value as Record<string, unknown>;
|
|
271
|
+
return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object[key])}`).join(",")}}`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function sha256(value: string): string {
|
|
275
|
+
return createHash("sha256").update(value).digest("hex");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function arollSha256(aroll: ArollSegment[]): string {
|
|
279
|
+
return sha256(canonicalJson(aroll));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function plannedRanges(needs: BrollNeed[]): BrollContinuityPlanReceipt["needs"] {
|
|
283
|
+
return needs.map((need) => ({
|
|
284
|
+
id: need.id,
|
|
285
|
+
outputStartMs: need.outputStartMs,
|
|
286
|
+
outputEndMs: need.outputEndMs,
|
|
287
|
+
}));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function createBrollContinuityPlanReceipt(
|
|
291
|
+
projectId: string,
|
|
292
|
+
revision: number,
|
|
293
|
+
aroll: ArollSegment[],
|
|
294
|
+
plan: BrollContinuityPlan,
|
|
295
|
+
): BrollContinuityPlanReceipt {
|
|
296
|
+
const payload: Omit<BrollContinuityPlanReceipt, "planSha256"> = {
|
|
297
|
+
schemaVersion: 1,
|
|
298
|
+
projectId,
|
|
299
|
+
revision,
|
|
300
|
+
arollSha256: arollSha256(aroll),
|
|
301
|
+
shortGapMs: plan.shortGapMs,
|
|
302
|
+
cutCoverBeforeMs: plan.cutCoverBeforeMs,
|
|
303
|
+
cutCoverAfterMs: plan.cutCoverAfterMs,
|
|
304
|
+
needs: plannedRanges(plan.needs),
|
|
305
|
+
jumpCuts: structuredClone(plan.jumpCuts),
|
|
306
|
+
};
|
|
307
|
+
return { ...payload, planSha256: sha256(planReceiptPayload(payload)) };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function verifyBrollContinuityPlanReceipt(
|
|
311
|
+
projectId: string,
|
|
312
|
+
revision: number,
|
|
313
|
+
aroll: ArollSegment[],
|
|
314
|
+
placements: BrollOutputWindow[],
|
|
315
|
+
receipt: BrollContinuityPlanReceipt,
|
|
316
|
+
): void {
|
|
317
|
+
if (receipt.schemaVersion !== 1 || receipt.projectId !== projectId || receipt.revision !== revision) {
|
|
318
|
+
throw new Error("B-roll continuity receipt does not match the current project revision");
|
|
319
|
+
}
|
|
320
|
+
if (receipt.arollSha256 !== arollSha256(aroll)) {
|
|
321
|
+
throw new Error("B-roll continuity receipt does not match the planned A-roll");
|
|
322
|
+
}
|
|
323
|
+
const { planSha256, ...payload } = receipt;
|
|
324
|
+
if (planSha256 !== sha256(planReceiptPayload(payload))) {
|
|
325
|
+
throw new Error("B-roll continuity receipt hash is invalid");
|
|
326
|
+
}
|
|
327
|
+
const dummyNeeds: BrollNeed[] = receipt.needs.map((need) => ({
|
|
328
|
+
...need,
|
|
329
|
+
speechText: "continuity receipt",
|
|
330
|
+
purpose: "mask-cut",
|
|
331
|
+
searchTerms: ["continuity"],
|
|
332
|
+
reason: "continuity receipt verification",
|
|
333
|
+
}));
|
|
334
|
+
const recomputed = planBrollContinuity({
|
|
335
|
+
aroll,
|
|
336
|
+
needs: dummyNeeds,
|
|
337
|
+
shortGapMs: receipt.shortGapMs,
|
|
338
|
+
cutCoverBeforeMs: receipt.cutCoverBeforeMs,
|
|
339
|
+
cutCoverAfterMs: receipt.cutCoverAfterMs,
|
|
340
|
+
});
|
|
341
|
+
if (canonicalJson(plannedRanges(recomputed.needs)) !== canonicalJson(receipt.needs)
|
|
342
|
+
|| canonicalJson(recomputed.jumpCuts) !== canonicalJson(receipt.jumpCuts)) {
|
|
343
|
+
throw new Error("B-roll continuity receipt does not match the recomputed plan");
|
|
344
|
+
}
|
|
345
|
+
const actualRanges = [...placements].sort((left, right) => (
|
|
346
|
+
left.outputStartMs - right.outputStartMs || left.outputEndMs - right.outputEndMs
|
|
347
|
+
)).map((placement) => ({
|
|
348
|
+
id: placement.id,
|
|
349
|
+
outputStartMs: placement.outputStartMs,
|
|
350
|
+
outputEndMs: placement.outputEndMs,
|
|
351
|
+
}));
|
|
352
|
+
if (canonicalJson(actualRanges) !== canonicalJson(receipt.needs)) {
|
|
353
|
+
throw new Error("B-roll placements do not match the planned ranges");
|
|
354
|
+
}
|
|
355
|
+
}
|
package/src/contracts.ts
CHANGED
|
@@ -165,6 +165,49 @@ export interface BrollWindowSelection {
|
|
|
165
165
|
placement: BrollPlacementInput;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
export interface BrollContinuityBridge {
|
|
169
|
+
fromNeedId: string;
|
|
170
|
+
toNeedId: string;
|
|
171
|
+
gapStartMs: number;
|
|
172
|
+
gapEndMs: number;
|
|
173
|
+
durationMs: number;
|
|
174
|
+
strategy: "extend-previous-broll";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface ArollJumpCut {
|
|
178
|
+
fromSegmentId: string;
|
|
179
|
+
toSegmentId: string;
|
|
180
|
+
outputTimeMs: number;
|
|
181
|
+
sourceDeltaMs: number;
|
|
182
|
+
suggestedOutputStartMs: number;
|
|
183
|
+
suggestedOutputEndMs: number;
|
|
184
|
+
coveredByNeedIds: string[];
|
|
185
|
+
status: "covered" | "needs-broll";
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface BrollContinuityPlan {
|
|
189
|
+
outputDurationMs: number;
|
|
190
|
+
shortGapMs: number;
|
|
191
|
+
cutCoverBeforeMs: number;
|
|
192
|
+
cutCoverAfterMs: number;
|
|
193
|
+
needs: BrollNeed[];
|
|
194
|
+
bridges: BrollContinuityBridge[];
|
|
195
|
+
jumpCuts: ArollJumpCut[];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface BrollContinuityPlanReceipt {
|
|
199
|
+
schemaVersion: 1;
|
|
200
|
+
projectId: string;
|
|
201
|
+
revision: number;
|
|
202
|
+
arollSha256: string;
|
|
203
|
+
shortGapMs: number;
|
|
204
|
+
cutCoverBeforeMs: number;
|
|
205
|
+
cutCoverAfterMs: number;
|
|
206
|
+
needs: Array<{ id: string; outputStartMs: number; outputEndMs: number }>;
|
|
207
|
+
jumpCuts: ArollJumpCut[];
|
|
208
|
+
planSha256: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
168
211
|
export interface TranscriptAnalysis {
|
|
169
212
|
schemaVersion: 2;
|
|
170
213
|
text: string;
|
|
@@ -209,6 +252,8 @@ export interface TalkingHeadSnapshot {
|
|
|
209
252
|
policy: TalkingHeadPolicy;
|
|
210
253
|
aroll: ArollSegment[];
|
|
211
254
|
broll: BrollPlacement[];
|
|
255
|
+
continuityPlanReceipt?: BrollContinuityPlanReceipt;
|
|
256
|
+
jumpCuts?: ArollJumpCut[];
|
|
212
257
|
outputDurationMs: number;
|
|
213
258
|
}
|
|
214
259
|
|
package/src/project.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
ArollSegment,
|
|
6
6
|
BrollPlacement,
|
|
7
7
|
BrollPlacementInput,
|
|
8
|
+
BrollContinuityPlanReceipt,
|
|
8
9
|
FillerCandidate,
|
|
9
10
|
PauseCandidate,
|
|
10
11
|
RepetitionCandidate,
|
|
@@ -17,6 +18,12 @@ import type {
|
|
|
17
18
|
WordTranscript,
|
|
18
19
|
} from "./contracts.ts";
|
|
19
20
|
import { verifyBrollPlacementSelection } from "./broll.ts";
|
|
21
|
+
import {
|
|
22
|
+
analyzeArollJumpCuts,
|
|
23
|
+
findOverlappingBrollWindows,
|
|
24
|
+
findShortArollFlashGaps,
|
|
25
|
+
verifyBrollContinuityPlanReceipt,
|
|
26
|
+
} from "./continuity.ts";
|
|
20
27
|
import { analyzeTranscript, DEFAULT_POLICY, timelineDuration } from "./transcript.ts";
|
|
21
28
|
import { resolveExistingWorkspaceFile, resolveWorkspacePath, snapshotFile, workspaceRelativePath } from "./workspace.ts";
|
|
22
29
|
|
|
@@ -34,6 +41,7 @@ export interface ApplyTimelineInput {
|
|
|
34
41
|
expectedRevision: number;
|
|
35
42
|
aroll: ArollSegment[];
|
|
36
43
|
broll: BrollPlacementInput[];
|
|
44
|
+
continuityPlanReceipt?: BrollContinuityPlanReceipt;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
function assertProjectId(projectId: string): void {
|
|
@@ -78,8 +86,11 @@ async function validateTimeline(
|
|
|
78
86
|
cwd: string,
|
|
79
87
|
aroll: ArollSegment[],
|
|
80
88
|
broll: BrollPlacementInput[],
|
|
89
|
+
projectId: string,
|
|
90
|
+
revision: number,
|
|
91
|
+
continuityPlanReceipt: BrollContinuityPlanReceipt | undefined,
|
|
81
92
|
signal?: AbortSignal,
|
|
82
|
-
): Promise<{ outputDurationMs: number; broll: BrollPlacement[] }> {
|
|
93
|
+
): Promise<{ outputDurationMs: number; broll: BrollPlacement[]; jumpCuts: ReturnType<typeof analyzeArollJumpCuts> }> {
|
|
83
94
|
if (aroll.length === 0 || aroll.length > 1_000) throw new Error("A-roll must contain 1-1000 segments");
|
|
84
95
|
uniqueIds(aroll, "A-roll segment");
|
|
85
96
|
for (const segment of aroll) {
|
|
@@ -91,9 +102,7 @@ async function validateTimeline(
|
|
|
91
102
|
const outputDurationMs = timelineDuration(aroll);
|
|
92
103
|
if (broll.length > 500) throw new Error("B-roll must contain at most 500 placements");
|
|
93
104
|
uniqueIds(broll, "B-roll placement");
|
|
94
|
-
const normalizedBroll: BrollPlacement[] = [];
|
|
95
105
|
for (const placement of broll) {
|
|
96
|
-
signal?.throwIfAborted();
|
|
97
106
|
if (!Number.isFinite(placement.outputStartMs) || !Number.isFinite(placement.outputEndMs)
|
|
98
107
|
|| placement.outputStartMs < 0 || placement.outputEndMs <= placement.outputStartMs) {
|
|
99
108
|
throw new Error(`Invalid B-roll output range: ${placement.id}`);
|
|
@@ -106,6 +115,24 @@ async function validateTimeline(
|
|
|
106
115
|
}
|
|
107
116
|
if (!placement.selectionReceipt) throw new Error(`B-roll selectionReceipt is required: ${placement.id}`);
|
|
108
117
|
if (placement.audio !== "keep-primary") throw new Error("B-roll audio must keep the primary A-roll audio");
|
|
118
|
+
}
|
|
119
|
+
const overlap = findOverlappingBrollWindows(broll)[0];
|
|
120
|
+
if (overlap) {
|
|
121
|
+
throw new Error(`B-roll placements ${overlap.underBrollId} and ${overlap.overBrollId} overlap; ambiguous z-order is not supported`);
|
|
122
|
+
}
|
|
123
|
+
const flashGap = findShortArollFlashGaps(broll, 500)[0];
|
|
124
|
+
if (flashGap) {
|
|
125
|
+
throw new Error(`B-roll placements ${flashGap.fromBrollId} and ${flashGap.toBrollId} leave a brief ${flashGap.durationMs}ms A-roll flash; run talking_head_broll_plan and reselect the bridged window`);
|
|
126
|
+
}
|
|
127
|
+
if (broll.length > 0 && !continuityPlanReceipt) {
|
|
128
|
+
throw new Error("B-roll continuityPlanReceipt is required; run talking_head_broll_plan first");
|
|
129
|
+
}
|
|
130
|
+
if (continuityPlanReceipt) {
|
|
131
|
+
verifyBrollContinuityPlanReceipt(projectId, revision, aroll, broll, continuityPlanReceipt);
|
|
132
|
+
}
|
|
133
|
+
const normalizedBroll: BrollPlacement[] = [];
|
|
134
|
+
for (const placement of broll) {
|
|
135
|
+
signal?.throwIfAborted();
|
|
109
136
|
const asset = await verifyBrollPlacementSelection(cwd, placement, signal);
|
|
110
137
|
normalizedBroll.push({
|
|
111
138
|
...structuredClone(placement),
|
|
@@ -114,7 +141,13 @@ async function validateTimeline(
|
|
|
114
141
|
assetSha256: asset.sha256,
|
|
115
142
|
});
|
|
116
143
|
}
|
|
117
|
-
return {
|
|
144
|
+
return {
|
|
145
|
+
outputDurationMs,
|
|
146
|
+
broll: normalizedBroll,
|
|
147
|
+
jumpCuts: continuityPlanReceipt
|
|
148
|
+
? structuredClone(continuityPlanReceipt.jumpCuts)
|
|
149
|
+
: analyzeArollJumpCuts(aroll, broll, outputDurationMs, 250, 500),
|
|
150
|
+
};
|
|
118
151
|
}
|
|
119
152
|
|
|
120
153
|
function summary(analysis: TranscriptAnalysis) {
|
|
@@ -181,6 +214,7 @@ export async function createTalkingHeadProject(cwd: string, input: CreateTalking
|
|
|
181
214
|
policy,
|
|
182
215
|
aroll: analysis.segments,
|
|
183
216
|
broll: [],
|
|
217
|
+
jumpCuts: analyzeArollJumpCuts(analysis.segments, [], analysis.outputDurationMs, 250, 500),
|
|
184
218
|
outputDurationMs: analysis.outputDurationMs,
|
|
185
219
|
};
|
|
186
220
|
try {
|
|
@@ -248,7 +282,15 @@ export async function applyTimeline(cwd: string, input: ApplyTimelineInput, sign
|
|
|
248
282
|
await assertProjectSourcesUnchanged(cwd, project);
|
|
249
283
|
await assertSnapshotAssetsUnchanged(cwd, current);
|
|
250
284
|
assertWordSafeSegments(input.aroll, await getAnalysis(cwd, project));
|
|
251
|
-
const validated = await validateTimeline(
|
|
285
|
+
const validated = await validateTimeline(
|
|
286
|
+
cwd,
|
|
287
|
+
input.aroll,
|
|
288
|
+
input.broll,
|
|
289
|
+
input.projectId,
|
|
290
|
+
input.expectedRevision,
|
|
291
|
+
input.continuityPlanReceipt,
|
|
292
|
+
signal,
|
|
293
|
+
);
|
|
252
294
|
const revision = project.currentRevision + 1;
|
|
253
295
|
const now = new Date().toISOString();
|
|
254
296
|
const snapshot: TalkingHeadSnapshot = {
|
|
@@ -260,6 +302,10 @@ export async function applyTimeline(cwd: string, input: ApplyTimelineInput, sign
|
|
|
260
302
|
policy: current.policy,
|
|
261
303
|
aroll: structuredClone(input.aroll),
|
|
262
304
|
broll: validated.broll,
|
|
305
|
+
jumpCuts: validated.jumpCuts,
|
|
306
|
+
...(input.continuityPlanReceipt === undefined
|
|
307
|
+
? {}
|
|
308
|
+
: { continuityPlanReceipt: structuredClone(input.continuityPlanReceipt) }),
|
|
263
309
|
outputDurationMs: validated.outputDurationMs,
|
|
264
310
|
};
|
|
265
311
|
await writeJson(join(directory, "snapshots", `${revision}.json`), snapshot, true);
|