@kriya-ai/harness 0.0.0-stage → 0.2.1
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 +379 -2
- package/SAFETY.md +162 -0
- package/THIRD_PARTY_NOTICES.md +7911 -0
- package/bin/kriya.js +577 -0
- package/bundle/cordis.patch.yml +397 -0
- package/contract/SOURCE.md +15 -0
- package/contract/contract.json +1355 -0
- package/package.json +57 -4
- package/plugins/anchor/index.js +56 -0
- package/plugins/anchor/package.json +13 -0
- package/plugins/approvals/index.js +183 -0
- package/plugins/approvals/package.json +13 -0
- package/plugins/brand/DESIGN.md +112 -0
- package/plugins/brand/client.js +826 -0
- package/plugins/brand/index.js +15 -0
- package/plugins/brand/package.json +25 -0
- package/plugins/brand/src/client.js +823 -0
- package/plugins/browser/index.js +218 -0
- package/plugins/browser/package.json +13 -0
- package/plugins/budget/index.js +108 -0
- package/plugins/budget/package.json +13 -0
- package/plugins/changes/client.js +245 -0
- package/plugins/changes/index.js +75 -0
- package/plugins/changes/package.json +22 -0
- package/plugins/edit/client.js +113 -0
- package/plugins/edit/index.js +58 -0
- package/plugins/edit/package.json +23 -0
- package/plugins/fs-freshness/index.js +28 -0
- package/plugins/fs-freshness/package.json +13 -0
- package/plugins/graph/client.js +178 -0
- package/plugins/graph/index.js +4 -0
- package/plugins/graph/package.json +22 -0
- package/plugins/kriya-handoff/index.js +194 -0
- package/plugins/kriya-handoff/package.json +13 -0
- package/plugins/kriya-tools/index.js +189 -0
- package/plugins/kriya-tools/package.json +13 -0
- package/plugins/loop/index.js +743 -0
- package/plugins/loop/package.json +13 -0
- package/plugins/mirror/index.js +235 -0
- package/plugins/mirror/package.json +13 -0
- package/plugins/overview/client.js +276 -0
- package/plugins/overview/index.js +95 -0
- package/plugins/overview/package.json +22 -0
- package/plugins/preview/client.js +337 -0
- package/plugins/preview/index.js +4 -0
- package/plugins/preview/package.json +22 -0
- package/plugins/progress/client.js +290 -0
- package/plugins/progress/index.js +100 -0
- package/plugins/progress/package.json +22 -0
- package/plugins/projects/client.js +249 -0
- package/plugins/projects/index.js +30 -0
- package/plugins/projects/package.json +24 -0
- package/plugins/rea/index.js +256 -0
- package/plugins/rea/package.json +10 -0
- package/plugins/rea/skill/LICENSE +21 -0
- package/plugins/rea/skill/SKILL.md +360 -0
- package/plugins/rea/skill/references/android-applications.md +36 -0
- package/plugins/rea/skill/references/connection-and-recovery.md +127 -0
- package/plugins/rea/skill/references/evidence-workflows.md +71 -0
- package/plugins/rea/skill/references/javascript-applications.md +218 -0
- package/plugins/rea/skill/references/native-and-artifacts.md +297 -0
- package/plugins/rea/skill/references/runtime-observation.md +78 -0
- package/plugins/remote/index.js +297 -0
- package/plugins/remote/package.json +10 -0
- package/plugins/router/index.js +84 -0
- package/plugins/router/package.json +13 -0
- package/plugins/sessions/client.js +68 -0
- package/plugins/sessions/index.js +79 -0
- package/plugins/sessions/package.json +20 -0
- package/plugins/skills/client.js +504 -0
- package/plugins/skills/index.js +166 -0
- package/plugins/skills/package.json +23 -0
- package/src/api.js +97 -0
- package/src/browser.js +286 -0
- package/src/changes.js +191 -0
- package/src/checkpoints.js +313 -0
- package/src/daemon.js +503 -0
- package/src/doctor.js +137 -0
- package/src/edit/core/anchors.js +102 -0
- package/src/edit/core/audio.js +158 -0
- package/src/edit/core/faces.js +99 -0
- package/src/edit/core/ffmpeg.js +258 -0
- package/src/edit/core/handoff.js +220 -0
- package/src/edit/core/history.js +90 -0
- package/src/edit/core/layout.js +92 -0
- package/src/edit/core/mix.js +115 -0
- package/src/edit/core/ops.js +602 -0
- package/src/edit/core/plan.js +266 -0
- package/src/edit/core/project.d.ts +134 -0
- package/src/edit/core/project.js +307 -0
- package/src/edit/core/reframe.js +125 -0
- package/src/edit/core/solver.js +416 -0
- package/src/edit/core/time.js +110 -0
- package/src/edit/core/tonemap.js +57 -0
- package/src/edit/director/ask.js +120 -0
- package/src/edit/director/gateway.js +16 -0
- package/src/edit/director/revise.js +186 -0
- package/src/edit/engine/capabilities.js +33 -0
- package/src/edit/engine/captions.js +154 -0
- package/src/edit/engine/color.js +269 -0
- package/src/edit/engine/confine.js +67 -0
- package/src/edit/engine/dna.js +148 -0
- package/src/edit/engine/index.js +473 -0
- package/src/edit/engine/loudness.js +43 -0
- package/src/edit/engine/media.js +57 -0
- package/src/edit/engine/motion.js +281 -0
- package/src/edit/engine/packs.js +87 -0
- package/src/edit/engine/probe.js +101 -0
- package/src/edit/engine/receipt.js +123 -0
- package/src/edit/engine/tool.js +101 -0
- package/src/edit/gates/copy.js +113 -0
- package/src/edit/gates/index.js +430 -0
- package/src/edit/gates/picture.js +130 -0
- package/src/edit/gates/sound.js +58 -0
- package/src/edit/gates/speech.js +127 -0
- package/src/edit/gates/text.js +196 -0
- package/src/edit/gates/text.swift +22 -0
- package/src/edit/graph/index.js +139 -0
- package/src/edit/graph/journal.js +69 -0
- package/src/edit/graph/scheduler.js +79 -0
- package/src/edit/host/client.js +58 -0
- package/src/edit/host/deliver.js +119 -0
- package/src/edit/host/jobs.js +84 -0
- package/src/edit/host/main.js +135 -0
- package/src/edit/host/paths.js +11 -0
- package/src/edit/host/projects.js +415 -0
- package/src/edit/host/server.js +391 -0
- package/src/edit/host/taste.js +135 -0
- package/src/edit/host/tavi.js +417 -0
- package/src/edit/host/watch.js +141 -0
- package/src/edit/index/db.js +109 -0
- package/src/edit/index/index.js +236 -0
- package/src/edit/index/layers/faces.js +78 -0
- package/src/edit/index/layers/faces.swift +18 -0
- package/src/edit/index/layers/meta.js +35 -0
- package/src/edit/index/layers/music.js +146 -0
- package/src/edit/index/layers/quality.js +120 -0
- package/src/edit/index/layers/retakes.js +132 -0
- package/src/edit/index/layers/screen.js +99 -0
- package/src/edit/index/layers/shots.js +29 -0
- package/src/edit/index/layers/sound.js +42 -0
- package/src/edit/index/layers/words.js +64 -0
- package/src/edit/index/story.js +248 -0
- package/src/edit/index/views.js +71 -0
- package/src/edit/loop/governor.js +112 -0
- package/src/edit/loop/loop.js +69 -0
- package/src/edit/loop/make.js +115 -0
- package/src/edit/loop/repair.js +97 -0
- package/src/edit/loop/replay.js +32 -0
- package/src/edit/recipes/multicam.js +461 -0
- package/src/edit/recipes/reel.js +202 -0
- package/src/edit/recipes/short-from-long.js +237 -0
- package/src/edit/recipes/tutorial.js +137 -0
- package/src/edit/recipes/youtube.js +155 -0
- package/src/edit/runtime/cli.js +126 -0
- package/src/edit/runtime/doctor.js +122 -0
- package/src/edit/runtime/fetch.js +15 -0
- package/src/edit/runtime/licences.js +88 -0
- package/src/edit/runtime/manifest.js +73 -0
- package/src/edit/runtime/setup.js +252 -0
- package/src/failure.js +69 -0
- package/src/gateway-proxy.js +213 -0
- package/src/intent.js +130 -0
- package/src/launch.js +315 -0
- package/src/live.js +81 -0
- package/src/local-skills.js +284 -0
- package/src/login.js +82 -0
- package/src/loop.js +428 -0
- package/src/modes.js +128 -0
- package/src/overview.js +71 -0
- package/src/paths.js +30 -0
- package/src/profiles.js +92 -0
- package/src/projects.js +104 -0
- package/src/recon.js +244 -0
- package/src/rules.js +139 -0
- package/src/runner.bundle.js +21172 -0
- package/src/sentinel.js +248 -0
- package/src/skill-switches.js +130 -0
- package/src/store.js +58 -0
- package/src/strict.js +124 -0
- package/src/verify.js +659 -0
- package/src/world.js +268 -0
- package/studio/dist/index.html +14 -0
- package/studio/dist/studio.css +163 -0
- package/studio/dist/studio.js +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Anchors name content instead of a time (EDIT_ENGINE §5). The index arrives as
|
|
2
|
+
// plain rows, so Edit Core stays free of I/O; times are flicks in the asset.
|
|
3
|
+
|
|
4
|
+
const opened = new WeakMap()
|
|
5
|
+
const NONE = {}
|
|
6
|
+
|
|
7
|
+
/** Lookup tables over raw index rows, built once per index object. */
|
|
8
|
+
export function openIndex(raw = NONE) {
|
|
9
|
+
if (opened.has(raw)) return opened.get(raw)
|
|
10
|
+
const byId = (rows = []) => new Map(rows.map((row) => [row.id, row]))
|
|
11
|
+
const words = new Map()
|
|
12
|
+
for (const word of raw.words ?? []) words.set(word.asset, [...(words.get(word.asset) ?? []), word])
|
|
13
|
+
for (const list of words.values()) list.sort((a, b) => a.start - b.start)
|
|
14
|
+
const index = { raw, word: byId(raw.words), shot: byId(raw.shots), beat: byId(raw.beats), words }
|
|
15
|
+
opened.set(raw, index)
|
|
16
|
+
return index
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Where a word, shot or beat anchor sits in its asset; null if the index doesn't know it. */
|
|
20
|
+
export function anchorSource(anchor, index, fallback = "start") {
|
|
21
|
+
if (anchor.word !== undefined) {
|
|
22
|
+
const word = index.word.get(anchor.word)
|
|
23
|
+
return word ? { asset: word.asset, t: word[anchor.edge] } : null
|
|
24
|
+
}
|
|
25
|
+
if (anchor.shot !== undefined) {
|
|
26
|
+
const shot = index.shot.get(anchor.shot)
|
|
27
|
+
return shot ? { asset: shot.asset, t: shot[anchor.edge ?? fallback] } : null
|
|
28
|
+
}
|
|
29
|
+
if (anchor.beat !== undefined) {
|
|
30
|
+
const beat = index.beat.get(anchor.beat)
|
|
31
|
+
return beat ? { asset: beat.asset, t: beat.t } : null
|
|
32
|
+
}
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The word whose body t falls strictly inside, by binary search
|
|
37
|
+
export function wordAt(words, t) {
|
|
38
|
+
let low = 0
|
|
39
|
+
let high = words.length - 1
|
|
40
|
+
while (low <= high) {
|
|
41
|
+
const middle = (low + high) >> 1
|
|
42
|
+
if (t <= words[middle].start) high = middle - 1
|
|
43
|
+
else if (t >= words[middle].end) low = middle + 1
|
|
44
|
+
else return words[middle]
|
|
45
|
+
}
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const wordBefore = (words, t) => words.findLast((word) => word.end <= t) ?? null
|
|
50
|
+
export const wordAfter = (words, t) => words.find((word) => word.start >= t) ?? null
|
|
51
|
+
|
|
52
|
+
const normal = (text) => text.normalize("NFKC").toLowerCase().replace(/[\p{P}\s]+/gu, "")
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Old word id → new id after re-transcription, or null when nothing matches. Both
|
|
56
|
+
* transcripts share the file's clock, so one pass over time replaces a full alignment.
|
|
57
|
+
*/
|
|
58
|
+
export function alignWords(before, after) {
|
|
59
|
+
const mapping = {}
|
|
60
|
+
const sorted = [...after].sort((a, b) => a.start - b.start)
|
|
61
|
+
let from = 0
|
|
62
|
+
for (const word of [...before].sort((a, b) => a.start - b.start)) {
|
|
63
|
+
while (from < sorted.length && sorted[from].end <= word.start) from++
|
|
64
|
+
let best = null
|
|
65
|
+
let overlap = 0
|
|
66
|
+
for (let i = from; i < sorted.length && sorted[i].start < word.end; i++) {
|
|
67
|
+
const shared = Math.min(word.end, sorted[i].end) - Math.max(word.start, sorted[i].start)
|
|
68
|
+
if (shared > overlap && normal(sorted[i].text) === normal(word.text)) {
|
|
69
|
+
best = sorted[i]
|
|
70
|
+
overlap = shared
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
mapping[word.id] = best?.id ?? null
|
|
74
|
+
}
|
|
75
|
+
return mapping
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Rewrites word ids through a mapping. A word with no new id keeps its old one and
|
|
80
|
+
* is listed: it is reported, never guessed.
|
|
81
|
+
* @returns {{ project: object, unmapped: string[] }}
|
|
82
|
+
*/
|
|
83
|
+
export function remapAnchors(project, mapping) {
|
|
84
|
+
const unmapped = new Set()
|
|
85
|
+
const next = (id) => {
|
|
86
|
+
if (Object.hasOwn(mapping, id) && mapping[id]) return mapping[id]
|
|
87
|
+
unmapped.add(id)
|
|
88
|
+
return id
|
|
89
|
+
}
|
|
90
|
+
const walk = (value) => {
|
|
91
|
+
if (Array.isArray(value)) return value.map(walk)
|
|
92
|
+
if (value === null || typeof value !== "object") return value
|
|
93
|
+
const copy = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, walk(item)]))
|
|
94
|
+
if (typeof copy.word === "string") copy.word = next(copy.word)
|
|
95
|
+
if (copy.type === "caption") {
|
|
96
|
+
copy.words = copy.words.map(next)
|
|
97
|
+
copy.emphasis = copy.emphasis.map(next)
|
|
98
|
+
}
|
|
99
|
+
return copy
|
|
100
|
+
}
|
|
101
|
+
return { project: { ...project, sequences: walk(project.sequences) }, unmapped: [...unmapped].sort() }
|
|
102
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// The audio plan (EDIT_ENGINE §10, ED9): pure decisions the render follows. Which bus
|
|
2
|
+
// a sound is on, where the speech is on the output, the music's path through its bars
|
|
3
|
+
// to the length, the duck's gain curve, and the loudness each deliverable aims at.
|
|
4
|
+
|
|
5
|
+
import { scaleFlicks } from "./time.js"
|
|
6
|
+
|
|
7
|
+
const FLICKS = 705_600_000
|
|
8
|
+
const ms = (n) => n * 705_600
|
|
9
|
+
|
|
10
|
+
/** Buses by track role. The dialogue bus also takes the base clips' own sound. */
|
|
11
|
+
export const BUSES = ["dialogue", "music", "sfx", "ambience"]
|
|
12
|
+
export const busOf = (role) => (role === "music" ? "music" : role === "sfx" ? "sfx" : role === "ambience" ? "ambience" : "dialogue")
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Loudness targets per deliverable preset. EBU R128 (−23 LUFS, −1 dBTP) and Apple's
|
|
16
|
+
* podcast spec (−16 LUFS, −1 dBTP) are published; the social and YouTube values are
|
|
17
|
+
* the level those services are commonly measured to normalise to, not a published spec.
|
|
18
|
+
*/
|
|
19
|
+
export const LOUDNESS_TARGETS = {
|
|
20
|
+
"reel-9x16": { lufs: -14, tp: -1, source: "common target, not a platform spec" },
|
|
21
|
+
"short-9x16": { lufs: -14, tp: -1, source: "common target, not a platform spec" },
|
|
22
|
+
"tiktok-9x16": { lufs: -14, tp: -1, source: "common target, not a platform spec" },
|
|
23
|
+
youtube: { lufs: -14, tp: -1, source: "common target, not a platform spec" },
|
|
24
|
+
podcast: { lufs: -16, tp: -1, source: "Apple Podcasts specification" },
|
|
25
|
+
broadcast: { lufs: -23, tp: -1, source: "EBU R128" },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// shortcut: untuned defaults (EDITOR_WORKFLOWS §5, §11); recipes may set their own
|
|
29
|
+
export const DUCK_DEFAULTS = { depth: -12, attack: ms(80), release: ms(300) }
|
|
30
|
+
export const SFX_UNDER_VOICE = 6 // LU a sound effect sits under the measured voice
|
|
31
|
+
export const MUSIC_UNDER_VOICE = 12 // LU the music bed sits under it, before the duck
|
|
32
|
+
export const SFX_SPACING = ms(1000) // rule of restraint: no two effects closer than this
|
|
33
|
+
export const CROSSFADE = ms(50) // equal-power, at each music edit
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Where speech is on the output: each dialogue item's words, mapped through its timing.
|
|
37
|
+
* With no words for an item, all of it counts as speech (so music still ducks).
|
|
38
|
+
* @returns {{ at: number, end: number }[]} merged, sorted
|
|
39
|
+
*/
|
|
40
|
+
export function speechSpans(items, words = [], { join = ms(300) } = {}) {
|
|
41
|
+
const spans = []
|
|
42
|
+
for (const item of items) {
|
|
43
|
+
if (busOf(item.role) !== "dialogue") continue
|
|
44
|
+
const rate = { n: item.speed?.d ?? 1, d: item.speed?.n ?? 1 }
|
|
45
|
+
const own = words.filter((w) => w.asset === item.asset && w.end > item.in && w.start < item.out)
|
|
46
|
+
if (own.length === 0) spans.push({ at: item.at, end: item.end })
|
|
47
|
+
for (const w of own) {
|
|
48
|
+
const at = item.at + scaleFlicks(Math.max(w.start, item.in) - item.in, rate)
|
|
49
|
+
const end = item.at + scaleFlicks(Math.min(w.end, item.out) - item.in, rate)
|
|
50
|
+
if (end > at) spans.push({ at, end: Math.min(end, item.end) })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
spans.sort((a, b) => a.at - b.at)
|
|
54
|
+
const merged = []
|
|
55
|
+
for (const span of spans) {
|
|
56
|
+
const last = merged.at(-1)
|
|
57
|
+
if (last && span.at - last.end <= join) last.end = Math.max(last.end, span.end)
|
|
58
|
+
else merged.push({ ...span })
|
|
59
|
+
}
|
|
60
|
+
return merged
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The duck's gain over time, sampled at `rate`: 1 away from speech, 10^(depth/20) during
|
|
65
|
+
* it, with linear ramps of `attack` before and `release` after.
|
|
66
|
+
* @returns {Float32Array}
|
|
67
|
+
*/
|
|
68
|
+
export function duckEnvelope(spans, { duration, depth, attack, release, rate = 1000 }) {
|
|
69
|
+
const n = Math.max(1, Math.ceil((duration / FLICKS) * rate))
|
|
70
|
+
const floor = 10 ** (depth / 20)
|
|
71
|
+
const out = new Float32Array(n).fill(1)
|
|
72
|
+
const toSample = (t) => (t / FLICKS) * rate
|
|
73
|
+
for (const { at, end } of spans) {
|
|
74
|
+
const a0 = toSample(at - attack)
|
|
75
|
+
const a1 = toSample(at)
|
|
76
|
+
const r0 = toSample(end)
|
|
77
|
+
const r1 = toSample(end + release)
|
|
78
|
+
for (let i = Math.max(0, Math.floor(a0)); i < Math.min(n, Math.ceil(r1) + 1); i++) {
|
|
79
|
+
const duck = i < a1 ? (i - a0) / Math.max(1e-9, a1 - a0) : i <= r0 ? 1 : 1 - (i - r0) / Math.max(1e-9, r1 - r0)
|
|
80
|
+
const d = Math.min(1, Math.max(0, duck))
|
|
81
|
+
out[i] = Math.min(out[i], 1 - (1 - floor) * d)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return out
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The music's path to a length (EDITOR_WORKFLOWS §5): whole bars out of the middle, or
|
|
89
|
+
* bars repeated, joined on downbeats, so it starts on its start and ends on its ending.
|
|
90
|
+
* The ending lands on the last frame: any extra comes off the head.
|
|
91
|
+
* @param {{ from: number, to: number, downbeats: number[], bars: { start: number, energy: number }[], target: number, crossfade?: number }} input source flicks
|
|
92
|
+
* @returns {{ segments: { in: number, out: number }[], length: number } | null} null: no bars to cut on
|
|
93
|
+
*/
|
|
94
|
+
export function fitMusic({ from, to, downbeats, bars = [], target, crossfade = CROSSFADE }) {
|
|
95
|
+
const downs = downbeats.filter((t) => t > from && t < to).sort((a, b) => a - b)
|
|
96
|
+
const length = (segments) => segments.reduce((sum, s) => sum + (s.out - s.in), 0) - crossfade * (segments.length - 1)
|
|
97
|
+
if (downs.length < 4) return null
|
|
98
|
+
const barLength = Math.min(...downs.slice(1).map((t, i) => t - downs[i]))
|
|
99
|
+
const whole = [{ in: from, out: to }]
|
|
100
|
+
if (length(whole) >= target && length(whole) - target < barLength) return headTrim(whole, target, crossfade)
|
|
101
|
+
const energy = (t) => bars.find((b) => b.start === t)?.energy ?? 0
|
|
102
|
+
// Keep the first and last bar whole: the intro and the ending
|
|
103
|
+
const inner = downs.slice(1, -1)
|
|
104
|
+
let best = null
|
|
105
|
+
const consider = (segments, a, b) => {
|
|
106
|
+
const total = length(segments)
|
|
107
|
+
// Within a bar of the length: the rest comes off the head, inside the first piece
|
|
108
|
+
if (total < target || total - target >= barLength) return
|
|
109
|
+
// Shortest that still covers the picture, then the smoothest join
|
|
110
|
+
const cost = total - target + ms(200) * Math.abs(energy(a) - energy(b))
|
|
111
|
+
if (!best || cost < best.cost) best = { cost, segments }
|
|
112
|
+
}
|
|
113
|
+
if (length(whole) > target) {
|
|
114
|
+
for (let i = 0; i < inner.length; i++) for (let k = i + 1; k < inner.length; k++) consider([{ in: from, out: inner[i] }, { in: inner[k], out: to }], inner[i], inner[k])
|
|
115
|
+
} else {
|
|
116
|
+
// Too short: repeat a run of bars, as often as needed
|
|
117
|
+
for (let i = 0; i < inner.length; i++) {
|
|
118
|
+
for (let k = i + 1; k < inner.length; k++) {
|
|
119
|
+
const loop = inner[k] - inner[i] - crossfade
|
|
120
|
+
if (loop <= 0) continue
|
|
121
|
+
const times = Math.max(1, Math.ceil((target - length(whole)) / loop))
|
|
122
|
+
if (times > 64) continue
|
|
123
|
+
const segments = [{ in: from, out: inner[k] }, ...Array.from({ length: times - 1 }, () => ({ in: inner[i], out: inner[k] })), { in: inner[i], out: to }]
|
|
124
|
+
consider(segments, inner[k], inner[i])
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return best ? headTrim(best.segments, target, crossfade) : null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function headTrim(segments, target, crossfade) {
|
|
132
|
+
const total = segments.reduce((sum, s) => sum + (s.out - s.in), 0) - crossfade * (segments.length - 1)
|
|
133
|
+
const extra = total - target
|
|
134
|
+
const out = segments.map((s) => ({ ...s }))
|
|
135
|
+
if (extra > 0 && out[0].out - out[0].in > extra + crossfade) out[0].in += extra
|
|
136
|
+
return { segments: out, length: Math.min(total, target) }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Rule of restraint (EDITOR_WORKFLOWS §11): effects closer than the spacing are reported. */
|
|
140
|
+
export function crowdedEffects(items, spacing = SFX_SPACING) {
|
|
141
|
+
const peaks = items.filter((item) => busOf(item.role) === "sfx").map((item) => ({ clip: item.clip, t: item.at + (item.peak ?? 0) })).sort((a, b) => a.t - b.t)
|
|
142
|
+
const issues = []
|
|
143
|
+
for (let i = 1; i < peaks.length; i++) if (peaks[i].t - peaks[i - 1].t < spacing) issues.push({ code: "sfx_crowded", clip: peaks[i].clip, message: "two sound effects land too close together; the second one crowds the first" })
|
|
144
|
+
return issues
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The voice-clean chain (EDIT_ENGINE §10) with FFmpeg's own filters; strength 0 to 1. */
|
|
148
|
+
export function voiceClean(strength = 0.5) {
|
|
149
|
+
const s = Math.min(1, Math.max(0, strength))
|
|
150
|
+
return [
|
|
151
|
+
"highpass=f=80",
|
|
152
|
+
`afftdn=nr=${(6 + 18 * s).toFixed(1)}:nf=-50:tn=1`,
|
|
153
|
+
"equalizer=f=250:t=q:w=1:g=-2",
|
|
154
|
+
"equalizer=f=3500:t=q:w=1.2:g=2",
|
|
155
|
+
"deesser=i=0.3:m=0.5:f=0.5",
|
|
156
|
+
"acompressor=threshold=0.1:ratio=3:attack=10:release=150:makeup=1.5",
|
|
157
|
+
]
|
|
158
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// L8 face boxes on the output (ED8): through each piece's crop path, zoom and the
|
|
2
|
+
// final scale-and-centre-crop, exactly as ffmpeg.js's pictureChain draws the frame.
|
|
3
|
+
// The matte and QG-08 both read faces from here, so they agree with the picture.
|
|
4
|
+
|
|
5
|
+
import { scaleFlicks } from "./time.js"
|
|
6
|
+
|
|
7
|
+
/** The x of a crop path at source time t: straight lines between points, like ffmpeg.js's cropX. */
|
|
8
|
+
function cropAt(crop, t) {
|
|
9
|
+
if (t <= crop[0].t) return crop[0].x
|
|
10
|
+
const next = crop.findIndex((point) => point.t > t)
|
|
11
|
+
if (next === -1) return crop.at(-1).x
|
|
12
|
+
const [a, b] = [crop[next - 1], crop[next]]
|
|
13
|
+
return a.x + ((b.x - a.x) * (t - a.t)) / (b.t - a.t)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Maps one source box through a picture item to output pixels.
|
|
18
|
+
* @param {{ x: number, y: number, w: number, h: number }} box source pixels
|
|
19
|
+
* @param {{ crop?: { t: number, x: number }[], zoom?: { scale: number } }} item
|
|
20
|
+
* @param {{ width: number, height: number }} source
|
|
21
|
+
* @param {{ width: number, height: number }} canvas the project's frame (sets the crop's width)
|
|
22
|
+
* @param {{ width: number, height: number }} output
|
|
23
|
+
* @param {number} t source time, for the crop path
|
|
24
|
+
*/
|
|
25
|
+
export function mapBox(box, item, source, canvas, output, t) {
|
|
26
|
+
let { x, y, w, h } = box
|
|
27
|
+
let width = source.width
|
|
28
|
+
let height = source.height
|
|
29
|
+
if (item.crop?.length) {
|
|
30
|
+
const cropWidth = (height * canvas.width) / canvas.height
|
|
31
|
+
x -= cropAt(item.crop, t)
|
|
32
|
+
width = cropWidth
|
|
33
|
+
}
|
|
34
|
+
const focused = item.zoom && (item.zoom.x !== undefined || item.zoom.ease === "smooth")
|
|
35
|
+
if (item.zoom && !focused) {
|
|
36
|
+
const zw = width / item.zoom.scale
|
|
37
|
+
const zh = height / item.zoom.scale
|
|
38
|
+
x -= (width - zw) / 2
|
|
39
|
+
y -= (height - zh) / 2
|
|
40
|
+
width = zw
|
|
41
|
+
height = zh
|
|
42
|
+
}
|
|
43
|
+
// scale with force_original_aspect_ratio=increase, then a centred crop
|
|
44
|
+
const scale = Math.max(output.width / width, output.height / height)
|
|
45
|
+
const left = (width * scale - output.width) / 2
|
|
46
|
+
const top = (height * scale - output.height) / 2
|
|
47
|
+
let out = { x: x * scale - left, y: y * scale - top, w: w * scale, h: h * scale }
|
|
48
|
+
// A focused or eased punch-in zooms the finished frame (ffmpeg.js's zoomSteps).
|
|
49
|
+
// shortcut: an eased zoom is mapped at its full scale, so faces in its first and last 0.3 s sit a little off
|
|
50
|
+
if (focused) {
|
|
51
|
+
const s = item.zoom.scale
|
|
52
|
+
const [zw, zh] = [output.width / s, output.height / s]
|
|
53
|
+
const zx = Math.min(Math.max(((item.zoom.x ?? 500) / 1000) * output.width - zw / 2, 0), output.width - zw)
|
|
54
|
+
const zy = Math.min(Math.max(((item.zoom.y ?? 500) / 1000) * output.height - zh / 2, 0), output.height - zh)
|
|
55
|
+
out = { x: (out.x - zx) * s, y: (out.y - zy) * s, w: out.w * s, h: out.h * s }
|
|
56
|
+
}
|
|
57
|
+
const x0 = Math.max(0, Math.floor(out.x))
|
|
58
|
+
const y0 = Math.max(0, Math.floor(out.y))
|
|
59
|
+
const x1 = Math.min(output.width, Math.ceil(out.x + out.w))
|
|
60
|
+
const y1 = Math.min(output.height, Math.ceil(out.y + out.h))
|
|
61
|
+
return x1 > x0 && y1 > y0 ? { x: x0, y: y0, w: x1 - x0, h: y1 - y0 } : null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Every face sample that plays, at its output time, in output pixels.
|
|
66
|
+
* @param {object[]} picture picture items with absolute output times (wholeSegment's)
|
|
67
|
+
* @param {object[]} faces the index's L8 rows: { asset, t, box }
|
|
68
|
+
* @param {(asset: string) => { width: number, height: number } | undefined} sizeOf
|
|
69
|
+
* @param {{ canvas: object, output: object, zoomAt?: (t: number) => { scale: number } | undefined }} frame
|
|
70
|
+
* zoomAt: the punch-in at an output time, when items don't carry their own
|
|
71
|
+
* @returns {{ t: number, box: object }[]} sorted by time
|
|
72
|
+
*/
|
|
73
|
+
export function outputFaces(picture, faces, sizeOf, { canvas, output, zoomAt }) {
|
|
74
|
+
const found = []
|
|
75
|
+
for (const item of picture) {
|
|
76
|
+
const source = sizeOf(item.asset)
|
|
77
|
+
if (!source?.width || !source?.height) continue
|
|
78
|
+
for (const face of faces ?? []) {
|
|
79
|
+
if (face.asset !== item.asset) continue
|
|
80
|
+
if (item.hold ? face.t !== item.in : face.t < item.in || face.t > item.out) continue
|
|
81
|
+
const t = item.hold ? item.at : item.at + scaleFlicks(face.t - item.in, { n: item.speed.d, d: item.speed.n })
|
|
82
|
+
if (t < item.at || t > item.end) continue
|
|
83
|
+
const zoom = zoomAt ? zoomAt(t) : item.zoom
|
|
84
|
+
const box = mapBox(face.box, { crop: item.crop, zoom }, source, canvas, output, face.t)
|
|
85
|
+
if (box) found.push({ t, box })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return found.sort((a, b) => a.t - b.t)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The smallest box holding all of these. */
|
|
92
|
+
export function unionBox(boxes) {
|
|
93
|
+
if (boxes.length === 0) return null
|
|
94
|
+
const x0 = Math.min(...boxes.map((b) => b.x))
|
|
95
|
+
const y0 = Math.min(...boxes.map((b) => b.y))
|
|
96
|
+
const x1 = Math.max(...boxes.map((b) => b.x + b.w))
|
|
97
|
+
const y1 = Math.max(...boxes.map((b) => b.y + b.h))
|
|
98
|
+
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 }
|
|
99
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// FFmpeg arguments (EDIT_ENGINE §8.1): the compiler's one builder. An argument list
|
|
2
|
+
// for spawn, never a shell string. Text passes through one tested escape.
|
|
3
|
+
|
|
4
|
+
import { secondsArg } from "./time.js"
|
|
5
|
+
|
|
6
|
+
const BT709 = ["-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709", "-color_range", "tv"]
|
|
7
|
+
// On the frames too: FFmpeg can drop the output flags alone when it converts a format
|
|
8
|
+
const TAG_BT709 = "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709:range=tv"
|
|
9
|
+
|
|
10
|
+
/** Escapes text for FFmpeg's two parsers: the filter's options, then the filtergraph. */
|
|
11
|
+
export function escapeFilterValue(text) {
|
|
12
|
+
const option = String(text).replaceAll("\u0000", "").replace(/[\\':\s]/g, "\\$&")
|
|
13
|
+
return option.replace(/[\\'[\],;\s]/g, "\\$&")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const filter = (name, options) => `${name}=${Object.entries(options).map(([key, value]) => `${key}=${escapeFilterValue(value)}`).join(":")}`
|
|
17
|
+
|
|
18
|
+
function absolute(path) {
|
|
19
|
+
if (!path.startsWith("/") && !/^[A-Za-z]:[\\/]/.test(path)) throw new RangeError(`an input must be an absolute path, got "${path}"`)
|
|
20
|
+
return path
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The crop's x at the piece's time t (0 at item.in): straight lines between the path's
|
|
24
|
+
// points (ED11), so a reframe glides. Only the points where the slope changes are kept,
|
|
25
|
+
// so a hold or a steady move is one piece of the expression. faces.js maps the same way.
|
|
26
|
+
// shortcut: t is the output's clock, so a sped-up piece follows its path at 1×; reframed pieces aren't retimed yet
|
|
27
|
+
function cropX(crop, origin) {
|
|
28
|
+
const knots = crop.filter((p, i) => i === 0 || i === crop.length - 1 || (p.x - crop[i - 1].x) * (crop[i + 1].t - p.t) !== (crop[i + 1].x - p.x) * (p.t - crop[i - 1].t))
|
|
29
|
+
// The path holds its first x before its first point and its last x after its last, so flat ends add nothing
|
|
30
|
+
while (knots.length > 1 && knots.at(-1).x === knots.at(-2).x) knots.pop()
|
|
31
|
+
while (knots.length > 1 && knots[0].x === knots[1].x) knots.shift()
|
|
32
|
+
if (knots.length === 1) return String(knots[0].x)
|
|
33
|
+
const at = (point) => secondsArg(point.t - origin)
|
|
34
|
+
// A point before the piece starts has a negative time, which secondsArg doesn't print
|
|
35
|
+
const since = (point) => (point.t >= origin ? `t-${at(point)}` : `t+${secondsArg(origin - point.t)}`)
|
|
36
|
+
const pieces = knots.slice(1).map((point, i) => [at(point), `${knots[i].x}+(${point.x - knots[i].x})*(${since(knots[i])})/${secondsArg(point.t - knots[i].t)}`])
|
|
37
|
+
if (knots[0].t > origin) pieces.unshift([at(knots[0]), String(knots[0].x)])
|
|
38
|
+
return pieces.reduceRight((rest, [until, value]) => `if(lt(t,${until}),${value},${rest})`, String(knots.at(-1).x))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const EASE = 0.3 // seconds a smooth punch-in takes to arrive and to leave
|
|
42
|
+
|
|
43
|
+
// A punch-in with a focus or a smooth ease (ED11): zoompan on the finished frame, one
|
|
44
|
+
// frame out per frame in. z eases with smoothstep over EASE at each end of the zoom.
|
|
45
|
+
// shortcut: zoompan crops on whole pixels, so a slow zoom can shimmer; a sub-pixel scaler replaces it if a gate sees it
|
|
46
|
+
function zoomSteps(zoom, width, height, fps) {
|
|
47
|
+
const rate = `${fps.n}/${fps.d}`
|
|
48
|
+
let z = String(zoom.scale)
|
|
49
|
+
if (zoom.ease === "smooth") {
|
|
50
|
+
const t = `(in*${fps.d}/${fps.n}+${secondsArg(zoom.since)})`
|
|
51
|
+
const ramp = `clip(min(${t},${secondsArg(zoom.length)}-${t})/${EASE},0,1)`
|
|
52
|
+
z = `1+${zoom.scale - 1}*${ramp}*${ramp}*(3-2*${ramp})`
|
|
53
|
+
}
|
|
54
|
+
const [fx, fy] = [(zoom.x ?? 500) / 1000, (zoom.y ?? 500) / 1000]
|
|
55
|
+
return [filter("fps", { fps: rate }), filter("zoompan", { z, x: `clip(${fx}*iw-iw/zoom/2,0,iw-iw/zoom)`, y: `clip(${fy}*ih-ih/zoom/2,0,ih-ih/zoom)`, d: 1, s: `${width}x${height}`, fps: rate })]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** True when a zoom needs zoompan rather than a plain centred crop. */
|
|
59
|
+
export const animatedZoom = (zoom) => zoom !== undefined && (zoom.x !== undefined || zoom.ease === "smooth")
|
|
60
|
+
|
|
61
|
+
// A colour match (ED13) is its baked .cube, measured by the Engine; then the person's own values.
|
|
62
|
+
// shortcut: eq only approximates lift, gain and ev; a full lift/gamma/gain grade isn't built
|
|
63
|
+
function gradeSteps({ gamma, saturation, lift, gain, ev, match }, input) {
|
|
64
|
+
const steps = match ? [filter("lut3d", { file: input(match.key) })] : []
|
|
65
|
+
const brightness = (lift ?? 0) + (ev ?? 0) / 8
|
|
66
|
+
const options = Object.fromEntries(Object.entries({ gamma, saturation, brightness: brightness || undefined, contrast: gain }).filter(([, value]) => value !== undefined))
|
|
67
|
+
if (Object.keys(options).length) steps.push(filter("eq", options))
|
|
68
|
+
return steps
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Colour first (EX-10): an untagged source gets its tags, and HDR maps down through a LUT. */
|
|
72
|
+
export function colourSteps(color, toneMap) {
|
|
73
|
+
if (!color) return []
|
|
74
|
+
if (!color.tagged) return [filter("setparams", { color_primaries: "bt709", color_trc: "bt709", colorspace: "bt709", range: "tv" })]
|
|
75
|
+
if (!color.hdr) return []
|
|
76
|
+
if (!toneMap) throw new RangeError(`this render has no tone-map for ${color.transfer}`)
|
|
77
|
+
return [filter("scale", { in_color_matrix: "bt2020", in_range: "tv", out_range: "pc" }), "format=gbrp16le", filter("lut3d", { file: toneMap(color.transfer) }), filter("scale", { out_color_matrix: "bt709", out_range: "tv" }), "format=yuv420p"]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function pictureChain(item, width, height, plan, { input, toneMap }) {
|
|
81
|
+
const steps = []
|
|
82
|
+
// The input already seeks to item.in, so a long file isn't decoded from its start
|
|
83
|
+
if (item.hold) {
|
|
84
|
+
steps.push(filter("trim", { end_frame: 1 }), "setpts=PTS-STARTPTS", filter("tpad", { stop_mode: "clone", stop_duration: secondsArg(item.end - item.at) }))
|
|
85
|
+
} else {
|
|
86
|
+
steps.push(filter("trim", { duration: secondsArg(item.out - item.in) }), "setpts=PTS-STARTPTS")
|
|
87
|
+
if (item.speed.n !== item.speed.d) steps.push(`setpts=${item.speed.d}/${item.speed.n}*PTS`)
|
|
88
|
+
}
|
|
89
|
+
steps.push(...colourSteps(item.color, toneMap))
|
|
90
|
+
if (item.crop?.length) steps.push(filter("crop", { w: `ih*${plan.canvas.width}/${plan.canvas.height}`, h: "ih", x: cropX(item.crop, item.in), y: 0 }))
|
|
91
|
+
if (item.zoom && !animatedZoom(item.zoom)) steps.push(filter("crop", { w: `iw/${item.zoom.scale}`, h: `ih/${item.zoom.scale}` }))
|
|
92
|
+
steps.push(filter("scale", { w: width, h: height, force_original_aspect_ratio: "increase" }), filter("crop", { w: width, h: height }))
|
|
93
|
+
if (animatedZoom(item.zoom)) steps.push(...zoomSteps(item.zoom, width, height, plan.output.fps))
|
|
94
|
+
for (const effect of item.effects) {
|
|
95
|
+
if (effect.type === "lut") steps.push(filter("lut3d", { file: input(effect.asset) }))
|
|
96
|
+
else if (effect.type === "grade") steps.push(...gradeSteps(effect, input))
|
|
97
|
+
else if (effect.type !== "reframe") throw new RangeError(`this render can't do ${effect.type} yet`)
|
|
98
|
+
}
|
|
99
|
+
// Square pixels on every piece: a zoom's crop leaves a fractional aspect, and concat refuses a mix (found in ED7)
|
|
100
|
+
steps.push("setsar=1", TAG_BT709)
|
|
101
|
+
return steps.join(",")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The speaker's matte as a grey mask (EDD-49): a head ellipse and shoulders under the
|
|
106
|
+
* face box, white inside. shortcut: drawn from the face box, not segmented; MediaPipe's
|
|
107
|
+
* selfie segmenter replaces it when the runtime ships it.
|
|
108
|
+
*/
|
|
109
|
+
export function matteMask({ x, y, w, h }) {
|
|
110
|
+
const cx = x + w / 2
|
|
111
|
+
const cy = y + h * 0.45
|
|
112
|
+
const head = `lte(pow((X-${cx})/${(w * 0.62).toFixed(2)},2)+pow((Y-${cy})/${(h * 0.78).toFixed(2)},2),1)`
|
|
113
|
+
const top = y + h * 0.9
|
|
114
|
+
const body = `gte(Y,${top.toFixed(2)})*lte(abs(X-${cx}),min(${(w * 0.6).toFixed(2)}+(Y-${top.toFixed(2)})*0.9,${(w * 1.7).toFixed(2)}))`
|
|
115
|
+
return `255*gt(${head}+${body},0)`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ET-HR-01: whatever their start times, behind-the-speaker text, then cards, then captions on top
|
|
119
|
+
const depthOf = (part) => (part.node.behind === true && !part.front ? 0 : part.kind === "caption" ? 2 : 1)
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The argument list for one draft segment. Audio never lives in segments.
|
|
123
|
+
* @param {object} plan
|
|
124
|
+
* @param {object} segment
|
|
125
|
+
* @param {{ input: (asset: string) => string, tile: (key: string) => string, output: string, encoder: string[], toneMap?: (transfer: string) => string, frames?: number[], without?: (part: object) => boolean }} io
|
|
126
|
+
* paths come from the Engine, which knows the project; encoder is its typed choice.
|
|
127
|
+
* frames: write only these frame numbers, as raw RGB on output (QG-09 reads pixels behind text);
|
|
128
|
+
* without: tiles to leave out of the picture (QG-09 leaves out the text itself)
|
|
129
|
+
*/
|
|
130
|
+
export function segmentArgs(plan, segment, { input, tile, output, encoder, toneMap, frames, without }) {
|
|
131
|
+
const { width, height } = plan.output
|
|
132
|
+
const { node } = segment
|
|
133
|
+
const inputs = []
|
|
134
|
+
const inputFor = (path, seek = null) => inputs.push({ path: absolute(path), seek }) - 1
|
|
135
|
+
const tiles = node.tiles
|
|
136
|
+
.map((part) => ({ ...plan.tiles.find((t) => t.key === part.key), ...part }))
|
|
137
|
+
.filter((part) => !without?.(part))
|
|
138
|
+
.map((part, i) => ({ part, i }))
|
|
139
|
+
.sort((a, b) => depthOf(a.part) - depthOf(b.part) || a.i - b.i)
|
|
140
|
+
.map(({ part }) => part)
|
|
141
|
+
const chains = []
|
|
142
|
+
|
|
143
|
+
const labels = node.picture.map((item, i) => {
|
|
144
|
+
chains.push(`[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap })}[p${i}]`)
|
|
145
|
+
return `[p${i}]`
|
|
146
|
+
})
|
|
147
|
+
let current = labels[0]
|
|
148
|
+
if (labels.length > 1) {
|
|
149
|
+
chains.push(`${labels.join("")}concat=n=${labels.length}:v=1:a=0[base]`)
|
|
150
|
+
current = "[base]"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let step = 0
|
|
154
|
+
const layer = (from, at, end) => {
|
|
155
|
+
const next = `[v${step++}]`
|
|
156
|
+
// End-exclusive: `between` includes its end, which showed a layer one frame too long (found in ED8)
|
|
157
|
+
chains.push(`${current}${from}${filter("overlay", { enable: `gte(t,${secondsArg(Math.max(0, at))})*lt(t,${secondsArg(end)})` })}${next}`)
|
|
158
|
+
current = next
|
|
159
|
+
}
|
|
160
|
+
node.overlays.forEach((item, i) => {
|
|
161
|
+
chains.push(`[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap })},setpts=PTS+${secondsArg(item.at)}/TB[o${i}]`)
|
|
162
|
+
layer(`[o${i}]`, item.at, item.end)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
// The speaker, cut from the picture before anything covers it, goes back over the text behind
|
|
166
|
+
const mattes = node.mattes ?? []
|
|
167
|
+
const keeps = []
|
|
168
|
+
if (mattes.length) {
|
|
169
|
+
const labels = mattes.map((_, i) => `[mk${i}]`)
|
|
170
|
+
chains.push(`${current}split=${mattes.length + 1}[mb]${labels.join("")}`)
|
|
171
|
+
current = "[mb]"
|
|
172
|
+
keeps.push(...labels)
|
|
173
|
+
}
|
|
174
|
+
const drawMattes = () => {
|
|
175
|
+
mattes.forEach((matte, i) => {
|
|
176
|
+
const length = secondsArg(segment.end - segment.start)
|
|
177
|
+
chains.push(`${filter("color", { c: "black", s: `${width}x${height}`, r: `${plan.output.fps.n}/${plan.output.fps.d}`, d: length })},format=gray,${filter("geq", { lum: matteMask(matte.box) })}[mm${i}]`)
|
|
178
|
+
chains.push(`${keeps[i]}[mm${i}]alphamerge[ms${i}]`)
|
|
179
|
+
layer(`[ms${i}]`, matte.at, matte.end)
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let matted = mattes.length === 0
|
|
184
|
+
for (const part of tiles) {
|
|
185
|
+
if (!matted && depthOf(part) > 0) {
|
|
186
|
+
drawMattes()
|
|
187
|
+
matted = true
|
|
188
|
+
}
|
|
189
|
+
if (part.kind === "caption" && part.node.style?.burn === true) {
|
|
190
|
+
const next = `[v${step++}]`
|
|
191
|
+
const box = part.node.placement
|
|
192
|
+
chains.push(`${current}${filter("drawtext", { text: part.node.text, expansion: "none", x: box?.x ?? 0, y: box?.y ?? 0, enable: `gte(t,${secondsArg(Math.max(0, part.at))})*lt(t,${secondsArg(part.end)})` })}${next}`)
|
|
193
|
+
current = next
|
|
194
|
+
} else {
|
|
195
|
+
const label = `[t${step}]`
|
|
196
|
+
// A tile that began in an earlier segment starts part way through
|
|
197
|
+
chains.push(`[${inputFor(tile(part.key))}:v]${filter("trim", { start: secondsArg(Math.max(0, -part.at)) })},setpts=PTS-STARTPTS+${secondsArg(Math.max(0, part.at))}/TB${label}`)
|
|
198
|
+
layer(label, part.at, part.end)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!matted) drawMattes()
|
|
202
|
+
|
|
203
|
+
const head = ["-nostdin", "-hide_banner", ...inputs.flatMap(({ path, seek }) => [...(seek === null ? [] : ["-ss", secondsArg(seek)]), "-protocol_whitelist", "file,pipe", "-i", path])]
|
|
204
|
+
if (frames) {
|
|
205
|
+
chains.push(`${current}${filter("select", { expr: frames.map((n) => `eq(n,${n})`).join("+") })},format=rgb24[still]`)
|
|
206
|
+
return [...head, "-filter_complex", chains.join(";"), "-map", "[still]", "-an", "-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", "rgb24", output]
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return [
|
|
210
|
+
"-nostdin",
|
|
211
|
+
"-hide_banner",
|
|
212
|
+
...inputs.flatMap(({ path, seek }) => [...(seek === null ? [] : ["-ss", secondsArg(seek)]), "-protocol_whitelist", "file,pipe", "-i", path]),
|
|
213
|
+
"-filter_complex",
|
|
214
|
+
chains.join(";"),
|
|
215
|
+
"-map",
|
|
216
|
+
current,
|
|
217
|
+
"-an",
|
|
218
|
+
...BT709,
|
|
219
|
+
"-r",
|
|
220
|
+
`${plan.output.fps.n}/${plan.output.fps.d}`,
|
|
221
|
+
"-t",
|
|
222
|
+
secondsArg(segment.end - segment.start),
|
|
223
|
+
...encoder,
|
|
224
|
+
"-y",
|
|
225
|
+
output,
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// The sound lives in mix.js (ED9): buses, voice clean, music fit, band ducking
|
|
230
|
+
export { audioArgs, stemsMixArgs } from "./mix.js"
|
|
231
|
+
|
|
232
|
+
/** EDD-12: the proxy. GOP 30 with no B-frames, measured frame-accurate in EX-03; timestamps are kept, so a VFR source doesn't drift. */
|
|
233
|
+
export function proxyArgs({ source, output, encoder, color, toneMap }) {
|
|
234
|
+
const steps = [...colourSteps(color, toneMap), filter("scale", { w: 960, h: 540, force_original_aspect_ratio: "decrease", force_divisible_by: 2 }), "format=yuv420p", TAG_BT709]
|
|
235
|
+
return ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-i", absolute(source), "-vf", steps.join(","), "-fps_mode", "passthrough", ...encoder, "-g", "30", "-bf", "0", "-b:v", "1500k", ...BT709, "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart", "-y", output]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A small copy of a finished file for Kriya: a fixed bitrate, so its size is known ahead (EH-23). */
|
|
239
|
+
export function previewArgs({ source, output, encoder, videoKbps, audioKbps }) {
|
|
240
|
+
return ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-i", absolute(source), "-vf", "scale=-2:'min(720,ih)'", ...encoder, "-b:v", `${videoKbps}k`, "-maxrate", `${videoKbps}k`, "-bufsize", `${videoKbps * 2}k`, "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", `${audioKbps}k`, "-movflags", "+faststart", "-y", output]
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** A few seconds of a take for a decision card (TAVI_INTEGRATION §5): small, and quick to open. */
|
|
244
|
+
export function clipArgs({ source, output, encoder, fromSeconds, seconds }) {
|
|
245
|
+
return ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-ss", fromSeconds.toFixed(3), "-t", seconds.toFixed(3), "-i", absolute(source), "-vf", "scale=-2:'min(360,ih)'", ...encoder, "-b:v", "400k", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "64k", "-movflags", "+faststart", "-y", output]
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Mono, at a rate peaks can be read from, on stdout. */
|
|
249
|
+
export const peakArgs = ({ source, rate }) => ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-i", absolute(source), "-vn", "-ac", "1", "-ar", String(rate), "-f", "s16le", "pipe:1"]
|
|
250
|
+
|
|
251
|
+
/** One sprite sheet of thumbnails, `every` seconds apart. */
|
|
252
|
+
export const thumbArgs = ({ source, output, every, columns, rows }) => ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-i", absolute(source), "-vf", `fps=1/${every},scale=160:-2,tile=${columns}x${rows}`, "-frames:v", "1", "-y", output]
|
|
253
|
+
|
|
254
|
+
/** Joins segments by stream copy and muxes the one audio track. `list` is a concat file Kriya wrote. */
|
|
255
|
+
export const joinArgs = ({ list, audio, output }) => ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-f", "concat", "-safe", "1", "-i", absolute(list), "-protocol_whitelist", "file,pipe", "-i", absolute(audio), "-map", "0:v", "-map", "1:a", "-c", "copy", "-movflags", "+faststart", "-y", output]
|
|
256
|
+
|
|
257
|
+
/** Muxes a master's picture and its audio. */
|
|
258
|
+
export const muxArgs = ({ video, audio, output }) => ["-nostdin", "-hide_banner", "-protocol_whitelist", "file,pipe", "-i", absolute(video), "-protocol_whitelist", "file,pipe", "-i", absolute(audio), "-map", "0:v", "-map", "1:a", "-c", "copy", "-movflags", "+faststart", "-y", output]
|