Skip to content

Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.

Composite the captions with the ffmpeg podcli provisioned (#191)

Nika Siradzee7411034d6c4
diff --git a/cli/VERSION b/cli/VERSION
index a616492..f1ffbeb 100644
--- a/cli/VERSION
+++ b/cli/VERSION
@@ -1 +1 @@
-2.7.18
+2.7.19
diff --git a/package-lock.json b/package-lock.json
index 5b6d245..a065ee6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "podcli",
- "version": "2.7.18",
+ "version": "2.7.19",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "podcli",
- "version": "2.7.18",
+ "version": "2.7.19",
"license": "AGPL-3.0-only",
"dependencies": {
"@fontsource/dm-sans": "^5.3.0",
diff --git a/package.json b/package.json
index 4d2141d..65184c8 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "podcli",
- "version": "2.7.18",
+ "version": "2.7.19",
"private": true,
"description": "AI-powered podcast clip generator for TikTok/YouTube Shorts. Transcribe, find viral moments, export vertical clips with burned captions.",
"type": "module",
diff --git a/remotion/render-bookend.mjs b/remotion/render-bookend.mjs
index dd5ed57..0d76530 100644
--- a/remotion/render-bookend.mjs
+++ b/remotion/render-bookend.mjs
@@ -84,7 +84,9 @@ async function main() {
// Add a silent stereo audio track so concat/crossfade with the main clip
// (which has audio) doesn't fail on a missing audio stream.
const mux = spawnSync(
- "ffmpeg",
+ // The provisioned one, for the same reason render.mjs uses it: nothing
+ // guarantees an ffmpeg on PATH beside a hermetic runtime.
+ process.env.PODCLI_FFMPEG || "ffmpeg",
[
"-y",
"-i", silentVideo,
diff --git a/remotion/render.mjs b/remotion/render.mjs
index 17f3aa2..cfb95da 100644
--- a/remotion/render.mjs
+++ b/remotion/render.mjs
@@ -142,23 +142,61 @@ async function main() {
let renderW = 1080;
let renderH = 1920;
let videoDuration = null;
- try {
- const { execSync } = await import("child_process");
- const probe = execSync(
- `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path.resolve(opts.video)}"`,
- { encoding: "utf-8", timeout: 5000 }
- ).trim();
- const [w, h] = probe.split("x").map(Number);
+ /*
+ * The shape the overlay is drawn at, measured rather than assumed.
+ *
+ * PODCLI_FFPROBE for the same reason the composite uses PODCLI_FFMPEG:
+ * nothing guarantees one on PATH beside a hermetic runtime. This used to
+ * swallow the failure whole, which left the defaults below standing: a
+ * horizontal clip then had a 1080x1920 overlay drawn over a 1920x1080
+ * frame, so every caption and the logo came out the wrong size and in the
+ * wrong place, and nothing anywhere said the measurement had not happened.
+ */
+ const { spawnSync } = await import("child_process");
+ const ffprobe = process.env.PODCLI_FFPROBE || "ffprobe";
+ const probeFor = (...entries) => {
+ const r = spawnSync(
+ ffprobe,
+ ["-v", "error", ...entries, path.resolve(opts.video)],
+ { encoding: "utf-8", timeout: 5000 },
+ );
+ if (r.error || r.status !== 0) return null;
+ return String(r.stdout ?? "").trim();
+ };
+
+ const size = probeFor(
+ "-select_streams", "v:0", "-show_entries", "stream=width,height",
+ "-of", "csv=s=x:p=0",
+ );
+ if (size) {
+ const [w, h] = size.split("x").map(Number);
if (w > 0 && h > 0) {
renderW = w;
renderH = h;
}
- const durStr = execSync(
- `ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${path.resolve(opts.video)}"`,
- { encoding: "utf-8", timeout: 5000 }
- ).trim();
- videoDuration = parseFloat(durStr);
- } catch {}
+ } else {
+ // Loud, because the fallback is a guess about the shape of the frame.
+ process.stderr.write(
+ ` could not measure the video with ${ffprobe}; drawing the overlay at `
+ + `${renderW}x${renderH}, which is wrong for anything else\n`,
+ );
+ }
+
+ const durStr = probeFor(
+ "-show_entries", "format=duration",
+ "-of", "default=noprint_wrappers=1:nokey=1",
+ );
+ // Same silence as the shape, and the same cost: an overlay cut to the last
+ // word rather than to the file stops before the clip does.
+ const measured = Number.parseFloat(durStr ?? "");
+ if (Number.isFinite(measured) && measured > 0) {
+ videoDuration = measured;
+ } else {
+ process.stderr.write(
+ ` could not measure the duration with ${ffprobe}; falling back to the `
+ + `last word, so the overlay may end before the clip does\n`,
+ );
+ }
// Calculate duration from video or word timing
const lastWord = words[words.length - 1];
@@ -312,14 +350,37 @@ async function main() {
});
// Composite: overlay transparent captions (ProRes 4444 with alpha) onto video
- const { execSync } = await import("child_process");
+ //
+ // PODCLI_FFMPEG, like every other module here. podcli provisions its own
+ // ffmpeg and nothing guarantees one on PATH: a container that carries the
+ // hermetic runtime and no system ffmpeg got "ffmpeg: not found" at this
+ // one step, which reads as a failed Remotion render. Every clip on such a
+ // box then fell back to burned-in ASS, looking nothing like the preview,
+ // and the only word for it was on a stream nobody was reading.
+ //
+ // Argv rather than a shell string: these are paths from the caller, and
+ // one with a space in it broke the quoting instead of the render.
process.stderr.write(" compositing...\n");
- execSync(
- `ffmpeg -y -hide_banner -loglevel warning -i "${path.resolve(opts.video)}" -i "${captionOverlay}" ` +
- `-filter_complex "[0:v][1:v]overlay=0:0:shortest=1" ` +
- `-c:v libx264 -crf 18 -preset fast -pix_fmt yuv420p -map 0:a -c:a copy "${opts.output}"`,
- { stdio: ["pipe", "pipe", "pipe"], timeout: 300000 }
+ const ffmpeg = process.env.PODCLI_FFMPEG || "ffmpeg";
+ const composite = spawnSync(
+ ffmpeg,
+ [
+ "-y", "-hide_banner", "-loglevel", "warning",
+ "-i", path.resolve(opts.video),
+ "-i", captionOverlay,
+ "-filter_complex", "[0:v][1:v]overlay=0:0:shortest=1",
+ "-c:v", "libx264", "-crf", "18", "-preset", "fast", "-pix_fmt", "yuv420p",
+ "-map", "0:a", "-c:a", "copy",
+ path.resolve(opts.output),
+ ],
+ { stdio: ["pipe", "pipe", "pipe"], timeout: 300000, encoding: "utf8" }
);
+ if (composite.error || composite.status !== 0) {
+ const why = composite.error
+ ? `${composite.error.code === "ENOENT" ? `${ffmpeg} not found` : composite.error.message}`
+ : `exit ${composite.status}: ${(composite.stderr || "").trim().slice(-500)}`;
+ throw new Error(`compositing the captions failed (${why})`);
+ }
if (opts["keep-overlay"]) {
console.log(`PODCLI_OVERLAY_PATH=${captionOverlay}`);