The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Studio: an export can be named where it is asked for (#98)
最爱双皮奶f771d053d31e
diff --git a/.changeset/export-file-name.md b/.changeset/export-file-name.mdnew file mode 100644index 0000000..b791976--- /dev/null+++ b/.changeset/export-file-name.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Studio: an export can be named where it is asked for — a name field beside the folder it goes to, the project's name in it to begin with — instead of every file taking the project's name. A named export keeps the suffixes that tell the files of one export apart (` · 哔哩哔哩`, `(alpha)`, `stills`) and drops the ones that only describe the project (`1080p`, `0-9s`). A name left empty is the project's, as before, and an export that would take a name already there still gets ` 2` rather than being written over.diff --git a/packages/openfilm/studio/server/exports.mjs b/packages/openfilm/studio/server/exports.mjsindex e6cf4e9..c7a87f8 100644--- a/packages/openfilm/studio/server/exports.mjs+++ b/packages/openfilm/studio/server/exports.mjs@@ -44,10 +44,11 @@* the project itself, to hand on or keep (see projectFiles): its work always, the parts asked besides; a zip* holding the project's folder, or the folder itself, opened as a project like any other*- * Any of them but the project also takes `range: [from, to]` (seconds; not stills, posters, slides or nle) and `label` (how the- * person's list names it); those with a picture (not one clip alone) take `burnSubtitles: true`, the subtitles drawn- * into the picture as the editor shows them (captions.mjs: the cues and the person's style). `folder`: an absolute- * path (or ~/…) to write to instead of the exports folder.+ * Any of them but the project also takes `range: [from, to]` (seconds; not stills, posters, slides or nle) and `label`+ * (how the person's list names it); any of them takes `name` (what the file is called; the project's own when there is+ * none); those with a picture (not one clip alone) take `burnSubtitles: true`, the subtitles drawn into the picture as+ * the editor shows them (captions.mjs: the cues and the person's style). `folder`: an absolute path (or ~/…) to write+ * to instead of the exports folder.*/import { execFile, fork, spawn } from 'node:child_process';import { randomBytes } from 'node:crypto';@@ -94,7 +95,7 @@ export { exportsRoot };* @typedef {{ kind: 'project', parts?: ProjectPart[], as?: 'zip' | 'folder' }} ProjectAsk* @typedef {typeof PROJECT_PARTS[number]} ProjectPart* @typedef {VideoAsk | GifAsk | AudioAsk | StillsAsk | PosterAsk | SubtitlesAsk | SlidesAsk | NleAsk | ProjectAsk} ExportSpec- * @typedef {ExportSpec & { range?: [number, number], label?: string }} ExportAsk+ * @typedef {ExportSpec & { range?: [number, number], label?: string, name?: string }} ExportAsk* @typedef {import('./film-subtitle.mjs').FilmSubtitleCue} Cue* @typedef {import('./film-subtitle.mjs').FilmSubtitleStyle} SubtitleStyle* @typedef {'preparing' | 'audio' | 'rendering' | 'encoding' | 'copying' | 'finishing'} ExportPhase@@ -219,14 +220,18 @@ const SOUND_CODECS = /** @type {Record<string, string[]>} */ ({ wav: ['-c:a', 'p/** What a file of this ask is called, before its extension. @param {string} project @param {ExportAsk} ask */function baseName(project, ask) {- const base = safeName(project);- const range = ask.range ? ` ${ask.range[0]}-${ask.range[1]}s` : '';+ /* a name typed at export time wins over the project's: a named file keeps the suffixes that tell the files of one+ export apart (a platform, alpha, stills) and loses the ones that only describe the project (a size, a range) */+ const named = typeof ask.name === 'string' && ask.name.trim() ? safeName(ask.name) : null;+ const base = named ?? safeName(project);+ const range = !named && ask.range ? ` ${ask.range[0]}-${ask.range[1]}s` : '';switch (ask.kind) {case 'video': {if (ask.preset) return `${base} · ${safeName(ask.preset)}${range}`;const alpha = ALPHA_CODECS.has(ask.codec ?? 'h264');if (ask.clip) return `${base} · ${safeName(ask.clip)}${alpha ? ' (alpha)' : ''}`;if (alpha) return `${base} (alpha)${range}`;+ if (named) return base;const frame = ask.frame && ask.frame !== 'native' ? ` ${ask.frame.replace(':', 'x')}` : '';return `${base}${frame}${ask.shortEdge ? ` ${ask.shortEdge}p` : ''}${range}`;}@@ -252,6 +257,7 @@ function checked(/** @type {ExportAsk} */ ask) {throw new ExportError('a range is [from, to] in seconds, to after from');}if (ask.label !== undefined && (typeof ask.label !== 'string' || ask.label.length > 120)) throw new ExportError('label: text, at most 120 characters');+ if (ask.name !== undefined && (typeof ask.name !== 'string' || ask.name.length > 120)) throw new ExportError('name: text, at most 120 characters');if ('frame' in ask && ask.frame !== undefined && ask.frame !== 'native' && frameRatio(ask.frame) == null) throw new ExportError('frame: native, or a ratio W:H from 1:4 to 4:1 (16:9, 2.39:1)');if ('fill' in ask && ask.fill !== undefined && ask.fill !== 'contain' && ask.fill !== 'cover') throw new ExportError('fill: contain or cover');if ('shortEdge' in ask && !between(ask.shortEdge, 64, MAX_DIM)) throw new ExportError(`shortEdge: 64 to ${MAX_DIM} pixels`);@@ -1227,13 +1233,13 @@ export function createExports({ onChange = () => {}, captions = subtitlesForExpo}/**- * The project itself (see projectFiles): a zip holding its folder, or the folder, under the project's name. Copied- * a piece at a time, so its footage can be any size; a link to a file is copied as the file.+ * The project itself (see projectFiles): a zip holding its folder, or the folder, under the name asked for or else+ * the project's. Copied a piece at a time, so its footage can be any size; a link to a file is copied as the file.* @param {ExportJob} job @param {string} root @param {string} dir @param {AbortSignal} signal*/async function exportProject(job, root, dir, signal) {const ask = /** @type {ProjectAsk} */ (job.ask);- const title = safeName(job.name);+ const title = baseName(job.name, ask);const files = await projectFiles(root, ask.parts ?? [], resolve(dir));const total = Math.max(1, files.reduce((n, f) => n + f.size, 0));let told = 0;diff --git a/packages/openfilm/studio/server/exports.test.mjs b/packages/openfilm/studio/server/exports.test.mjsindex 6451e80..ff89a08 100644--- a/packages/openfilm/studio/server/exports.test.mjs+++ b/packages/openfilm/studio/server/exports.test.mjs@@ -164,6 +164,22 @@ test('a video export is render: an MP4 named after the project, with progress, nassert.ok(existsSync(join(exportsRoot(), 'Tiny 0-0.5s - mix.m4a')), 'the mix, named so');});+test('an export named where it is asked for: that is the file, and the project is not asked', ffmpeg, async () => {+ const done = await exported({ kind: 'video', fps: 24, name: '预告片' });+ assert.equal(done.out, join(exportsRoot(), '预告片.mp4'));+});++test('a name of nothing but spaces: the project names the file, as before', ffmpeg, async () => {+ const done = await exported({ kind: 'video', fps: 24, name: ' ' }, 'Blank');+ assert.equal(done.out, join(exportsRoot(), 'Blank.mp4'));+});++test('a name is text, at most 120 characters', () => {+ for (const name of [42, 'x'.repeat(121)]) {+ assert.throws(() => createExports().start(project(), { kind: 'subtitles', name }), ExportError, JSON.stringify(name));+ }+});+test('a renderer that dies fails its export with the reason, and exports go on', { ...ffmpeg, skip: ffmpeg.skip || (process.platform === 'win32' && 'no pgrep') }, async () => {const exports = createExports();const job = exports.start(project('Crash'), { kind: 'video' });@@ -926,6 +942,14 @@ test('a project exports as a zip holding its folder, or as the folder, each openassert.throws(() => createExports().start(project('My Film', dir), { kind: 'project', range: [0, 1] }), ExportError);});+test('a project export named where it is asked for: the zip and the folder in it take that name', async () => {+ const dir = fullProject();+ const zipped = await exported({ kind: 'project', name: 'Hand-off' }, 'My Film', dir);+ assert.equal(zipped.out, join(exportsRoot(), 'Hand-off.zip'));+ assert.ok([...zipEntries(zipped.out).keys()].every((n) => n.startsWith('Hand-off/')));+ assert.equal((await exported({ kind: 'project', as: 'folder', name: 'Hand-off' }, 'My Film', dir)).out, join(exportsRoot(), 'Hand-off'));+});+test('the API: where exports go and what can be made here; several at once; open and reveal only what is there', async () => {process.env.OPENFILM_HOME = join(scratch, 'home');process.env.OPENFILM_LIBRARY = join(scratch, 'library');diff --git a/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsx b/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsxindex e69be87..bdfa21a 100644--- a/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsx+++ b/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsx@@ -261,6 +261,10 @@ export function ExportCenter(props: ExportCenterProps) {const [nleSourceFps, setNleSourceFps] = React.useState<number | null>(null);/** The folder being typed after "Change…" (null when not editing). */const [folderDraft, setFolderDraft] = React.useState<string | null>(null);+ /** What the files are called, as typed here: the project's name to begin with, and when left empty. */+ const [exportName, setExportName] = React.useState<string>('');+ /** Whether that name was typed over: only then is it sent, so a dialog left alone exports as it always did. */+ const [nameTyped, setNameTyped] = React.useState(false);React.useEffect(() => {if (!open) return;@@ -272,6 +276,9 @@ export function ExportCenter(props: ExportCenterProps) {setResult(null);setWorking(null);setFolderDraft(null);+ /* a name is this export's, not a setting: each visit starts from the project's own */+ setExportName(props.title);+ setNameTyped(false);setRange((r) => ({ ...r, on: false }));void listExports(props.projectId).then((r) => { setCan(r.can); setDraftApps({ jianying: Boolean(r.drafts?.jianying), capcut: Boolean(r.drafts?.capcut) }); setDefaultFolder(r.folder); setCaptionCount(r.subtitles ?? 0); setProjectSizes(r.project ?? null); }).catch(() => {});// eslint-disable-next-line react-hooks/exhaustive-deps@@ -505,7 +512,11 @@ export function ExportCenter(props: ExportCenterProps) {}setWorking(t('exportCenter.queueing'));try {- const queued = await startExports(props.projectId, jobs, s.folder || undefined);+ /* the name typed here, unless there is none or its field is hidden (a draft is named by its app): every way out+ of this screen comes through here */+ const typed = nameTyped && !toDrafts ? exportName.trim() : '';+ const named = typed ? jobs.map((job) => ({ ...job, name: typed })) : jobs;+ const queued = await startExports(props.projectId, named, s.folder || undefined);props.onQueued?.(queued);onClose();} catch (e) {@@ -1167,6 +1178,24 @@ export function ExportCenter(props: ExportCenterProps) {</span></button>)}+ {/* what the files are called: the project's own name unless typed over (a draft is named by its app) */}+ {!toDrafts && (+ <label className="flex min-w-0 items-center gap-2">+ <span className="shrink-0 text-[11px] text-[var(--text-faint)]">{t('exportCenter.fileName')}</span>+ <input+ value={exportName}+ spellCheck={false}+ placeholder={props.title}+ aria-label={t('exportCenter.fileName')}+ onChange={(e) => { setExportName(e.target.value); setNameTyped(true); }}+ onFocus={(e) => e.currentTarget.select()}+ onKeyDown={(e) => {+ if (e.key === 'Enter' && !e.nativeEvent.isComposing && !disabled) { e.preventDefault(); void queue(requests); }+ }}+ className="h-10 w-[220px] min-w-[140px] rounded-lg border border-[var(--border)] bg-[var(--bg)] px-3 text-[13px] text-[var(--text)] outline-none focus:border-[var(--text-faint)]"+ />+ </label>+ )}<div className="ml-auto flex min-w-0 items-center gap-4"><div className="min-w-0 text-right text-[12px] leading-snug">{result ? (diff --git a/packages/openfilm/studio/ui/src/i18n/en.ts b/packages/openfilm/studio/ui/src/i18n/en.tsindex 721645d..d8c933b 100644--- a/packages/openfilm/studio/ui/src/i18n/en.ts+++ b/packages/openfilm/studio/ui/src/i18n/en.ts@@ -402,6 +402,7 @@ export const en = {rangeFrom: 'From',rangeTo: 'To',saveTo: 'Save to',+ fileName: 'Name',change: 'Change…',pickTitle: 'Choose where to save exports',pickButton: 'Choose',diff --git a/packages/openfilm/studio/ui/src/i18n/es.ts b/packages/openfilm/studio/ui/src/i18n/es.tsindex 61ea501..d06347a 100644--- a/packages/openfilm/studio/ui/src/i18n/es.ts+++ b/packages/openfilm/studio/ui/src/i18n/es.ts@@ -401,6 +401,7 @@ export const es: Words = {rangeFrom: 'Desde',rangeTo: 'Hasta',saveTo: 'Guardar en',+ fileName: 'Nombre',change: 'Cambiar…',pickTitle: 'Elige dónde guardar las exportaciones',pickButton: 'Elegir',diff --git a/packages/openfilm/studio/ui/src/i18n/ja.ts b/packages/openfilm/studio/ui/src/i18n/ja.tsindex e26217a..9bca42d 100644--- a/packages/openfilm/studio/ui/src/i18n/ja.ts+++ b/packages/openfilm/studio/ui/src/i18n/ja.ts@@ -401,6 +401,7 @@ export const ja: Words = {rangeFrom: '開始',rangeTo: '終了',saveTo: '保存先',+ fileName: '名前',change: '変更…',pickTitle: '書き出しの保存先を選択',pickButton: '選択',diff --git a/packages/openfilm/studio/ui/src/i18n/ko.ts b/packages/openfilm/studio/ui/src/i18n/ko.tsindex 7b9e362..5a86947 100644--- a/packages/openfilm/studio/ui/src/i18n/ko.ts+++ b/packages/openfilm/studio/ui/src/i18n/ko.ts@@ -401,6 +401,7 @@ export const ko: Words = {rangeFrom: '시작',rangeTo: '끝',saveTo: '저장 위치',+ fileName: '이름',change: '변경…',pickTitle: '내보내기 저장 위치 선택',pickButton: '선택',diff --git a/packages/openfilm/studio/ui/src/i18n/zh-CN.ts b/packages/openfilm/studio/ui/src/i18n/zh-CN.tsindex 41bd116..2ef3269 100644--- a/packages/openfilm/studio/ui/src/i18n/zh-CN.ts+++ b/packages/openfilm/studio/ui/src/i18n/zh-CN.ts@@ -402,6 +402,7 @@ export const zhCN: Words = {rangeFrom: '起点',rangeTo: '终点',saveTo: '保存到',+ fileName: '名称',change: '更改…',pickTitle: '选择导出的保存位置',pickButton: '选择',diff --git a/packages/openfilm/studio/ui/src/lib/export-jobs.ts b/packages/openfilm/studio/ui/src/lib/export-jobs.tsindex 644b830..a78afbf 100644--- a/packages/openfilm/studio/ui/src/lib/export-jobs.ts+++ b/packages/openfilm/studio/ui/src/lib/export-jobs.ts@@ -8,8 +8,9 @@ import type { ExportQuality, ExportVideoCodec } from '@/lib/export-spec';/** `burnSubtitles`: the film's subtitles drawn into the picture, as the editor shows them. */type Framing = { frame?: FilmFrameId; fill?: FilmFrameFill; burnSubtitles?: boolean };-/** One export, as the server takes it. `range` is [from, to] in seconds. */-export type ExportRequest = { range?: [number, number]; label?: string } & (+/** One export, as the server takes it. `range` is [from, to] in seconds; `name` is what its files are called (the+ * project's name when there is none). */+export type ExportRequest = { range?: [number, number]; label?: string; name?: string } & (| (Framing & { kind: 'video'; codec: ExportVideoCodec; shortEdge?: number; fps: number; quality: ExportQuality; audio: boolean;clip?: string; scale?: number; preset?: string; sidecar?: 'srt' | 'vtt' })| (Framing & { kind: 'gif'; width: number; fps: number })