Skip to content

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

Draw footage in the band a card takes, and cut 2.7.22 (#194)

Nika Siradzeaf13030325f8
diff --git a/cli/VERSION b/cli/VERSION
index b92fb48..19f0c15 100644
--- a/cli/VERSION
+++ b/cli/VERSION
@@ -1 +1 @@
-2.7.21
+2.7.22
diff --git a/package.json b/package.json
index 8280485..bf0a491 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "podcli",
- "version": "2.7.21",
+ "version": "2.7.22",
"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/src/cards.ts b/remotion/src/cards.ts
index c91c492..934b684 100644
--- a/remotion/src/cards.ts
+++ b/remotion/src/cards.ts
@@ -96,6 +96,35 @@ export type Card =
*/
fit?: "fit" | "fill";
caption?: string;
+ })
+ /**
+ * Footage in the band under the speaker.
+ *
+ * The split every phone already knows: the person talking above, the thing
+ * they are talking about below. It is the one card that shows rather than
+ * states, which is why it earns the frame where a slide would not.
+ *
+ * Silent, always, and not negotiable. The moment is somebody speaking, and
+ * a second soundtrack under them is what makes a clip unwatchable rather
+ * than merely busy.
+ *
+ * Footage shorter than the card's own window runs out inside it: there is
+ * no looping here, because the only component that can seek frame-perfectly
+ * during a render cannot loop, and a preview that loops where the render
+ * does not is a preview that lies. The window is the agreement.
+ */
+ | (CardBase & {
+ kind: "video";
+ /** A URL the renderer can reach, or a path inside the bundle. */
+ src: string;
+ /**
+ * "fill" crops to the band, which is what footage wants. "fit" shows
+ * the whole frame for a screen recording, where the edges are content.
+ */
+ fit?: "fit" | "fill";
+ /** Where in the file to start, in seconds. */
+ startAt?: number;
+ caption?: string;
});
/**
diff --git a/remotion/src/components/Cards.tsx b/remotion/src/components/Cards.tsx
index ca94716..f9209a5 100644
--- a/remotion/src/components/Cards.tsx
+++ b/remotion/src/components/Cards.tsx
@@ -65,6 +65,47 @@ const track = (fill: string) =>
/** Authored for the 1920-tall canvas, like every other measurement here. */
const TYPE = { label: 34, body: 46, item: 58, quote: 68, lead: 84, figure: 168 };
+/**
+ * How much of the frame a video card's footage takes.
+ *
+ * The arithmetic it has to fit: a 1920 canvas, roughly 470 reserved for the
+ * captions, 76 of gap, and the speaker's own floor of 820 above it. What is
+ * left is this. Asking for the literal half of the frame would push the band
+ * under that floor, and the card would answer by dropping the speaker
+ * altogether — the opposite of what a split screen is for.
+ *
+ * It shrinks before the speaker does, because a caption style with tall words
+ * has to take its room from somewhere and a face cut in half is worse than
+ * footage cropped a little tighter.
+ */
+const VIDEO_BAND = 540;
+
+/**
+ * The least footage worth keeping the speaker for.
+ *
+ * Captions placed high on the frame reserve their band from the same 1920,
+ * and what is left after a speaker can be a few dozen pixels. A letterbox
+ * slit of a factory floor says nothing while still costing the frame it sits
+ * in, so short of this the card takes the whole frame and the footage gets a
+ * size worth looking at. The same call the speaker's own floor makes, made
+ * for the other half.
+ */
+const VIDEO_MIN = 260;
+
+/** What a card's own caption costs whatever is above it. */
+const CAPTION_ROW = TYPE.label * 1.3 + GAP.tight;
+
+/**
+ * How tall the footage is in a body of this height.
+ *
+ * One formula, because two things ask: the card, to decide whether keeping
+ * the speaker still leaves footage worth showing, and the body, to draw it.
+ * Asked twice and answered differently, the card keeps a speaker for a band
+ * it then draws too short to read.
+ */
+const videoBand = (bodyRoom: number, s: number, hasCaption: boolean) =>
+ Math.min(VIDEO_BAND * s, Math.max(0, bodyRoom - (hasCaption ? CAPTION_ROW * s : 0)));
+
/**
* The least of the frame the speaker keeps.
*
@@ -187,9 +228,24 @@ const Endpoint: React.FC<{
</div>
);
-const CardBody: React.FC<{ card: Card; scale: number; brand: Brand }> = ({
- card, scale: s, brand,
+const CardBody: React.FC<{
+ card: Card;
+ scale: number;
+ brand: Brand;
+ /**
+ * The height the body may take, for the one kind that has to be told.
+ *
+ * Every other card is as tall as its own words and the layout absorbs it.
+ * Footage is given a height, and a height that does not fit is a card
+ * drawn over the captions rather than a card that came out short.
+ */
+ room?: number;
+}> = ({
+ card, scale: s, brand, room,
}) => {
+ // Read before any of the branches below, so a card kind that never uses it
+ // does not change the order the hooks run in.
+ const { fps } = useVideoConfig();
const accent = card.accent ?? brand.accent;
const INK = brand.ink;
const MUTED = muted(brand.ink);
@@ -491,6 +547,49 @@ const CardBody: React.FC<{ card: Card; scale: number; brand: Brand }> = ({
);
}
+ if (card.kind === "video") {
+ // The same split as the speaker above it: the player seeks a <video> per
+ // frame, and a render has no seekable player to drive.
+ const Frame = getRemotionEnvironment().isRendering ? OffthreadVideo : Video;
+ return (
+ <>
+ <Frame
+ src={card.src.startsWith("http") ? card.src : staticFile(card.src)}
+ startFrom={Math.max(0, Math.round((card.startAt ?? 0) * fps))}
+ muted
+ style={{
+ width: "100%",
+ height: videoBand(room ?? VIDEO_BAND * s, s, Boolean(card.caption)),
+ // Black rather than the surface tone: letterboxing that matches
+ // the card reads as a card drawn short, where black reads as the
+ // shape of the footage, which is what it is.
+ backgroundColor: "#000",
+ objectFit: card.fit === "fit" ? "contain" : "cover",
+ }}
+ />
+ {card.caption && (
+ <div
+ style={{
+ fontFamily: FONT,
+ fontSize: TYPE.label * s,
+ fontWeight: 400,
+ lineHeight: 1.3,
+ color: MUTED,
+ // Its own inset: the footage above it runs to both edges, and a
+ // caption that did the same would sit against the frame.
+ padding: `0 ${96 * s}px`,
+ marginTop: GAP.tight * s,
+ }}
+ >
+ {card.caption}
+ </div>
+ )}
+ </>
+ );
+ }
+
+ if (card.kind !== "quote") return null;
+
return (
<>
<div
@@ -555,6 +654,17 @@ const SpeakerBand: React.FC<{ src: string; startFrom: number; faceY?: number | n
);
};
+/**
+ * Every kind this build draws.
+ *
+ * Written out rather than derived from the union, because the point is to
+ * answer for a card that arrived from somewhere newer, and a type cannot.
+ */
+const KNOWN_KINDS = new Set([
+ "stat", "headline", "bullets", "compare", "change", "share", "entity", "quote",
+ "image", "video",
+]);
+
export const Cards: React.FC<{
cards: Card[];
videoSrc?: string;
@@ -569,9 +679,20 @@ export const Cards: React.FC<{
const { fps, height } = useVideoConfig();
const s = captionScale(height);
- // A picture whose file went missing is dropped here rather than drawn: the
- // card is opaque, so rendering it anyway would cover the clip with nothing.
- const usable = cards.filter((c) => c.kind !== "image" || Boolean(c.src));
+ /*
+ * Only the cards this build can actually draw.
+ *
+ * A picture or a piece of footage whose file went missing is dropped rather
+ * than drawn: the card is opaque, so rendering it anyway would cover the
+ * clip with nothing. A kind this build has never heard of goes the same
+ * way. An older engine handed a newer plan used to fall through to the
+ * quote branch and draw an empty slab over the speaker, which is the one
+ * failure that looks deliberate.
+ */
+ const usable = cards.filter((c) => (
+ KNOWN_KINDS.has(c.kind)
+ && (c.kind !== "image" && c.kind !== "video" ? true : Boolean(c.src))
+ ));
const card = cardAt(usable, frame / fps);
if (!card) return null;
@@ -593,9 +714,21 @@ export const Cards: React.FC<{
*/
const room = height - (captionZone(style) + GAP.section) * s;
const headNeeds = faceH ? faceH * HEAD_TO_FACE * height : SPEAKER_MIN * s;
+ /*
+ * Footage keeps the speaker only while both still fit.
+ *
+ * The speaker's floor is the first claim on the frame and the captions are
+ * reserved before either, so on a clip whose captions sit high there can be
+ * too little left to draw footage in at all. Rather than overflow the
+ * caption band, the card gives up the speaker and takes the whole frame,
+ * which is what it would have done for a card too tall to share.
+ */
+ const bodyRoom = (available: number) => Math.max(0, available - GAP.section * s);
const withSpeaker = card.speaker !== null
&& Boolean(videoSrc)
- && room >= headNeeds;
+ && room >= headNeeds
+ && (card.kind !== "video"
+ || videoBand(bodyRoom(room - headNeeds), s, Boolean(card.caption)) >= VIDEO_MIN * s);
return (
<div
@@ -619,7 +752,9 @@ export const Cards: React.FC<{
)}
<div
style={{
- padding: `${GAP.section * s}px ${96 * s}px 0`,
+ // Footage runs to both edges. An inset would draw it as a picture
+ // pasted on a card, where the point is a second half of the frame.
+ padding: `${GAP.section * s}px ${(card.kind === "video" ? 0 : 96) * s}px 0`,
display: "flex",
flexDirection: "column",
/*
@@ -635,7 +770,12 @@ export const Cards: React.FC<{
marginBottom: withSpeaker ? undefined : "auto",
}}
>
- <CardBody card={card} scale={s} brand={colours} />
+ <CardBody
+ card={card}
+ scale={s}
+ brand={colours}
+ room={bodyRoom(withSpeaker ? room - headNeeds : room)}
+ />
</div>
</div>
);