Skip to content

Agent Skill for 15–90 s motion graphics, promo and character videos: reference analysis, seven stage gates, Remotion and HyperFrames engines.

fix(timeline): review fixes (#8)

Unclejobscdac7e1f39bd
diff --git a/skills/motion-video-production/timeline/build.mjs b/skills/motion-video-production/timeline/build.mjs
index 90b2ba4..3048437 100644
--- a/skills/motion-video-production/timeline/build.mjs
+++ b/skills/motion-video-production/timeline/build.mjs
@@ -46,30 +46,28 @@ cuts.forEach((c, i) => {
});
graph.push(`${cuts.map((_, i) => `[v${i}]`).join('')}concat=n=${cuts.length}:v=1:a=0[vout]`);
-const voices = [], music = [];
+const voices = [], music = [], steady = []; // music = ducks under voice, steady = music with duck: false
doc.audio.forEach((a, k) => {
const i = cuts.length + k, ms = Math.round(a.t * 1000);
inputs.push('-ss', String(a.in), '-t', String(a.d), '-i', abs(a.file));
const fades = [a.fadeIn > 0 && `afade=t=in:d=${a.fadeIn}`, a.fadeOut > 0 && `afade=t=out:st=${Math.max(0, a.d - a.fadeOut)}:d=${a.fadeOut}`].filter(Boolean);
graph.push(`[${i}:a]aformat=sample_rates=48000:channel_layouts=stereo,volume=${a.gain}dB${fades.map((f) => `,${f}`).join('')},adelay=${ms}:all=1[a${k}]`);
- (a.kind === 'voice' ? voices : music).push({ label: `a${k}`, duck: a.duck !== false });
+ (a.kind === 'voice' ? voices : a.duck === false ? steady : music).push(`a${k}`);
});
-const mix = (list, out) => graph.push(list.length === 1 ? `[${list[0].label}]anull[${out}]` : `${list.map((x) => `[${x.label}]`).join('')}amix=inputs=${list.length}:normalize=0[${out}]`);
-let audio;
-if (!voices.length && !music.length) {
- graph.push(`anullsrc=r=48000:cl=stereo,atrim=duration=${total}[aout]`);
- audio = 'aout';
-} else {
+const mix = (list, out) => graph.push(list.length === 1 ? `[${list[0]}]anull[${out}]` : `${list.map((x) => `[${x}]`).join('')}amix=inputs=${list.length}:normalize=0[${out}]`);
+let audio = 'aout';
+if (!doc.audio.length) graph.push(`anullsrc=r=48000:cl=stereo,atrim=duration=${total}[aout]`);
+else {
const parts = [];
if (voices.length) mix(voices, 'vo');
if (music.length) mix(music, 'mu');
- if (voices.length && music.length && music.some((m) => m.duck)) {
+ if (steady.length) { mix(steady, 'st'); parts.push('st'); }
+ if (voices.length && music.length) {
// same ducking as scripts/mix-mux.sh: the voice keys a compressor on the music
graph.push('[vo]asplit=2[vo1][key]', '[mu][key]sidechaincompress=threshold=0.03:ratio=5:attack=15:release=250:makeup=1[mud]');
parts.push('vo1', 'mud');
} else parts.push(...(voices.length ? ['vo'] : []), ...(music.length ? ['mu'] : []));
graph.push(`${parts.map((x) => `[${x}]`).join('')}amix=inputs=${parts.length}:normalize=0,apad,atrim=duration=${total},loudnorm=I=-14:TP=-1.5:LRA=9,aresample=48000[aout]`);
- audio = 'aout';
}
mkdirSync(join(p.root, 'out'), { recursive: true });
diff --git a/skills/motion-video-production/timeline/core.mjs b/skills/motion-video-production/timeline/core.mjs
index 2512165..8c1969e 100644
--- a/skills/motion-video-production/timeline/core.mjs
+++ b/skills/motion-video-production/timeline/core.mjs
@@ -26,16 +26,7 @@ export function normalize(raw) {
const doc = clone(raw) || {};
doc.fps ??= 30;
for (const track of TRACKS) doc[track] = Array.isArray(doc[track]) ? doc[track] : [];
- for (const track of TRACKS) {
- const used = new Set(doc[track].map((x) => x.id).filter(Boolean));
- let n = 1;
- for (const x of doc[track]) {
- if (x.id) continue;
- while (used.has(PREFIX[track] + n)) n++;
- x.id = PREFIX[track] + n;
- used.add(x.id);
- }
- }
+ for (const track of TRACKS) for (const x of doc[track]) x.id ||= freshId(doc, track);
for (const a of doc.audio) {
a.kind ??= 'music';
a.in ??= 0;
@@ -122,10 +113,9 @@ export function validate(doc, media = {}) {
return out;
}
-/** Nearest beat (or frame when beats are off) to t. */
-export function snap(doc, t, { beats = true } = {}) {
- const step = beats ? beat(doc) : frame(doc);
- return round(Math.max(0, Math.round(t / step) * step));
+/** Nearest beat to t. */
+export function snap(doc, t) {
+ return round(Math.max(0, Math.round(t / beat(doc)) * beat(doc)));
}
/**
diff --git a/skills/motion-video-production/timeline/core.test.mjs b/skills/motion-video-production/timeline/core.test.mjs
index cc567b6..fd6ad8a 100644
--- a/skills/motion-video-production/timeline/core.test.mjs
+++ b/skills/motion-video-production/timeline/core.test.mjs
@@ -73,7 +73,6 @@ test('roll edit stops where the right cut would run out of source', () => {
test('snap goes to the nearest beat', () => {
assert.equal(snap(base(), 1.26), 1.5);
- assert.equal(snap(base(), 1.26, { beats: false }), 1.2667);
});
test('serialize keeps the gate fields first and drops empty tracks', () => {
diff --git a/skills/motion-video-production/timeline/editor.html b/skills/motion-video-production/timeline/editor.html
index a2eb388..e3003ef 100644
--- a/skills/motion-video-production/timeline/editor.html
+++ b/skills/motion-video-production/timeline/editor.html
@@ -378,10 +378,14 @@ function renderInspector() {
}));
}
function bind(id, patch, ev = 'change') {
- $(id)[`on${ev}`] = (e) => commit([{ op: 'update', track: track(S.sel.kind), id: S.sel.id, patch: patch(e.target.value) }], { label: id.slice(2) });
+ $(id)[`on${ev}`] = (e) => {
+ const x = find(S.sel), change = patch(e.target.value);
+ if (Object.entries(change).every(([k, v]) => (v ?? undefined) === x[k])) return; // a blur repeats the last change
+ commit([{ op: 'update', track: track(S.sel.kind), id: S.sel.id, patch: change }], { label: id.slice(2) });
+ };
}
function addText() {
- const t = S.snapOn !== false ? snapTo(S.doc, S.t) : S.t;
+ const t = $('snap').checked ? snapTo(S.doc, S.t) : S.t;
const id = freshId(S.doc, 'text');
commit([{ op: 'create', track: 'text', item: { id, t, d: beat(S.doc) * 4, text: '' } }], { label: 'new text' }).then(() => {
S.sel = { kind: 'text', id }; render(); $('f-text')?.focus();
@@ -448,7 +452,7 @@ lanes.addEventListener('pointerup', () => {
const D = S.drag; S.drag = null; showSnap(0, false);
if (!D) return;
if (D.mode === 'roll' && D.t != null) return commit(rollOps(S.doc, D.id, D.t), { label: 'cut point' });
- if (D.mode === 'select' || !D.moved || !D.patch) { const x = find({ kind: D.kind, id: D.id }); if (x && !D.moved) seek(Math.max(S.t, 0)); return; }
+ if (D.mode === 'select' || !D.moved || !D.patch) return;
const changed = Object.fromEntries(Object.entries(D.patch).filter(([k, v]) => Math.abs(v - D.orig[k]) > 1e-4));
if (Object.keys(changed).length) commit([{ op: 'update', track: track(D.kind), id: D.id, patch: changed }], { label: D.mode === 'move' ? 'move' : 'trim' });
});
@@ -565,7 +569,7 @@ async function run(path, title) {
S.busy = true; $('gate').disabled = $('build').disabled = true;
$('dlgTitle').textContent = `${title} …`; $('dlgBody').textContent = ''; $('dlg').showModal();
try {
- const r = await (await fetch(path, { method: 'POST' })).json();
+ const r = await (await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' })).json();
$('dlgTitle').textContent = `${title} · ${r.code === 0 ? 'exit 0' : `exit ${r.code}`}`;
$('dlgBody').textContent = r.text || '(no output)';
} finally { S.busy = false; $('gate').disabled = $('build').disabled = false; }
diff --git a/skills/motion-video-production/timeline/serve.mjs b/skills/motion-video-production/timeline/serve.mjs
index 6811fa1..fff6d55 100644
--- a/skills/motion-video-production/timeline/serve.mjs
+++ b/skills/motion-video-production/timeline/serve.mjs
@@ -19,6 +19,7 @@ const root = args.find((a) => !a.startsWith('--') && args[args.indexOf(a) - 1] !
if (!root) { console.error('usage: node serve.mjs <project> [--port 4321] [--no-open]'); process.exit(2); }
const port = Number(args[args.indexOf('--port') + 1]) || 4321;
const p = open(root);
+const HOSTS = new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
const cache = join(p.root, 'qa', 'timeline', 'cache');
mkdirSync(cache, { recursive: true });
@@ -36,13 +37,16 @@ function sync() {
const state = () => {
const m = media(p, doc);
- return { name: basename(p.root), revision, doc, media: m, diagnostics: validate(doc, m), hasSkillGate: existsSync(join(SKILL, 'harness', 'gate.py')) };
+ return { name: basename(p.root), revision, doc, media: m, diagnostics: validate(doc, m) };
};
const TYPES = { '.html': 'text/html; charset=utf-8', '.mjs': 'text/javascript', '.js': 'text/javascript', '.json': 'application/json', '.mp4': 'video/mp4', '.mov': 'video/quicktime', '.webm': 'video/webm', '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.m4a': 'audio/mp4', '.png': 'image/png', '.jpg': 'image/jpeg' };
const server = createServer(async (req, res) => {
const url = new URL(req.url, 'http://x');
+ // Only this machine's browser tab: the Host check stops DNS rebinding, and requiring JSON on POST forces a CORS
+ // preflight (which this server never answers), so other websites cannot edit the project or start a build.
+ if (!HOSTS.has(req.headers.host) || (req.method === 'POST' && !String(req.headers['content-type']).startsWith('application/json'))) return send(res, 403);
try {
if (req.method === 'GET' && url.pathname === '/') return file(res, join(HERE, 'editor.html'));
if (url.pathname === '/favicon.ico') return send(res, 204);
@@ -121,9 +125,10 @@ function file(res, abs, range) {
const size = statSync(abs).size;
const type = TYPES[extname(abs).toLowerCase()] || 'application/octet-stream';
const m = range && /bytes=(\d*)-(\d*)/.exec(range);
- if (m) {
- const start = m[1] ? Number(m[1]) : size - Number(m[2]);
+ if (m && (m[1] || m[2])) {
+ const start = m[1] ? Number(m[1]) : Math.max(0, size - Number(m[2]));
const end = m[1] && m[2] ? Math.min(Number(m[2]), size - 1) : size - 1;
+ if (start > end) { res.writeHead(416, { 'Content-Range': `bytes */${size}` }); return res.end(); }
res.writeHead(206, { 'Content-Type': type, 'Content-Range': `bytes ${start}-${end}/${size}`, 'Accept-Ranges': 'bytes', 'Content-Length': end - start + 1, 'Cache-Control': 'no-cache' });
return createReadStream(abs, { start, end }).pipe(res);
}