Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor([vo-mux-preserve-clip-audio-under-ducked-vo]): extract shared runFfprobe helper
[._.]/ Adam Eivy2aa844edd30a
diff --git a/server/lib/ffmpeg.js b/server/lib/ffmpeg.jsindex a56d247e2c..13ec2e3899 100644--- a/server/lib/ffmpeg.js+++ b/server/lib/ffmpeg.js@@ -141,6 +141,18 @@ export const findFfprobe = async () => {return cachedFfprobePath;};+// Run ffprobe with the given args and return its trimmed stdout, or '' when+// ffprobe is unavailable or the call fails. Collapses the shared discover →+// spawn → catch-default → trim boilerplate behind the three ffprobe-based+// probes below (duration, frame count, audio-stream presence) so they can't+// drift on the env/timeout/error-handling contract.+const runFfprobe = async (args, timeout = 5000) => {+ const ffprobe = await findFfprobe();+ if (!ffprobe) return '';+ const { stdout } = await execFileAsync(ffprobe, args, { env: safeChildProcessEnv(), timeout }).catch(() => ({ stdout: '' }));+ return (stdout || '').trim();+};+// Probe whether a media file carries at least one audio stream. Referencing// `[0:a]` in a filter_complex graph against a silent video (AI-gen clips are// silent today) aborts the whole ffmpeg run, so callers that want to preserve@@ -150,17 +162,14 @@ export const findFfprobe = async () => {// can't build.export const hasAudioStream = async (videoPath) => {if (typeof videoPath !== 'string' || !videoPath) return false;- const ffprobe = await findFfprobe();- if (!ffprobe) return false;- const args = [+ const stdout = await runFfprobe(['-v', 'error','-select_streams', 'a','-show_entries', 'stream=index','-of', 'default=nokey=1:noprint_wrappers=1',videoPath,- ];- const { stdout } = await execFileAsync(ffprobe, args, { env: safeChildProcessEnv(), timeout: 5000 }).catch(() => ({ stdout: '' }));- return (stdout || '').trim().length > 0;+ ]);+ return stdout.length > 0;};// Single-video thumbnail extraction. Seeks to mid-clip rather than frame 0@@ -179,16 +188,13 @@ export const hasAudioStream = async (videoPath) => {// callers should treat null as "no thumbnail" rather than aborting the// parent operation.const probeDurationSeconds = async (videoPath) => {- const ffprobe = await findFfprobe();- if (!ffprobe) return null;- const args = [+ const stdout = await runFfprobe(['-v', 'error','-show_entries', 'format=duration','-of', 'default=nokey=1:noprint_wrappers=1',videoPath,- ];- const { stdout } = await execFileAsync(ffprobe, args, { env: safeChildProcessEnv(), timeout: 5000 }).catch(() => ({ stdout: '' }));- const n = parseFloat((stdout || '').trim());+ ]);+ const n = parseFloat(stdout);return Number.isFinite(n) && n > 0 ? n : null;};@@ -221,19 +227,16 @@ export const generateThumbnail = async (videoPath, jobId) => {// nb_frames in their header. Returns null when both paths fail or the// reported count is unusable.const probeFrameCount = async (videoPath) => {- const ffprobe = await findFfprobe();- if (!ffprobe) return null;const run = async (countFrames) => {- const args = [+ const stdout = await runFfprobe(['-v', 'error',...(countFrames ? ['-count_frames'] : []),'-select_streams', 'v:0','-show_entries', `stream=${countFrames ? 'nb_read_frames' : 'nb_frames'}`,'-of', 'default=nokey=1:noprint_wrappers=1',videoPath,- ];- const { stdout } = await execFileAsync(ffprobe, args, { env: safeChildProcessEnv(), timeout: 15000 }).catch(() => ({ stdout: '' }));- const n = parseInt((stdout || '').trim(), 10);+ ], 15000);+ const n = parseInt(stdout, 10);return Number.isFinite(n) && n > 0 ? n : null;};return (await run(false)) ?? (await run(true));