@senseihq/emaki-cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +69 -2
- package/package.json +44 -4
- package/plugin/.claude-plugin/plugin.json +19 -0
- package/plugin/PLAYBOOK.md +137 -0
- package/plugin/README.md +51 -0
- package/plugin/agents/fact-checker.md +28 -0
- package/plugin/agents/localizer.md +34 -0
- package/plugin/agents/scene-builder.md +43 -0
- package/plugin/agents/story-planner.md +42 -0
- package/plugin/agents/story-writer.md +34 -0
- package/plugin/agents/visual-reviewer.md +33 -0
- package/plugin/modules/campaign/README.md +30 -0
- package/plugin/modules/campaign/calendar.csv +2 -0
- package/plugin/modules/campaign/day-script.template.md +42 -0
- package/plugin/modules/posting-desk/README.md +37 -0
- package/plugin/skills/emaki/SKILL.md +107 -0
- package/plugin/skills/emaki/references/01-interview.md +68 -0
- package/plugin/skills/emaki/references/02-architecture.md +69 -0
- package/plugin/skills/emaki/references/03-content-model.md +68 -0
- package/plugin/skills/emaki/references/04-scene-authoring.md +99 -0
- package/plugin/skills/emaki/references/05-voice-and-video.md +97 -0
- package/plugin/skills/emaki/references/06-i18n.md +37 -0
- package/plugin/skills/emaki/references/07-quality-gates.md +44 -0
- package/plugin/skills/emaki/references/08-feedback-loop.md +32 -0
- package/plugin/skills/emaki/references/09-publishing.md +14 -0
- package/plugin/skills/story-build/SKILL.md +37 -0
- package/plugin/skills/story-localize/SKILL.md +24 -0
- package/plugin/skills/story-media/SKILL.md +38 -0
- package/plugin/skills/story-publish/SKILL.md +36 -0
- package/plugin/skills/story-review/SKILL.md +29 -0
- package/plugin/templates/brief.md +32 -0
- package/plugin/templates/change-request.md +7 -0
- package/plugin/templates/changelog.md +4 -0
- package/plugin/templates/decisions.md +5 -0
- package/plugin/templates/glossary.md +4 -0
- package/plugin/templates/item-card.md +34 -0
- package/plugin/templates/outline.md +19 -0
- package/plugin/templates/review-sheet.md +12 -0
- package/plugin/templates/style-guide.md +21 -0
- package/plugin/templates/tracker.md +11 -0
- package/src/api.js +20 -0
- package/src/campaign.js +157 -0
- package/src/capture.js +205 -0
- package/src/carousel.js +91 -0
- package/src/config.js +32 -0
- package/src/day-script.js +66 -0
- package/src/desk-client.js +37 -0
- package/src/desk-plan.js +57 -0
- package/src/films.js +152 -0
- package/src/http.js +30 -0
- package/src/index.js +353 -0
- package/src/init.js +110 -0
- package/src/media.js +236 -0
- package/src/migrate.js +67 -0
- package/src/plugin.js +106 -0
- package/src/publish.js +118 -0
- package/src/stage.js +107 -0
- package/src/stories.js +66 -0
- package/src/tts.js +290 -0
- package/src/upload/instagram.js +34 -0
- package/src/upload/youtube.js +90 -0
- package/src/util.js +66 -0
- package/src/voice.js +295 -0
- package/src/youtube-text.js +58 -0
- package/templates/content/films/index.json +1 -0
- package/templates/content/films/measure-the-right-work/film.json +68 -0
- package/templates/content/films/measure-the-right-work/look.css +17 -0
- package/templates/content/films/measure-the-right-work/scene-close.json +153 -0
- package/templates/content/films/measure-the-right-work/scene-groups.json +99 -0
- package/templates/content/films/measure-the-right-work/scene-hook.json +96 -0
- package/templates/content/films/measure-the-right-work/scene-pair.json +190 -0
- package/templates/content/films/measure-the-right-work/scene-problem.json +162 -0
- package/templates/content/films/measure-the-right-work/score.js +19 -0
- package/templates/content/films/measure-the-right-work/strings/en.json +50 -0
- package/templates/content/films/measure-the-right-work/strings/es.json +50 -0
- package/templates/content/films/measure-the-right-work/timing.en.json +24 -0
- package/templates/content/films/measure-the-right-work/timing.es.json +24 -0
- package/templates/content/films/measure-the-right-work/voice/en/close.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/en/groups.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/en/hook.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/en/pair.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/en/problem.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/en.json +7 -0
- package/templates/content/films/measure-the-right-work/voice/es/close.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/es/groups.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/es/hook.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/es/pair.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/es/problem.m4a +0 -0
- package/templates/content/films/measure-the-right-work/voice/es.json +7 -0
- package/templates/content/logos/brand.svg +1 -0
- package/templates/content/site.json +10 -0
- package/templates/content/stories/en/measure-the-right-work.json +13 -0
- package/templates/content/stories/es/measure-the-right-work.json +13 -0
- package/templates/content/stories/index.json +12 -0
- package/templates/content/ui/en.json +1 -0
- package/templates/content/ui/es.json +1 -0
- package/templates/emaki.config.json +67 -0
- package/templates/film/look.css +17 -0
- package/templates/film/scene-close.json +153 -0
- package/templates/film/scene-template.json +71 -0
- package/templates/film/score.js +12 -0
package/src/voice.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// The narration: choose a voice per locale, synthesise takes, fit scene times to them, and build the final videos
|
|
2
|
+
// (voice + score + captions, -14 LUFS).
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { join, resolve } from 'node:path'
|
|
5
|
+
import { SUFFIX } from './config.js'
|
|
6
|
+
import {
|
|
7
|
+
buildArgs, buildPlan, chaptersText, description, ffmeta, planTable, posterSteps, storyLink, webArgs, webNote, webVoiceArgs, ytChapters
|
|
8
|
+
} from './media.js'
|
|
9
|
+
import { OFFLINE, provider, TTSError, voiceConfig } from './tts.js'
|
|
10
|
+
import { localizeScene, motionEnd } from '@senseihq/emaki'
|
|
11
|
+
import { die, hasAudio, load, mediaLength, pad2, run, save } from './util.js'
|
|
12
|
+
|
|
13
|
+
export const NO_PROVIDER = (loc) => `no voice provider is set for ${loc}. Choose one and record it with set-voice, for example:
|
|
14
|
+
offline piper (good, free) kokoro (very natural, free) macos (Mac drafts) espeak (robotic drafts)
|
|
15
|
+
cloud elevenlabs openai azure (Microsoft shops) google (Google shops) polly (AWS shops)
|
|
16
|
+
person manual (record take-NN.wav files yourself)
|
|
17
|
+
emaki set-voice --locale default --provider piper --opt model=voices/en_US-lessac-medium.onnx`
|
|
18
|
+
|
|
19
|
+
export function chosen(p, locale, override, opts = {}) {
|
|
20
|
+
let v = voiceConfig(p.cfg, locale)
|
|
21
|
+
if (override) v = { ...v, provider: override }
|
|
22
|
+
v = { ...v, ...opts }
|
|
23
|
+
if (!v.provider) die(NO_PROVIDER(locale))
|
|
24
|
+
return { vcfg: v, prov: provider(v.provider) }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Per locale: the configured provider and whether it is ready here; and which offline engines this machine has. */
|
|
28
|
+
export function ttsCheck(p) {
|
|
29
|
+
const rows = p.site.locales.map((loc) => {
|
|
30
|
+
const v = voiceConfig(p.cfg, loc)
|
|
31
|
+
if (!v.provider) return { locale: loc, provider: null, ready: false, note: 'no provider set' }
|
|
32
|
+
try {
|
|
33
|
+
provider(v.provider).check(v, loc)
|
|
34
|
+
return { locale: loc, provider: v.provider, label: provider(v.provider).label, ready: true }
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return { locale: loc, provider: v.provider, label: provider(v.provider).label, ready: false, note: e.message }
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
const here = []
|
|
40
|
+
for (const name of OFFLINE) {
|
|
41
|
+
try {
|
|
42
|
+
provider(name).check(name === 'piper' ? { model: '__probe__' } : {}, p.site.defaultLocale)
|
|
43
|
+
here.push(name)
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (name === 'piper' && /voice model/.test(e.message)) here.push('piper (needs a voice model)')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { rows, offline: here }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Records the provider (and options) for a locale in emaki.config.json. Keys never go there. */
|
|
52
|
+
export function setVoice(p, locale, name, opts = {}) {
|
|
53
|
+
provider(name)
|
|
54
|
+
const cfg = existsSync(p.cfgPath) ? load(p.cfgPath) : {}
|
|
55
|
+
const block = ((cfg.voice ??= {})[locale] ??= {})
|
|
56
|
+
block.provider = name
|
|
57
|
+
Object.assign(block, opts)
|
|
58
|
+
const dropped = Object.keys(block).filter((k) => /key|secret|token/i.test(k))
|
|
59
|
+
for (const k of dropped) delete block[k]
|
|
60
|
+
save(p.cfgPath, cfg)
|
|
61
|
+
p.cfg = cfg
|
|
62
|
+
return { block, dropped }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function listVoices(p, locale, override) {
|
|
66
|
+
const { vcfg, prov } = chosen(p, locale, override)
|
|
67
|
+
return prov.voices(vcfg, locale)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Synthesises take-NN.wav per voice line (or prints the recording list for `manual`). */
|
|
71
|
+
export async function voice(p, slug, { locale, only, provider: override, opts = {}, log = console.info } = {}) {
|
|
72
|
+
const d = p.filmDir(slug)
|
|
73
|
+
const lines = load(join(d, 'voice', `${locale}.json`))
|
|
74
|
+
const pick = only ? new Set(String(only).split(',').map(Number)) : null
|
|
75
|
+
const { vcfg, prov } = chosen(p, locale, override, opts)
|
|
76
|
+
try {
|
|
77
|
+
prov.check(vcfg, locale)
|
|
78
|
+
} catch (e) {
|
|
79
|
+
die(`${prov.label}: ${e.message}`)
|
|
80
|
+
}
|
|
81
|
+
const takes = p.prod(slug, locale, 'takes')
|
|
82
|
+
if (vcfg.provider === 'manual') {
|
|
83
|
+
log(`manual: record ${lines.length} takes into ${p.rel(takes)}/ as take-01.wav … take-${pad2(lines.length)}.wav, in this order:`)
|
|
84
|
+
lines.forEach((l, i) => log(` take-${pad2(i + 1)} (${l.scene}): ${l.text}`))
|
|
85
|
+
return []
|
|
86
|
+
}
|
|
87
|
+
mkdirSync(takes, { recursive: true })
|
|
88
|
+
const spoken = lines.map((l) => l.say || l.text), made = []
|
|
89
|
+
for (const [i, l] of lines.entries()) {
|
|
90
|
+
const n = i + 1
|
|
91
|
+
if (pick && !pick.has(n)) continue
|
|
92
|
+
const ctx = { prev: spoken[i - 1] ?? null, next: spoken[i + 1] ?? null }
|
|
93
|
+
const dst = join(takes, `take-${pad2(n)}.wav`)
|
|
94
|
+
try {
|
|
95
|
+
await prov.synth(spoken[i], dst, vcfg, locale, ctx)
|
|
96
|
+
} catch (e) {
|
|
97
|
+
die(`take-${pad2(n)}: ${e instanceof TTSError ? e.message : e}`)
|
|
98
|
+
}
|
|
99
|
+
const len = mediaLength(dst)
|
|
100
|
+
made.push({ take: n, scene: l.scene, seconds: len })
|
|
101
|
+
log(`take-${pad2(n)} (${l.scene}): ${len.toFixed(1)} s · ${prov.label}`)
|
|
102
|
+
}
|
|
103
|
+
const keep = Object.fromEntries(Object.entries(vcfg).filter(([k]) => ['provider', 'voice', 'voice_id', 'model'].includes(k)))
|
|
104
|
+
writeFileSync(join(takes, 'provider.json'), JSON.stringify(keep, null, 1) + '\n')
|
|
105
|
+
return made
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** scene id → [take file, voice line] for the takes that exist. */
|
|
109
|
+
export function takesFor(p, slug, locale) {
|
|
110
|
+
const d = p.filmDir(slug), lines = load(join(d, 'voice', `${locale}.json`)), folder = p.prod(slug, locale, 'takes')
|
|
111
|
+
const out = new Map()
|
|
112
|
+
lines.forEach((l, i) => {
|
|
113
|
+
for (const ext of ['wav', 'mp3', 'm4a', 'aiff']) {
|
|
114
|
+
const f = join(folder, `take-${pad2(i + 1)}.${ext}`)
|
|
115
|
+
if (existsSync(f)) { out.set(l.scene, [f, l]); break }
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
return out
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The narration for the browser: each take as voice/<locale>/<scene>.m4a beside the film, and in timing.<locale>.json
|
|
122
|
+
* each narrated scene's `voice` start (the same lead the videos use), so the story player and article figures speak
|
|
123
|
+
* in step with the picture. A scene whose take is gone loses its file and its start. Run after `fit`. */
|
|
124
|
+
export function voiceWeb(p, slug, { locale, encode = (src, dst) => run('ffmpeg', webVoiceArgs(src, dst)), log = () => {} } = {}) {
|
|
125
|
+
const d = p.filmDir(slug), takes = takesFor(p, slug, locale)
|
|
126
|
+
if (!takes.size) die(`${slug} has no takes for ${locale}: record or synthesise them first (emaki voice ${slug} --locale ${locale})`)
|
|
127
|
+
const film = load(join(d, 'film.json')), dir = join(d, 'voice', locale), tp = join(d, `timing.${locale}.json`)
|
|
128
|
+
const timing = existsSync(tp) ? load(tp) : { scenes: {} }
|
|
129
|
+
const tsc = (timing.scenes ??= {})
|
|
130
|
+
mkdirSync(dir, { recursive: true })
|
|
131
|
+
const wrote = [], removed = []
|
|
132
|
+
for (const s of film.scenes) {
|
|
133
|
+
const dst = join(dir, `${s.id}.m4a`), c = tsc[s.id] ?? {}
|
|
134
|
+
if (takes.has(s.id)) {
|
|
135
|
+
encode(takes.get(s.id)[0], dst)
|
|
136
|
+
wrote.push(p.rel(dst))
|
|
137
|
+
log(`${p.rel(dst)}`)
|
|
138
|
+
c.voice = p.lead
|
|
139
|
+
} else {
|
|
140
|
+
if (existsSync(dst)) { rmSync(dst); removed.push(p.rel(dst)) }
|
|
141
|
+
delete c.voice
|
|
142
|
+
}
|
|
143
|
+
if (Object.keys(c).length) tsc[s.id] = c
|
|
144
|
+
else delete tsc[s.id]
|
|
145
|
+
}
|
|
146
|
+
if (!readdirSync(dir).length) rmSync(dir, { recursive: true })
|
|
147
|
+
save(tp, timing)
|
|
148
|
+
return { wrote, removed, timing: p.rel(tp) }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const up = (v) => Math.ceil(v * 10 - 1e-9) / 10
|
|
152
|
+
|
|
153
|
+
/** When scene `s` stops moving, in scene seconds: film.json "settle", else the end of its JSON scene's tracks in this
|
|
154
|
+
* locale (word counts follow the translation), else null (a JS scene: its motion cannot be read). */
|
|
155
|
+
function settleOf(d, s, locale) {
|
|
156
|
+
if (s.settle != null) return s.settle
|
|
157
|
+
const f = join(d, `scene-${s.id}.json`)
|
|
158
|
+
if (!existsSync(f)) return null
|
|
159
|
+
const sp = join(d, `strings/${locale}.json`)
|
|
160
|
+
return motionEnd(localizeScene(load(f), existsSync(sp) ? load(sp) : {}))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** timing.<locale>.json: a narrated scene runs lead + take + tail, longer or shorter than its design, but never ends
|
|
164
|
+
* before its motion settles; a scene without a take, or a JS scene without "settle", keeps its design time. */
|
|
165
|
+
export function fit(p, slug, { locale, check = false, length = mediaLength } = {}) {
|
|
166
|
+
const d = p.filmDir(slug), film = load(join(d, 'film.json')), takes = takesFor(p, slug, locale)
|
|
167
|
+
const tp = join(d, `timing.${locale}.json`)
|
|
168
|
+
const timing = existsSync(tp) ? load(tp) : { scenes: {} }
|
|
169
|
+
const tsc = (timing.scenes ??= {})
|
|
170
|
+
const rows = []
|
|
171
|
+
for (const s of film.scenes) {
|
|
172
|
+
const c = tsc[s.id] ?? {}
|
|
173
|
+
const holds = (c.holds ?? []).reduce((n, h) => n + h[1], 0)
|
|
174
|
+
const L = takes.has(s.id) ? length(takes.get(s.id)[0]) : 0
|
|
175
|
+
const base = s.dur + holds
|
|
176
|
+
let runs = base
|
|
177
|
+
if (L) {
|
|
178
|
+
const settle = settleOf(d, s, locale)
|
|
179
|
+
const floor = settle == null ? base : Math.min(base, up(settle + holds))
|
|
180
|
+
runs = Math.max(floor, up(p.lead + L + p.tail))
|
|
181
|
+
}
|
|
182
|
+
if (Math.abs(runs - base) > 1e-6) c.dur = runs
|
|
183
|
+
else delete c.dur
|
|
184
|
+
if (Object.keys(c).length) tsc[s.id] = c
|
|
185
|
+
else delete tsc[s.id]
|
|
186
|
+
rows.push({ scene: s.id, design: s.dur, holds, take: L, runs, longer: runs > base + 1e-6, shorter: runs < base - 1e-6 })
|
|
187
|
+
}
|
|
188
|
+
if (!check) save(tp, timing)
|
|
189
|
+
return { rows, total: rows.reduce((n, r) => n + r.runs, 0), path: p.rel(tp), written: !check }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const stamp = (t, sep = '.') => {
|
|
193
|
+
const h = Math.floor(t / 3600), m = Math.floor((t % 3600) / 60), s = t % 60
|
|
194
|
+
return `${pad2(h)}:${pad2(m)}:${s.toFixed(3).padStart(6, '0')}`.replace('.', sep)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Captions from the voice lines, spread over each take by sentence length. */
|
|
198
|
+
export function captions(takes, starts, lead, length = mediaLength) {
|
|
199
|
+
const vtt = ['WEBVTT', ''], srt = []
|
|
200
|
+
let k = 0
|
|
201
|
+
for (const [sid, [f, line]] of takes) {
|
|
202
|
+
let t0 = starts.get(sid)[0] + lead
|
|
203
|
+
const span = length(f) - 0.1
|
|
204
|
+
const parts = line.text.split(/(?<=[.!?¿¡;:])\s+/).map((x) => x.trim()).filter(Boolean)
|
|
205
|
+
const total = parts.reduce((n, x) => n + x.length, 0)
|
|
206
|
+
for (const x of parts) {
|
|
207
|
+
const dd = (span * x.length) / total
|
|
208
|
+
k++
|
|
209
|
+
vtt.push(`${stamp(t0)} --> ${stamp(t0 + dd)}`, x, '')
|
|
210
|
+
srt.push(String(k), `${stamp(t0, ',')} --> ${stamp(t0 + dd, ',')}`, x, '')
|
|
211
|
+
t0 += dd
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { vtt: vtt.join('\n'), srt: srt.join('\n') }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** libass lays SRT out on a 384x288 canvas scaled to the video, so these are in 288ths of the height: landscape 16 ≈
|
|
218
|
+
* 60 px text 127 px up; portrait 9 ≈ 60 px text 333 px up (clear of the platform's buttons). */
|
|
219
|
+
const burnIn = (srtPath, layout) => {
|
|
220
|
+
const size = layout === 'landscape' ? 16 : 9, margin = layout === 'landscape' ? 34 : 50
|
|
221
|
+
return `subtitles=${srtPath.replace(/([:\\'])/g, '\\$1')}:force_style='FontName=Inter,FontSize=${size},PrimaryColour=&H00FFFFFF,OutlineColour=&H66000000,BackColour=&H66000000,BorderStyle=3,Outline=5,Shadow=0,MarginV=${margin}'`
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Final videos per orientation (build.py): the rendered picture with the voice laid `lead` s into each scene, the
|
|
225
|
+
* render's music ducked under it, -14 LUFS, captions burned in (and shipped as .srt/.vtt). A take that outruns its
|
|
226
|
+
* scene freezes the scene's last frame until it has finished (buildPlan). `check` prints the plan and builds nothing;
|
|
227
|
+
* `out` is the output folder (default production/<slug>/<locale>/out/). */
|
|
228
|
+
export function build(p, slug, { locale, noCaptions = false, check = false, out: target = undefined, log = console.info, length = mediaLength } = {}) {
|
|
229
|
+
const d = p.filmDir(slug), film = load(join(d, 'film.json'))
|
|
230
|
+
const tp = join(d, `timing.${locale}.json`)
|
|
231
|
+
const tm = existsSync(tp) ? (load(tp).scenes ?? {}) : {}
|
|
232
|
+
const takes = takesFor(p, slug, locale)
|
|
233
|
+
const plan = buildPlan(film, tm, new Map([...takes].map(([sid, [file]]) => [sid, { file, seconds: length(file) }])), p)
|
|
234
|
+
const render = p.prod(slug, locale, 'render')
|
|
235
|
+
const pics = ['landscape', 'portrait'].map((layout) => [layout, join(render, `${slug}-${locale}-${SUFFIX[layout]}.mp4`)])
|
|
236
|
+
.filter(([, f]) => existsSync(f))
|
|
237
|
+
log(`${film.title ?? slug} (${locale}): ${plan.picture.toFixed(1)} s as rendered`)
|
|
238
|
+
planTable(plan).forEach((l) => log(l))
|
|
239
|
+
if (plan.missing.length) log(`missing takes: ${plan.missing.join(', ')}`)
|
|
240
|
+
if (check) {
|
|
241
|
+
if (!pics.length) log(`MISSING: no render in ${p.rel(render)}; run \`emaki render ${slug} --locale ${locale}\``)
|
|
242
|
+
return { built: [], duration: plan.total, plan }
|
|
243
|
+
}
|
|
244
|
+
if (!takes.size) die(`no takes in ${p.rel(p.prod(slug, locale, 'takes'))}; run \`emaki voice\` (or record them) first`)
|
|
245
|
+
if (!pics.length) die(`no render in ${p.rel(render)}; run \`emaki render ${slug} --locale ${locale}\` first`)
|
|
246
|
+
const out = target ? resolve(target) : p.prod(slug, locale, 'out')
|
|
247
|
+
mkdirSync(out, { recursive: true })
|
|
248
|
+
const voiced = new Map([...takes].filter(([sid]) => plan.rows.some((r) => r.id === sid)))
|
|
249
|
+
const starts = new Map(plan.rows.map((r) => [r.id, [r.at, r.tot]]))
|
|
250
|
+
const cap = captions(voiced, starts, p.lead, length)
|
|
251
|
+
const srtPath = join(out, `${slug}-${locale}.srt`)
|
|
252
|
+
writeFileSync(join(out, `${slug}-${locale}.vtt`), cap.vtt)
|
|
253
|
+
writeFileSync(srtPath, cap.srt)
|
|
254
|
+
const inputs = [], filters = []
|
|
255
|
+
;[...voiced].forEach(([sid, [f]], i) => {
|
|
256
|
+
inputs.push('-i', f)
|
|
257
|
+
const ms = Math.round((starts.get(sid)[0] + p.lead) * 1000)
|
|
258
|
+
filters.push(`[${i}:a]aresample=48000,adelay=${ms}|${ms},apad[v${i}]`)
|
|
259
|
+
})
|
|
260
|
+
const voicePath = join(out, 'voice.wav')
|
|
261
|
+
run('ffmpeg', ['-y', '-v', 'error', ...inputs, '-filter_complex',
|
|
262
|
+
filters.join(';') + ';' + [...voiced].map((_, i) => `[v${i}]`).join('') + `amix=inputs=${voiced.size}:normalize=0,atrim=0:${plan.total.toFixed(3)}[vo]`,
|
|
263
|
+
'-map', '[vo]', '-ac', '2', voicePath])
|
|
264
|
+
const chapters = join(out, 'chapters.ffmeta')
|
|
265
|
+
writeFileSync(chapters, ffmeta(plan.rows))
|
|
266
|
+
const yt = ytChapters(plan.rows)
|
|
267
|
+
writeFileSync(join(out, 'chapters.txt'), chaptersText(yt))
|
|
268
|
+
const story = join(p.content, 'stories', locale, `${slug}.json`)
|
|
269
|
+
const title = (existsSync(story) ? load(story).title : null) ?? film.title ?? slug
|
|
270
|
+
writeFileSync(join(out, 'description.txt'), description({ title, chapters: yt, link: storyLink(p.site, p.cfg, slug, locale) }))
|
|
271
|
+
const built = [], videos = {}
|
|
272
|
+
for (const [layout, pic] of pics) {
|
|
273
|
+
const dst = join(out, `${slug}-${locale}-${SUFFIX[layout]}.mp4`)
|
|
274
|
+
run('ffmpeg', buildArgs({
|
|
275
|
+
pic, voice: voicePath, plan, music: hasAudio(pic), subtitles: noCaptions ? null : burnIn(srtPath, layout),
|
|
276
|
+
chapters, scoreLevel: p.cfg.scoreLevel ?? 0.55, dst
|
|
277
|
+
}))
|
|
278
|
+
log(`built ${p.rel(dst)} (${plan.rows.length} chapters)`)
|
|
279
|
+
built.push((videos[layout] = dst))
|
|
280
|
+
}
|
|
281
|
+
rmSync(chapters, { force: true })
|
|
282
|
+
if (videos.landscape) {
|
|
283
|
+
const web = join(out, `${slug}-${locale}-web.mp4`)
|
|
284
|
+
run('ffmpeg', webArgs(videos.landscape, web))
|
|
285
|
+
log(`built ${p.rel(web)} (${webNote(statSync(web).size)})`)
|
|
286
|
+
built.push(web)
|
|
287
|
+
}
|
|
288
|
+
for (const step of posterSteps({ render, out, slug, locale, built: videos, last: plan.rows.at(-1), exists: existsSync })) {
|
|
289
|
+
if (step.copy) copyFileSync(...step.copy)
|
|
290
|
+
else run('ffmpeg', step.ffmpeg)
|
|
291
|
+
log(` ${p.rel((step.copy ?? step.ffmpeg).at(-1))}`)
|
|
292
|
+
}
|
|
293
|
+
log(`captions: ${p.rel(out)}/${slug}-${locale}.vtt/.srt; chapters.txt, description.txt`)
|
|
294
|
+
return { built, duration: plan.total, plan }
|
|
295
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The words that go up with a YouTube film: chapters YouTube accepts, the description, and how an update merges
|
|
2
|
+
// ours with what is already on the video.
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { filmFiles, storyUrl } from './stories.js'
|
|
6
|
+
import { exists, load, runningTime } from './util.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* [[at, name]] for the description: first at 0:00, every chapter at least 10 s (YouTube shows none unless all its
|
|
10
|
+
* rules hold). Short scenes fold into the chapter they start; a short tail joins the last chapter.
|
|
11
|
+
*/
|
|
12
|
+
export function chapters(plan) {
|
|
13
|
+
const groups = []
|
|
14
|
+
let cur = [], start = 0
|
|
15
|
+
for (const s of plan) {
|
|
16
|
+
cur.push(s)
|
|
17
|
+
if (s.at + s.dur - start >= 10 - 1e-6) {
|
|
18
|
+
groups.push([start, cur])
|
|
19
|
+
cur = []
|
|
20
|
+
start = s.at + s.dur
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (cur.length) groups.length ? groups.at(-1)[1].push(...cur) : groups.push([start, cur])
|
|
24
|
+
return groups.map(([at, ss]) => [at, ss.map((s) => s.name).join(' + ')])
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Each scene's start and running time in one locale (design time, holds, and timing.<locale>.json). */
|
|
28
|
+
export function scenePlan(p, slug, locale) {
|
|
29
|
+
const d = join(p.films, slug), film = load(join(d, 'film.json'))
|
|
30
|
+
const tp = join(d, `timing.${locale}.json`), tm = exists(tp) ? (load(tp).scenes ?? {}) : {}
|
|
31
|
+
let at = 0
|
|
32
|
+
return film.scenes.map((s) => {
|
|
33
|
+
const dur = runningTime(s, tm[s.id])
|
|
34
|
+
const row = { id: s.id, name: s.name ?? s.id, at, dur }
|
|
35
|
+
at += dur
|
|
36
|
+
return row
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The description to publish: the built out/description.txt, else title + chapters + the story's link. */
|
|
41
|
+
export function youtubeDescription(p, slug, locale, title) {
|
|
42
|
+
const f = filmFiles(p, slug, locale).description
|
|
43
|
+
if (f) return readFileSync(f, 'utf-8')
|
|
44
|
+
const lines = chapters(scenePlan(p, slug, locale)).map(([at, n]) => `${Math.floor(at / 60)}:${String(Math.floor(at % 60)).padStart(2, '0')} ${n}\n`).join('')
|
|
45
|
+
return `${title}\n\n${lines}\n${storyUrl(p, slug, locale)}\n`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** prepend: ours first, then what was there (minus earlier copies of ours); replace: ours only. */
|
|
49
|
+
export function mergeDescription(remote, local, mode = 'prepend') {
|
|
50
|
+
if (mode === 'replace') return local
|
|
51
|
+
const ours = local.trim()
|
|
52
|
+
let rest = (remote ?? '').trim()
|
|
53
|
+
while (ours && rest.startsWith(ours)) {
|
|
54
|
+
rest = rest.slice(ours.length).trim()
|
|
55
|
+
if (rest.startsWith('---')) rest = rest.slice(3).trim()
|
|
56
|
+
}
|
|
57
|
+
return rest ? `${ours}\n\n---\n\n${rest}\n` : `${ours}\n`
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["measure-the-right-work"]
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Measure the Right Work",
|
|
3
|
+
"look": "Session board: counters, an activity chart, two paired metric cards and metric groups on a dot-grid desk. Washi paper, sumi ink, rationed vermillion for rework, jade for work that landed. The brand mark on the close.",
|
|
4
|
+
"background": "#F3F0E9",
|
|
5
|
+
"dark": {
|
|
6
|
+
"background": "#1E1B18",
|
|
7
|
+
"palette": [
|
|
8
|
+
"#191614",
|
|
9
|
+
"#D8D0C7",
|
|
10
|
+
"#F2ECE4",
|
|
11
|
+
"#E0795C"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"palette": [
|
|
15
|
+
"#F9F6F1",
|
|
16
|
+
"#48413D",
|
|
17
|
+
"#1F1916",
|
|
18
|
+
"#C25237"
|
|
19
|
+
],
|
|
20
|
+
"fonts": {
|
|
21
|
+
"display": {
|
|
22
|
+
"family": "Fraunces",
|
|
23
|
+
"weights": [
|
|
24
|
+
300,
|
|
25
|
+
400
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"sans": {
|
|
29
|
+
"family": "Inter",
|
|
30
|
+
"weights": [
|
|
31
|
+
400,
|
|
32
|
+
600
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"scenes": [
|
|
37
|
+
{
|
|
38
|
+
"id": "hook",
|
|
39
|
+
"name": "More",
|
|
40
|
+
"dur": 6.5,
|
|
41
|
+
"desc": "Tokens, commits and lines count up. Is any of it right?"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "problem",
|
|
45
|
+
"name": "Busy",
|
|
46
|
+
"dur": 8.5,
|
|
47
|
+
"desc": "A bad week looks busier than a good one: fixing things is activity too."
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"id": "pair",
|
|
51
|
+
"name": "The pair",
|
|
52
|
+
"dur": 13,
|
|
53
|
+
"desc": "First-turn resolution and rework share, read together: high resolution with rising rework means work deferred, not done."
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "groups",
|
|
57
|
+
"name": "Grouped",
|
|
58
|
+
"dur": 9,
|
|
59
|
+
"desc": "The dashboard groups metrics by outcome, quality, velocity, usage and cost, and shows velocity next to its quality companion."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"id": "close",
|
|
63
|
+
"name": "Close",
|
|
64
|
+
"dur": 5.5,
|
|
65
|
+
"desc": "End card with the brand mark: measure the right work, not more work."
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#stage { --ground:#F9F6F1; --main:#48413D; --second:#1F1916; --accent:#C25237; color:var(--second); font-family:var(--sans, system-ui, sans-serif) }
|
|
2
|
+
#stage { --jade:#599576; --board:#F3F0E9; --dot:#DCD7CD; --tile:#FCFAF6; --hair:#DCD7CD; --mute:#7F7975; --wire:#B2ADA9; --edge:color-mix(in srgb, var(--second) 14%, transparent); --shade:color-mix(in srgb, var(--second) 7%, transparent); --soft:var(--main) }
|
|
3
|
+
#stage[data-mode="dark"] { --ground:#191614; --main:#D8D0C7; --second:#F2ECE4; --accent:#E0795C; --jade:#6FAE8B; --board:#1E1B18; --dot:#34302B; --tile:#26221F; --hair:#3A3530; --mute:#A0978F; --wire:#5E5751; --shade:rgba(0,0,0,.35) }
|
|
4
|
+
.ground { position:absolute; inset:0; background:var(--board) }
|
|
5
|
+
.art { position:absolute; inset:0; width:100%; height:100%; overflow:visible }
|
|
6
|
+
.cam { position:absolute; inset:0; transform-origin:960px 540px }
|
|
7
|
+
.words { position:absolute; margin:0; display:flex; flex-direction:column; gap:20px } .words > * { margin:0 }
|
|
8
|
+
.line { font-family:var(--display, var(--sans, system-ui, sans-serif)); font-size:84px; line-height:1.08; font-weight:400; letter-spacing:-0.02em }
|
|
9
|
+
.sub { font-size:36px; line-height:1.35; color:var(--soft) }
|
|
10
|
+
.eyebrow { font-size:26px; font-weight:600; letter-spacing:0.16em; text-transform:uppercase; color:var(--accent) }
|
|
11
|
+
.card { position:absolute; background:var(--tile); border:2px solid var(--hair); border-radius:18px }
|
|
12
|
+
.tag { position:absolute; transform:translate(-50%,0); padding:8px 18px; border-radius:999px; font-size:28px; font-weight:600; white-space:nowrap; background:var(--tile); color:var(--second); border:2px solid var(--hair) }
|
|
13
|
+
.tag.hot { background:var(--accent); color:var(--ground); border-color:var(--accent) } .tag.ink { background:var(--main); color:var(--ground); border-color:var(--main) } .tag.ok { background:var(--jade); color:var(--ground); border-color:var(--jade) }
|
|
14
|
+
.checks { position:absolute; display:flex; flex-direction:column; gap:14px }
|
|
15
|
+
.chk { display:flex; align-items:flex-start; gap:18px; padding:16px 22px; background:var(--tile); border:2px solid var(--hair); border-radius:14px; font-size:32px; line-height:1.25; font-weight:500 }
|
|
16
|
+
.chk i { flex:none; width:30px; height:30px; margin-top:3px; border-radius:50%; background:var(--jade); position:relative } .chk i::after { content:''; position:absolute; left:9px; top:5px; width:8px; height:14px; border:solid var(--ground); border-width:0 4px 4px 0; transform:rotate(45deg) }
|
|
17
|
+
.mono { font-family:var(--mono, ui-monospace, monospace) }
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
{
|
|
2
|
+
"components": [
|
|
3
|
+
{
|
|
4
|
+
"type": "board",
|
|
5
|
+
"id": "close-bg"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"type": "group",
|
|
9
|
+
"id": "close-mark",
|
|
10
|
+
"style": "transform-origin:1530px 540px",
|
|
11
|
+
"children": [
|
|
12
|
+
{
|
|
13
|
+
"type": "logo",
|
|
14
|
+
"id": "close-logo",
|
|
15
|
+
"name": "brand",
|
|
16
|
+
"x": 1530,
|
|
17
|
+
"y": 540,
|
|
18
|
+
"size": 400
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"type": "box",
|
|
24
|
+
"id": "close-card",
|
|
25
|
+
"at": "ground",
|
|
26
|
+
"children": [
|
|
27
|
+
{
|
|
28
|
+
"type": "text",
|
|
29
|
+
"id": "close-title",
|
|
30
|
+
"tag": "h1",
|
|
31
|
+
"text": "{{close.title}}",
|
|
32
|
+
"split": true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"type": "raw",
|
|
36
|
+
"id": "close-bar",
|
|
37
|
+
"html": "<div class='close-bar'></div>"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"type": "text",
|
|
41
|
+
"id": "close-sub",
|
|
42
|
+
"cls": "sub",
|
|
43
|
+
"text": "{{close.sub}}"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"tracks": [
|
|
49
|
+
{
|
|
50
|
+
"kind": "effect",
|
|
51
|
+
"effect": "push",
|
|
52
|
+
"target": ".cam",
|
|
53
|
+
"t0": 0,
|
|
54
|
+
"dur": 5,
|
|
55
|
+
"from": 1,
|
|
56
|
+
"to": 1.025
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"kind": "tween",
|
|
60
|
+
"target": ".close-card",
|
|
61
|
+
"prop": "opacity",
|
|
62
|
+
"from": 0,
|
|
63
|
+
"to": 1,
|
|
64
|
+
"t0": -0.2,
|
|
65
|
+
"t1": 0.4,
|
|
66
|
+
"easing": "eo"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"kind": "tween",
|
|
70
|
+
"target": ".close-card",
|
|
71
|
+
"prop": "transform",
|
|
72
|
+
"template": "translateY({v}px)",
|
|
73
|
+
"from": 24,
|
|
74
|
+
"to": 0,
|
|
75
|
+
"t0": -0.2,
|
|
76
|
+
"t1": 0.4,
|
|
77
|
+
"easing": "eo"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"kind": "effect",
|
|
81
|
+
"effect": "words",
|
|
82
|
+
"target": ".close-title",
|
|
83
|
+
"t0": 0
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"kind": "tween",
|
|
87
|
+
"target": ".close-bar",
|
|
88
|
+
"prop": "transform",
|
|
89
|
+
"template": "scaleX({v})",
|
|
90
|
+
"from": 0,
|
|
91
|
+
"to": 1,
|
|
92
|
+
"t0": 0.6,
|
|
93
|
+
"t1": 1.1,
|
|
94
|
+
"easing": "eo",
|
|
95
|
+
"decimals": 3
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"kind": "tween",
|
|
99
|
+
"target": ".close-sub",
|
|
100
|
+
"prop": "opacity",
|
|
101
|
+
"from": 0,
|
|
102
|
+
"to": 1,
|
|
103
|
+
"t0": 0.8,
|
|
104
|
+
"t1": 1.3,
|
|
105
|
+
"easing": "eo"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"kind": "tween",
|
|
109
|
+
"target": ".close-sub",
|
|
110
|
+
"prop": "transform",
|
|
111
|
+
"template": "translateX({v}px)",
|
|
112
|
+
"from": 26,
|
|
113
|
+
"to": 0,
|
|
114
|
+
"t0": 0.8,
|
|
115
|
+
"t1": 1.3,
|
|
116
|
+
"easing": "eo"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"kind": "effect",
|
|
120
|
+
"effect": "settle",
|
|
121
|
+
"target": ".close-mark",
|
|
122
|
+
"t0": 0.3,
|
|
123
|
+
"t1": 1,
|
|
124
|
+
"o": 1.4,
|
|
125
|
+
"scaleFrom": 0.7,
|
|
126
|
+
"scaleTo": 1,
|
|
127
|
+
"breatheAmp": 0.012,
|
|
128
|
+
"breatheFreq": 1.6,
|
|
129
|
+
"rotateFrom": -14,
|
|
130
|
+
"rotateTo": 0,
|
|
131
|
+
"rt0": 0.3,
|
|
132
|
+
"rt1": 1.4,
|
|
133
|
+
"opacityMult": 1.5
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"css": ".close-card { position:absolute; left:110px; top:330px; display:flex; flex-direction:column; gap:26px; max-width:1060px }.close-title { margin:0; font-family:var(--display, serif); font-weight:400; font-size:120px; line-height:1.04; letter-spacing:-0.02em }.close-bar { width:300px; height:3px; border-radius:2px; background:var(--accent); transform-origin:0 50% } .close-card .sub { font-size:42px }",
|
|
137
|
+
"portrait": {
|
|
138
|
+
"hoist": [
|
|
139
|
+
".close-card"
|
|
140
|
+
],
|
|
141
|
+
"frame": [
|
|
142
|
+
700,
|
|
143
|
+
920
|
|
144
|
+
],
|
|
145
|
+
"crop": [
|
|
146
|
+
1250,
|
|
147
|
+
260,
|
|
148
|
+
560,
|
|
149
|
+
560
|
|
150
|
+
],
|
|
151
|
+
"css": ".close-card{left:70px!important;top:180px!important;max-width:none!important;width:940px} .close-title{font-size:110px!important}"
|
|
152
|
+
}
|
|
153
|
+
}
|