UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

58 lines (57 loc) • 2.61 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { n as runExec } from "./exec-aRIvS9s4.mjs"; import { t as resolveSystemBin } from "./resolve-system-bin-DT18BSuF.mjs"; //#region src/media/ffmpeg-limits.ts /** Shared stdout/stderr buffer cap for ffmpeg and ffprobe child processes. */ const MEDIA_FFMPEG_MAX_BUFFER_BYTES = 10485760; /** Default ffprobe timeout for lightweight metadata probes. */ const MEDIA_FFPROBE_TIMEOUT_MS = 1e4; /** Default ffmpeg timeout for bounded media conversion work. */ const MEDIA_FFMPEG_TIMEOUT_MS = 45e3; /** Maximum audio duration accepted by ffmpeg-backed media flows. */ const MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS = 1200; //#endregion //#region src/media/ffmpeg-exec.ts function resolveExecOptions(e, t) { if (t?.input !== void 0 && t.stdinFileDescriptor !== void 0) throw new Error("media exec accepts either input or stdinFileDescriptor, not both"); return { input: t?.input, ...t?.stdinFileDescriptor !== void 0 ? { stdinFileDescriptor: t.stdinFileDescriptor } : {}, logOutput: false, maxBuffer: t?.maxBufferBytes ?? 10485760, timeoutMs: t?.timeoutMs ?? e }; } function requireSystemBin(e) { const t = resolveSystemBin(e, { trust: "standard" }); if (!t) { const t = process.platform === "darwin" ? "e.g. brew install ffmpeg" : "e.g. apt install ffmpeg / dnf install ffmpeg"; throw new Error(`${e} not found in trusted system directories. Install it via your system package manager (${t}).`); } return t; } /** Resolves ffmpeg from trusted system paths before command execution. */ function resolveFfmpegBin() { return requireSystemBin("ffmpeg"); } /** Runs ffprobe with optional stdin input. */ async function runFfprobe(e, t) { const { stdout: n } = await runExec(requireSystemBin("ffprobe"), e, resolveExecOptions(MEDIA_FFPROBE_TIMEOUT_MS, t)); return n; } /** Runs ffmpeg with bounded timeout and buffer settings. */ async function runFfmpeg(e, t) { const { stdout: n } = await runExec(resolveFfmpegBin(), e, resolveExecOptions(MEDIA_FFMPEG_TIMEOUT_MS, t)); return n; } /** Parses codec and positive sample rate from compact ffprobe stream output. */ function parseFfprobeCodecAndSampleRate(e) { const [t, n] = e.trim().split(/[,\r\n]+/, 2).map((e) => normalizeLowercaseStringOrEmpty(e)); const r = n && /^\d+$/.test(n) ? Number(n) : 0; return { codec: t || null, sampleRateHz: Number.isSafeInteger(r) && r > 0 ? r : null }; } //#endregion export { MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS as a, runFfprobe as i, resolveFfmpegBin as n, runFfmpeg as r, parseFfprobeCodecAndSampleRate as t };