The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Exports: sound is on each time, a film is silent only once every video said so, a remade file is asked again (#252)
riverisbuilding0ca8c951c344
diff --git a/.changeset/export-sound-unknown.md b/.changeset/export-sound-unknown.mdnew file mode 100644index 0000000..4f5d119--- /dev/null+++ b/.changeset/export-sound-unknown.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Exports keep their sound more reliably. "Include sound" is on each time the export opens: switched off once, it used to stay off, and every later video came out silent without anyone noticing. A film counts as silent only once every video in it has been checked, so the Audio export no longer says a film has no sound while its videos are still being read. A file made again at the same path is checked again for sound, instead of being remembered as silent until Studio restarts.diff --git a/packages/openfilm/src/shared.mjs b/packages/openfilm/src/shared.mjsindex 9ab1575..73097c8 100644--- a/packages/openfilm/src/shared.mjs+++ b/packages/openfilm/src/shared.mjs@@ -220,15 +220,24 @@ export async function filmSound(s, from) {}const audioStreams = new Map();-/** How many channels a file's first sound stream has: 0 without one (a video clip may be silent). */+/**+ * How many channels a file's first sound stream has: 0 without one (a video clip may be silent). Kept by the file's+ * version, so a file made again at the same path (Studio runs for days) is asked again; a file ffprobe could not read+ * is not kept as silent.+ */export function audioChannels(file) {- if (!audioStreams.has(file)) {+ let version = '';+ try { const s = statSync(file); version = `${s.mtimeMs}:${s.size}`; } catch { /* gone: asked as it is */ }+ const key = `${file}\0${version}`;+ if (!audioStreams.has(key)) {const r = spawnSync('ffprobe', ['-v', 'error', '-select_streams', 'a:0', '-show_entries', 'stream=channels', '-of', 'csv=p=0', file], { encoding: 'utf8', windowsHide: true });if (r.error) throw new Error(`ffprobe: ${/** @type {NodeJS.ErrnoException} */ (r.error).code === 'ENOENT' ? 'not found on the PATH (it comes with ffmpeg)' : r.error.message}`);const out = (r.stdout ?? '').trim();- audioStreams.set(file, out ? Number.parseInt(out, 10) || 2 : 0);+ const channels = out ? Number.parseInt(out, 10) || 2 : 0;+ if (r.status !== 0) return channels;+ audioStreams.set(key, channels);}- return audioStreams.get(file);+ return audioStreams.get(key);}/** Whether a file has a sound stream (a video clip may be silent). */diff --git a/packages/openfilm/src/shared.test.mjs b/packages/openfilm/src/shared.test.mjsindex b4919fa..dd90be0 100644--- a/packages/openfilm/src/shared.test.mjs+++ b/packages/openfilm/src/shared.test.mjs@@ -4,7 +4,7 @@ import { copyFileSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSyncimport { tmpdir } from 'node:os';import { join } from 'node:path';import { spawnSync } from 'node:child_process';-import { COMMAND_ROOM, audioClips, checkSound, fadeFilter, ffmpeg, fileOf, mix, mixGraph } from './shared.mjs';+import { COMMAND_ROOM, audioChannels, audioClips, checkSound, fadeFilter, ffmpeg, fileOf, mix, mixGraph } from './shared.mjs';import { addLinkedPlaces } from './media-links.mjs';test('an ffmpeg that does not end is stopped, and says what did not finish', { timeout: 20_000 }, async () => {@@ -200,3 +200,16 @@ test('a mix of hundreds of sounds keeps its command short: its graph goes in a frmSync(dir, { recursive: true, force: true });}});++test('a file made again at the same path is asked again for its sound: one that was silent can have it now', () => {+ const dir = mkdtempSync(join(tmpdir(), 'openfilm-channels-'));+ try {+ const file = join(dir, 'clip.mp4');+ spawnSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'color=c=black:s=64x64:d=1', '-pix_fmt', 'yuv420p', file]);+ assert.equal(audioChannels(file), 0);+ spawnSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'color=c=black:s=64x64:d=1', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=1', '-pix_fmt', 'yuv420p', '-shortest', file]);+ assert.equal(audioChannels(file), 1);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+});diff --git a/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsx b/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsxindex 5fff6d7..a39a5ce 100644--- a/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsx+++ b/packages/openfilm/studio/ui/src/components/export/ExportCenter.tsx@@ -158,9 +158,10 @@ function loadSettings(language: string): Settings {...DEFAULTS,...raw,presets: Array.isArray(raw.presets) ? raw.presets.filter((id) => exportPreset(id)) : DEFAULTS.presets,- video: { ...DEFAULTS.video, ...raw.video },+ /* sound starts on each time: switched off for one export and kept, every later one came out silent unnoticed */+ video: { ...DEFAULTS.video, ...raw.video, audio: true },gif: { ...DEFAULTS.gif, ...raw.gif },- alpha: { ...DEFAULTS.alpha, ...raw.alpha },+ alpha: { ...DEFAULTS.alpha, ...raw.alpha, audio: true },audio: { ...DEFAULTS.audio, ...raw.audio },nle,subtitles: { ...DEFAULTS.subtitles, ...raw.subtitles },@@ -226,6 +227,8 @@ export interface ExportCenterProps {film?: {scenes: readonly { startMs: number; durMs: number; label: string; src?: string }[];sounds: readonly { kind: Exclude<StemKind, 'footage'>; durMs: number; src?: string }[];+ /** Video clips not probed yet: the film is not known to be silent while there are any. */+ unprobed?: number;} | null;/** Where the playhead is: the poster is that frame (the middle of the film without it). */playheadMs?: number;@@ -308,7 +311,8 @@ export function ExportCenter(props: ExportCenterProps) {() => new Set<StemKind>((film?.sounds ?? []).filter((x) => x.durMs > 0).map((x) => (x.src && VIDEO_SRC.test(x.src) ? 'footage' : x.kind))),[film],);- const knownSilent = film != null && soundKinds.size === 0;+ /* silent only when every video's file said it has no sound: one not probed yet (or that failed to be) may have */+ const knownSilent = film != null && soundKinds.size === 0 && !film.unprobed;const blocks = React.useMemo(() => props.mgBlocks ?? [], [props.mgBlocks]);const captions = captionCount ?? 0;diff --git a/packages/openfilm/studio/ui/src/lib/film-shape.test.ts b/packages/openfilm/studio/ui/src/lib/film-shape.test.tsindex 07463c3..7d36df4 100644--- a/packages/openfilm/studio/ui/src/lib/film-shape.test.ts+++ b/packages/openfilm/studio/ui/src/lib/film-shape.test.ts@@ -47,3 +47,13 @@ test('a clip shows from its start up to, not including, its end', () => {assert.equal(spanShows(span, 6100), false);assert.equal(spanShows(span, 5160), true);});++test('a video not probed yet may carry sound: the film is not known to be silent until every one has said', () => {+ const film = doc([{ src: 'assets/a.mp4', id: 'a', time: [0, 2] }, { src: 'assets/b.mp4', id: 'b', at: 2, time: [0, 2] }]);+ const spans: ClipSpan[] = [{ id: 'a', src: 'assets/a.mp4', at: 0, end: 2, native: 9 }, { id: 'b', src: 'assets/b.mp4', at: 2, end: 4, native: 9 }];+ assert.equal(filmShape(film, spans).unprobed, 2);+ assert.equal(filmShape(film, spans, new Map([['assets/a.mp4', { audio: false }]])).unprobed, 1);+ const both = filmShape(film, spans, new Map([['assets/a.mp4', { audio: false }], ['assets/b.mp4', { audio: true }]]));+ assert.equal(both.unprobed, undefined);+ assert.deepEqual(both.sounds.map((x) => x.src), ['assets/b.mp4']);+});diff --git a/packages/openfilm/studio/ui/src/lib/film-shape.ts b/packages/openfilm/studio/ui/src/lib/film-shape.tsindex bc455f3..8077a12 100644--- a/packages/openfilm/studio/ui/src/lib/film-shape.ts+++ b/packages/openfilm/studio/ui/src/lib/film-shape.ts@@ -65,6 +65,8 @@ export function filmShape(const scenes: TimelineFilm['scenes'][number][] = [];const videos: TimelineFilm['videos'][number][] = [];const sounds: TimelineFilm['sounds'][number][] = [];+ /* videos whose file was not probed (yet): whether they carry sound is not known */+ let unprobed = 0;doc.tracks.forEach((track: FilmTrack, ti: number) => {const ref: NonNullable<Track> = {@@ -160,6 +162,7 @@ export function filmShape(});/* the footage's own sound: the timeline draws it on the video block, not as a block of its own (at volume 0too: it is still there, turned down, and the inspector turns it up again) */+ if (!still && !media.has(clip.src)) unprobed++;if (!still && media.get(clip.src)?.audio) {sounds.push({ ...shared, kind: 'voice', src: clip.src, ...(inMs ? { inMs } : {}), ...(speed !== 1 ? { speed } : {}) });}@@ -168,5 +171,5 @@ export function filmShape(});/* the timeline also draws tracks with nothing on them (somewhere to drop), named by their kind */- return { scenes, videos, sounds, captions: [], doc: { ...doc, tracks: doc.tracks.map((t) => ({ ...t, kind: filmTrackKind(t) })) } };+ return { scenes, videos, sounds, captions: [], ...(unprobed ? { unprobed } : {}), doc: { ...doc, tracks: doc.tracks.map((t) => ({ ...t, kind: filmTrackKind(t) })) } };}diff --git a/packages/openfilm/studio/ui/src/lib/timeline-layout.ts b/packages/openfilm/studio/ui/src/lib/timeline-layout.tsindex e6ec745..f8ca2a6 100644--- a/packages/openfilm/studio/ui/src/lib/timeline-layout.ts+++ b/packages/openfilm/studio/ui/src/lib/timeline-layout.ts@@ -511,6 +511,8 @@ export interface TimelineFilm {silent?: boolean;}[];captions: readonly { key: string; startMs: number; durMs: number; text: string; loc?: string }[];+ /** Video clips whose file was not probed (yet): whether they carry sound is not known. */+ unprobed?: number;/*** film.html as on disk. The evaluated lists only hold clips with a length, so an empty track vanishes from them;* the timeline still draws it, as a place to drop onto.