The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Export: the tray beside the desktop chat; fail on an ffmpeg that ends early; find an ffmpeg that arrives later (#13)
riverisbuilding74fd6d1faa8b
diff --git a/.changeset/export-stuck-encoder.md b/.changeset/export-stuck-encoder.mdnew file mode 100644index 0000000..7d81f46--- /dev/null+++ b/.changeset/export-stuck-encoder.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Export: in the desktop app, the export tray (what an export is doing, how far it has got) sits beside the chat instead of under it; pressing Export seemed to do nothing while the film rendered unseen. An ffmpeg that ends before the last frame (not found, an encoder that fails to start) fails the export with ffmpeg's own error; the export used to stay at "preparing" forever. The export dialog finds an ffmpeg that arrives after Studio started (the desktop app downloads it on a first start); every format used to say this computer's ffmpeg could not make it until Studio restarted.diff --git a/packages/openfilm/src/render.mjs b/packages/openfilm/src/render.mjsindex 20f8653..c3ebb82 100644--- a/packages/openfilm/src/render.mjs+++ b/packages/openfilm/src/render.mjs@@ -135,6 +135,10 @@ async function encode({ film, a, b, file }, { fps, samples, shutter, duration, fencode takes seconds to drain); the parts folder goes with it (see render's finally) */const stop = () => kill(enc.proc);enc.proc.stdin.on('error', () => {});+ /* an ffmpeg that ends before its last frame (not found, an encoder that fails to start) never drains its input:+ the frame being written fails with ffmpeg's own error instead of waiting for it forever */+ const ended = enc.done.then(() => { throw new Error('ffmpeg ended before the last frame'); });+ ended.catch(() => {});signal?.addEventListener('abort', stop, { once: true });try {for (let f = a; f < b; f++) {@@ -145,7 +149,8 @@ async function encode({ film, a, b, file }, { fps, samples, shutter, duration, ffor (let k = 0; k < samples; k++) {const t = (f + (samples > 1 ? (k / samples - 0.5) * shutter : 0)) / fps;await film.seek(Math.min(Math.max(0, t), duration - 1e-4));- await write(enc.proc.stdin, await film.capture(still === 'png' ? { format: 'png' } : { format: 'jpeg', quality: 95 }));+ const frame = await film.capture(still === 'png' ? { format: 'png' } : { format: 'jpeg', quality: 95 });+ await Promise.race([write(enc.proc.stdin, frame), ended]);}onFrame();}diff --git a/packages/openfilm/src/render.test.mjs b/packages/openfilm/src/render.test.mjsnew file mode 100644index 0000000..db4f579--- /dev/null+++ b/packages/openfilm/src/render.test.mjs@@ -0,0 +1,24 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { execFileSync } from 'node:child_process';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { render } from './render.mjs';++const hasFfmpeg = (() => { try { execFileSync('ffmpeg', ['-version'], { stdio: 'ignore' }); return true; } catch { return false; } })();++test('an encoder that fails to start fails the render with ffmpeg\'s error, instead of waiting forever', { skip: !hasFfmpeg && 'no ffmpeg', timeout: 60_000 }, async () => {+ const dir = mkdtempSync(join(tmpdir(), 'of-render-fails-'));+ try {+ /* noise: frames too big for the pipe to take while no one reads it */+ writeFileSync(join(dir, 'index.html'), '<!doctype html><body style="margin:0"><canvas width="1280" height="720"></canvas><script>'+ + 'const c = document.querySelector("canvas").getContext("2d"), img = c.createImageData(1280, 720);'+ + 'window.film = { duration: 1, width: 1280, height: 720, frame(t) { let s = 1 + Math.round(t * 30);'+ + 'for (let i = 0; i < img.data.length; i++) { s = (s * 1103515245 + 12345) % 2147483648; img.data[i] = i % 4 === 3 ? 255 : s & 255; }'+ + 'c.putImageData(img, 0, 0); } };</script>');+ await assert.rejects(render([dir], { out: join(dir, 'out.mp4'), workers: 1, format: { video: ['-c:v', 'no_such_encoder'] } }), /^Error: ffmpeg: .*no_such_encoder/);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+});diff --git a/packages/openfilm/studio/server/export-capabilities.test.mjs b/packages/openfilm/studio/server/export-capabilities.test.mjsnew file mode 100644index 0000000..aeaf206--- /dev/null+++ b/packages/openfilm/studio/server/export-capabilities.test.mjs@@ -0,0 +1,23 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { execFileSync } from 'node:child_process';+import { mkdtempSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { exportCapabilities } from './exports.mjs';++/* a file of its own: what this machine encodes is kept for the whole process once ffmpeg answers */+const hasFfmpeg = (() => { try { execFileSync('ffmpeg', ['-version'], { stdio: 'ignore' }); return true; } catch { return false; } })();++test('an ffmpeg that arrives after Studio started is found: having none is not remembered', { skip: !hasFfmpeg && 'no ffmpeg' }, async () => {+ const path = process.env.PATH;+ const empty = mkdtempSync(join(tmpdir(), 'of-no-ffmpeg-'));+ try {+ process.env.PATH = empty;+ assert.ok(!Object.values(await exportCapabilities()).some(Boolean), 'nothing without ffmpeg');+ } finally {+ process.env.PATH = path;+ rmSync(empty, { recursive: true, force: true });+ }+ assert.ok(Object.values(await exportCapabilities()).some(Boolean), 'the encoders of the ffmpeg now on the PATH');+});diff --git a/packages/openfilm/studio/server/exports.mjs b/packages/openfilm/studio/server/exports.mjsindex c0f06ec..7abfb38 100644--- a/packages/openfilm/studio/server/exports.mjs+++ b/packages/openfilm/studio/server/exports.mjs@@ -113,10 +113,14 @@ export class ExportError extends Error {/** @type {Promise<Set<string>> | null} */let encoderList = null;-/** The encoders this machine's ffmpeg has (none when there is no ffmpeg). */+/**+ * The encoders this machine's ffmpeg has (none when there is no ffmpeg). No ffmpeg is asked about again next time:+ * the desktop app downloads it while Studio is already running.+ */function encoders() {encoderList ??= new Promise((done) => {execFile('ffmpeg', ['-hide_banner', '-encoders'], { maxBuffer: 8 << 20, windowsHide: true }, (error, stdout) => {+ if (error) encoderList = null;done(new Set(error ? [] : [...String(stdout).matchAll(/^ [VAS][.A-Z]{5} (\S+)/gm)].map((m) => m[1])));});});diff --git a/packages/openfilm/studio/ui/src/components/ProjectView.tsx b/packages/openfilm/studio/ui/src/components/ProjectView.tsxindex 079ba28..4fbf231 100644--- a/packages/openfilm/studio/ui/src/components/ProjectView.tsx+++ b/packages/openfilm/studio/ui/src/components/ProjectView.tsx@@ -2457,7 +2457,7 @@ export function ProjectView({ projectId, onProject, onLeave }: {onQueued={(jobs) => exportTrayRef.current?.push(jobs)}projectFps={projectFps}/>- <ExportTray ref={exportTrayRef} projectId={projectId} onError={toast.showError} />+ <ExportTray ref={exportTrayRef} projectId={projectId} onError={toast.showError} inset={hostPanel?.open ? hostPanel.width : 0} /><SpendAsks projectId={projectId} /><Toast toast={toast.current} /></div>diff --git a/packages/openfilm/studio/ui/src/components/export/ExportTray.tsx b/packages/openfilm/studio/ui/src/components/export/ExportTray.tsxindex f04739c..9d82191 100644--- a/packages/openfilm/studio/ui/src/components/export/ExportTray.tsx+++ b/packages/openfilm/studio/ui/src/components/export/ExportTray.tsx@@ -38,8 +38,11 @@ export interface ExportTrayHandle {const recent = (job: ExportJob, now: number) => jobIsActive(job)|| (job.finishedAt != null && now - job.finishedAt < (job.status === 'failed' ? FAILED_KEPT_MS : DONE_KEPT_MS));-/** `onError`: a finished export that could not be opened or shown (its file moved or deleted since), in a sentence. */-export const ExportTray = React.forwardRef<ExportTrayHandle, { projectId: string; onError?: (message: string) => void }>(function ExportTray({ projectId, onError }, ref) {+/**+ * `onError`: a finished export that could not be opened or shown (its file moved or deleted since), in a sentence.+ * `inset`: how much of the window's right side the app's own panel takes (its chat): the tray stays beside it, not under it.+ */+export const ExportTray = React.forwardRef<ExportTrayHandle, { projectId: string; onError?: (message: string) => void; inset?: number }>(function ExportTray({ projectId, onError, inset = 0 }, ref) {const t = useT();const fileAction = (run: Promise<void>) => { void run.catch(() => onError?.(t('exportTray.fileGone'))); };const [jobs, setJobs] = React.useState<ExportJob[]>([]);@@ -137,7 +140,8 @@ export const ExportTray = React.forwardRef<ExportTrayHandle, { projectId: string<divonMouseEnter={() => setHovered(true)}onMouseLeave={() => setHovered(false)}- className="pointer-events-auto fixed bottom-4 right-4 z-[120] w-[340px] overflow-hidden rounded-2xl border border-[var(--border)] bg-[var(--surface)] shadow-[var(--shadow-lg)]"+ style={{ right: 16 + inset }}+ className="pointer-events-auto fixed bottom-4 z-[120] w-[340px] overflow-hidden rounded-2xl border border-[var(--border)] bg-[var(--surface)] shadow-[var(--shadow-lg)]"><div className="flex items-center gap-2 border-b border-[var(--border-soft)] px-3.5 py-2.5">{!ended ? <Loader2 size={14} className="shrink-0 animate-spin text-[var(--text-muted)]" />