{"title":"Rendering Social Carousels As Video With Remotion","html_url":"https://deallocatedobjects.com/posts/rendering-social-carousels-as-video-with-remotion","source_url":"","markdown_content":"Each post on this blog gets a short carousel on Threads and X: four or five slides with the main idea and usually a code sample or a table. They used to be PNGs. Now every slide is a little video where the words come in one at a time, rendered with [Remotion](https://www.remotion.dev) from a TypeScript file per post.\n\nHere's slide 2 from the carousel for [Why du Overcounts On APFS](/posts/why-du-overcounts-on-apfs):\n\n<video src=\"/media/posts/rendering-social-carousels-as-video-with-remotion/du-apfs-slide-02.mp4\" controls playsinline></video>\n\n### One File Per Carousel\n\nA carousel is plain data. There are four kinds of block a slide can hold: a paragraph, a code panel, a three-column table, and a big number that counts from one value to another.\n\n```ts title=\"reels/src/carousel/types.ts\"\nexport type Block =\n  | { type: \"p\"; text: string }\n  | { type: \"code\"; lines: string[]; size?: number }\n  | { type: \"rows\"; rows: [string, string, string][] }\n  | { type: \"count\"; from: number; to: number; unit: string; label: string };\n\nexport type Slide = {\n  tone?: \"blue\" | \"white\";\n  kicker: string;\n  title: string; // on screen from frame 0, so thumbnails aren't blank\n  big?: boolean; // h1 size\n  blocks: Block[];\n};\n```\n\nEach post gets a file in `reels/carousels/` named after its slug. The `folder` is where the finished videos go, and `satisfies Carousel` means a typo in a block type fails before anything renders:\n\n```ts title=\"reels/carousels/why-du-overcounts-on-apfs.ts\"\nexport default {\n  slug: \"why-du-overcounts-on-apfs\",\n  folder: \"2026-11-13-du-apfs\",\n  caption: \"Chrome keeps 14 copies of itself in a temp folder on my Mac, ...\",\n  slides: [\n    { tone: \"blue\", big: true, kicker: \"Deallocated Objects\", title: \"Why du overcounts on APFS\", blocks: [{ type: \"p\", text: \"Clones share their blocks, and du counts every one in full.\" }] },\n    { kicker: \"The test\", title: \"Three clones, 92 KB\", blocks: [\n      { type: \"code\", lines: [\"$ cp -c original.bin copy1.bin\", \"$ cp -c original.bin copy2.bin\", \"$ cp -c original.bin copy3.bin\", \"$ du -sh .\", \"1.0G  .\"], size: 34 },\n      { type: \"p\", text: \"A 256 MB file and three clones moved free space by 92 KB. A plain cp took 257 MB.\" },\n    ] },\n    // ...three more slides\n  ],\n} satisfies Carousel;\n```\n\nBackticks inside paragraph text become little code chips, so I can write \"`gzip_static` follows `gzip_proxied`\" and the slide styles it the way the blog does.\n\n### Timing Comes From The Words\n\nNothing in the carousel file says how long a slide lasts. A `timeline()` function works it out from the content. Paragraphs reveal at 14 words a second, a counter takes 36 frames, and there's a 6-frame gap after each block. Then it estimates how long a person needs to read everything on the slide at 3.6 words a second and holds the slide that long:\n\n```ts title=\"reels/src/carousel/types.ts\"\nexport const FPS = 30;\n\n/** Word reveal 14/s, counters 36 frames; code and tables are on screen from frame 0. */\nexport function timeline(slide: Slide): { blocks: Timed[]; animFrames: number; totalFrames: number } {\n  let t = 8;\n  let readWords = words(slide.title) + words(slide.kicker);\n  const blocks: Timed[] = slide.blocks.map((b) => {\n    const start = t;\n    let frames = 0;\n    let w = 0;\n    if (b.type === \"p\") { w = words(b.text); frames = Math.ceil((w / 14) * FPS); }\n    if (b.type === \"code\") { w = b.lines.join(\" \").split(/\\s+/).length; frames = 0; } // shown from frame 0\n    if (b.type === \"rows\") { w = b.rows.length * 4; frames = 0; } // shown from frame 0\n    if (b.type === \"count\") { w = 6; frames = 36; }\n    readWords += w;\n    t += frames + 6;\n    return { start, frames, words: w };\n  });\n  const animFrames = t + 12;\n  const read = Math.ceil((readWords / 3.6) * FPS) + 30;\n  return { blocks, animFrames, totalFrames: Math.max(animFrames + 45, read, 4 * FPS) };\n}\n```\n\n`animFrames` is how long the motion takes, and `totalFrames` is how long the finished video runs. They're very different numbers. Slide 2 above animates for 73 frames, about 2.4 seconds, and the video runs 13.8 seconds. Every slide also runs at least 4 seconds, so a title slide with one short line doesn't flash by.\n\n### The Remotion Side\n\nThere's one composition, 1080 by 1350 at 30 fps. That's a 4:5 portrait frame. The duration comes from the props through `calculateMetadata`, so each slide renders exactly as many frames as its animation needs:\n\n```tsx title=\"reels/src/carousel/index.tsx\"\nconst Root: React.FC = () => (\n  <Composition\n    id=\"carousel-slide\"\n    component={CarouselSlide as any}\n    width={1080}\n    height={1350}\n    fps={FPS}\n    durationInFrames={60}\n    defaultProps={{ slide: placeholder, index: 0, total: 1 }}\n    calculateMetadata={({ props }) => ({ durationInFrames: timeline((props as any).slide).animFrames })}\n  />\n);\n```\n\nThe slide component is ordinary React. Each paragraph splits into words, and each word fades in and rises 16 pixels, starting 1/14 of a second after the one before it:\n\n```tsx title=\"reels/src/carousel/Slide.tsx\"\nconst ease = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst inOut = (f: number, start: number, len = 9) => interpolate(f, [start, start + len], [0, 1], { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\", easing: ease });\n\n// inside Para:\n{tokens.map((w, i) => {\n  const o = inOut(frame, t.start + (i / 14) * 30);\n  return (\n    <span key={i} style={{ display: \"inline-block\", marginRight: \"0.26em\", opacity: o, transform: `translateY(${(1 - o) * 16}px)` }}>\n      ...\n    </span>\n  );\n})}\n```\n\nThe fonts are Source Sans 3 and JetBrains Mono, loaded with `@remotion/google-fonts`, the same two the blog uses. The footer shows the domain on the left and \"swipe →\" on the first slide or \"2 / 5\" on the rest.\n\n### Rendering Only The Moving Part\n\n`bun reels/render-carousel.ts <slug>` does the whole thing. It bundles the Remotion project once, then for each slide writes the props to a JSON file and renders against the bundle:\n\n```ts title=\"reels/render-carousel.ts\"\nconst raw = join(out, `raw-${n}.mp4`);\nrun(remotion, [\"render\", bundle, \"carousel-slide\", raw, `--props=${propsFile}`, \"--codec=h264\", \"--crf=16\", \"--concurrency=4\", \"--log=error\"]);\n```\n\nThat raw render only covers `animFrames`. The long hold at the end is the last frame repeated, and there's no reason to make Remotion draw the same frame a few hundred times. ffmpeg's `tpad` filter clones the last frame for however long the hold needs to be:\n\n```ts title=\"reels/render-carousel.ts\"\nconst holdSec = ((tl.totalFrames - tl.animFrames) / FPS).toFixed(2);\n// -t, not -shortest: -shortest cuts the output before tpad's held frames are written.\nrun(\"ffmpeg\", [\"-y\", \"-loglevel\", \"error\", \"-i\", raw, \"-f\", \"lavfi\", \"-i\", \"anullsrc=r=44100:cl=stereo\",\n  \"-vf\", `tpad=stop_mode=clone:stop_duration=${holdSec},scale=out_range=tv,format=yuv420p`,\n  \"-t\", (tl.totalFrames / FPS).toFixed(3), \"-c:v\", \"libx264\", \"-crf\", \"20\", \"-preset\", \"medium\",\n  \"-color_range\", \"tv\", \"-r\", String(FPS), \"-c:a\", \"aac\", \"-b:a\", \"64k\", \"-movflags\", \"+faststart\", final]);\n```\n\nFor the du carousel that meant Remotion rendered 354 frames and ffmpeg wrote 1,536.\n\nA few other things happen in that pass. It adds a silent stereo AAC track from `anullsrc`. It converts the color range: ffprobe reports the raw Remotion file as `yuvj420p` with `color_range=pc`, and the finished slide as `yuv420p` with `color_range=tv`. And `+faststart` moves the index to the front of the file so playback can start before the whole thing downloads.\n\nThe comment about `-t` explains a trap. `anullsrc` never ends, so something has to stop the output, and `-shortest` sounds like the right tool. It cuts the file off before `tpad` has written the held frames, though. Passing the exact duration with `-t` gets the whole hold.\n\n### One Joined File For X\n\nThreads takes a carousel of videos, so each `slide-NN.mp4` goes up as its own item. For X I post one video with every slide in order. Since every slide comes out of the same ffmpeg settings, the concat demuxer can join them without re-encoding:\n\n```ts title=\"reels/render-carousel.ts\"\nconst list = join(out, \"concat.txt\");\nwriteFileSync(list, parts.map((p) => `file '${p}'`).join(\"\\n\"));\nrun(\"ffmpeg\", [\"-y\", \"-loglevel\", \"error\", \"-f\", \"concat\", \"-safe\", \"0\", \"-i\", list, \"-c\", \"copy\", \"-movflags\", \"+faststart\", join(out, \"all-slides.mp4\")]);\n```\n\n`concat.txt` is just a list of absolute paths, one `file '...'` line per slide, and `-safe 0` lets ffmpeg accept absolute paths. For the du carousel the five slides run 6, 13.8, 9.4, 12.7 and 9.4 seconds and weigh 134 to 265 KB each. The joined file runs 51.2 seconds and comes in at 915 KB.\n\nEverything lands in `reels/out/carousels/<folder>/`, and I copy the finished files into `public/social/<folder>/threads/` and `public/social/<folder>/twitter/` so they deploy with the site. From there [Octopost](https://octopost.ink/?ref=deallocated-post) schedules them alongside the post.\n\n### Checking Before Posting\n\nBefore anything renders, the script gathers the caption, kickers, titles and paragraph text and runs them through a style check based on the blog's writing rules. Any em or en dash, any word from a short banned list, or anything shaped like \"not this, but that\" stops the render with a list of problems. Code blocks are skipped, since code is allowed to look however it looks.\n\nAfter each slide renders, ffmpeg pulls two stills out of it:\n\n```ts title=\"reels/render-carousel.ts\"\nrun(\"ffmpeg\", [\"-y\", \"-loglevel\", \"error\", \"-sseof\", \"-0.1\", \"-i\", final, \"-frames:v\", \"1\", join(out, `slide-${n}-end.png`)]);\nrun(\"ffmpeg\", [\"-y\", \"-loglevel\", \"error\", \"-i\", final, \"-frames:v\", \"1\", join(out, `slide-${n}-first.png`)]);\n```\n\nThe end frame shows the finished slide. There's also a `--stills` flag that skips video entirely and renders only the last animated frame of each slide as a PNG, a quick layout check while I'm adjusting text.\n\n### Threads Shows The First Frame\n\nThe first version animated everything. Code panels came in line by line, every 6 frames, sliding in from the left. Table rows came in one at a time, every 8 frames. It looked nice in motion.\n\nThen I saw the carousels on Threads. Threads uses each video's first frame as the preview in the carousel, and on frame 0 of a code slide nothing had arrived yet except the title. Here's the first frame of the table slide from the Brotli carousel as it was:\n\n![The first frame of a carousel slide titled Quality 11, once, with only the kicker and title visible and empty white space where the table should be](/media/posts/rendering-social-carousels-as-video-with-remotion/first-frame-before.png \"Before: frame 0 has only the title\")\n\nA slide whose whole point is a table of numbers previewed as a heading over empty space. Someone scrolling past had no reason to tap it.\n\nTitles were already on screen from frame 0 for this exact reason, so the fix was to treat code and tables the same way. The code panel lost its per-line fade:\n\n```diff title=\"reels/src/carousel/Slide.tsx\"\n-      const o = inOut(frame, t.start + i * 6);\n-      return <div key={i} style={{ minHeight: \"1.45em\", opacity: o, transform: `translateX(${(1 - o) * -18}px)` }}>{l}</div>;\n+      // On screen from frame 0: Threads uses each video's first frame as its preview, and an empty code panel looked broken.\n+      return <div key={i} style={{ minHeight: \"1.45em\" }}>{l}</div>;\n```\n\nTable rows got `const o = 1`, and `timeline()` gave both block types zero animation frames, so a paragraph after them starts 6 frames in instead of waiting for a reveal that no longer happens:\n\n```diff title=\"reels/src/carousel/types.ts\"\n-    if (b.type === \"code\") { w = b.lines.join(\" \").split(/\\s+/).length; frames = b.lines.length * 6; }\n-    if (b.type === \"rows\") { w = b.rows.length * 4; frames = b.rows.length * 8; }\n+    if (b.type === \"code\") { w = b.lines.join(\" \").split(/\\s+/).length; frames = 0; } // shown from frame 0\n+    if (b.type === \"rows\") { w = b.rows.length * 4; frames = 0; } // shown from frame 0\n```\n\nThe words in the code still count toward the reading time, so the slide still holds long enough to read it. Here's the same slide's first frame after the re-render:\n\n![The first frame of the same slide, now showing the full table of gzip and Brotli sizes and times under the title](/media/posts/rendering-social-carousels-as-video-with-remotion/first-frame-after.png \"After: the table is there from frame 0\")\n\nParagraphs still animate in word by word, and that's fine. A preview with the title and a code panel or table reads as a real slide, and the motion is still there once someone taps in. The `slide-NN-first.png` stills are what I check for this. If the first frame of a slide doesn't make sense on its own, it isn't ready to post.","html_content":"<p>Each post on this blog gets a short carousel on Threads and X: four or five slides with the main idea and usually a code sample or a table. They used to be PNGs. Now every slide is a little video where the words come in one at a time, rendered with <a href=\"https://www.remotion.dev\">Remotion</a> from a TypeScript file per post.</p>\n<p>Here’s slide 2 from the carousel for <a href=\"https://deallocatedobjects.com/posts/why-du-overcounts-on-apfs\">Why du Overcounts On APFS</a>:</p>\n<p><video src=\"https://deallocatedobjects.com/media/posts/rendering-social-carousels-as-video-with-remotion/du-apfs-slide-02.mp4\" controls playsinline></video></p>\n<h2 id=\"one-file-per-carousel\" data-level=\"3\">One File Per Carousel</h2>\n<p>A carousel is plain data. There are four kinds of block a slide can hold: a paragraph, a code panel, a three-column table, and a big number that counts from one value to another.</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/src/carousel/types.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> type</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Block</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  |</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">type</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"p\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">text</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  |</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">type</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"code\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">lines</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[]; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">size</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">?:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> number</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  |</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">type</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"rows\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">rows</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> [</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">][] }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  |</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">type</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"count\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">from</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> number</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">to</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> number</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">unit</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">label</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> };</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> type</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Slide</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">  tone</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">?:</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"blue\"</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> |</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"white\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">  kicker</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">  title</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> string</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// on screen from frame 0, so thumbnails aren't blank</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">  big</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">?:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> boolean</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// h1 size</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">  blocks</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Block</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[];</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">};</span></span></code></pre></figure><p>Each post gets a file in <code>reels/carousels/</code> named after its slug. The <code>folder</code> is where the finished videos go, and <code>satisfies Carousel</code> means a typo in a block type fails before anything renders:</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/carousels/why-du-overcounts-on-apfs.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> default</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  slug: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"why-du-overcounts-on-apfs\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  folder: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"2026-11-13-du-apfs\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  caption: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Chrome keeps 14 copies of itself in a temp folder on my Mac, ...\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  slides: [</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    { tone: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"blue\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, big: </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">true</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, kicker: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Deallocated Objects\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, title: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Why du overcounts on APFS\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, blocks: [{ type: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"p\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, text: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Clones share their blocks, and du counts every one in full.\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> }] },</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    { kicker: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"The test\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, title: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Three clones, 92 KB\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, blocks: [</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      { type: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"code\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, lines: [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"$ cp -c original.bin copy1.bin\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"$ cp -c original.bin copy2.bin\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"$ cp -c original.bin copy3.bin\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"$ du -sh .\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"1.0G  .\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">], size: </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">34</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> },</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      { type: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"p\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, text: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"A 256 MB file and three clones moved free space by 92 KB. A plain cp took 257 MB.\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> },</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    ] },</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">    // ...three more slides</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  ],</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">} </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">satisfies</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Carousel</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span></code></pre></figure><p>Backticks inside paragraph text become little code chips, so I can write “<code>gzip_static</code> follows <code>gzip_proxied</code>” and the slide styles it the way the blog does.</p>\n<h2 id=\"timing-comes-from-the-words\" data-level=\"3\">Timing Comes From The Words</h2>\n<p>Nothing in the carousel file says how long a slide lasts. A <code>timeline()</code> function works it out from the content. Paragraphs reveal at 14 words a second, a counter takes 36 frames, and there’s a 6-frame gap after each block. Then it estimates how long a person needs to read everything on the slide at 3.6 words a second and holds the slide that long:</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/src/carousel/types.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> FPS</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 30</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">/** Word reveal 14/s, counters 36 frames; code and tables are on screen from frame 0. */</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">export</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> function</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> timeline</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">slide</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Slide</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">blocks</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Timed</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[]; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">animFrames</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> number</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; </span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">totalFrames</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> number</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> } {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  let</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> t </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 8</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  let</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> readWords </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> words</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(slide.title) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> words</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(slide.kicker);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> blocks</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Timed</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">[] </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> slide.blocks.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">map</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">((</span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">b</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=></span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> start</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> t;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    let</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> frames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    let</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> w </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    if</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (b.type </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">===</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"p\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) { w </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> words</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(b.text); frames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> Math.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">ceil</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">((w </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 14</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> FPS</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">); }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    if</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (b.type </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">===</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"code\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) { w </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> b.lines.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\" \"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">).</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">split</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">/</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">\\s</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">/</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">).</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">length</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; frames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; } </span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// shown from frame 0</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    if</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (b.type </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">===</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"rows\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) { w </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> b.rows.</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">length</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 4</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; frames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 0</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; } </span><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// shown from frame 0</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    if</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (b.type </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">===</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \"count\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) { w </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 6</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; frames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 36</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">; }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    readWords </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> w;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">    t </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> frames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 6</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">    return</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { start, frames, words: w };</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">  });</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> animFrames</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> t </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 12</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> read</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> Math.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">ceil</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">((readWords </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 3.6</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> FPS</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 30</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">  return</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> { blocks, animFrames, totalFrames: Math.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">max</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(animFrames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">+</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> 45</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, read, </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">4</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> *</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> FPS</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) };</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}</span></span></code></pre></figure><p><code>animFrames</code> is how long the motion takes, and <code>totalFrames</code> is how long the finished video runs. They’re very different numbers. Slide 2 above animates for 73 frames, about 2.4 seconds, and the video runs 13.8 seconds. Every slide also runs at least 4 seconds, so a title slide with one short line doesn’t flash by.</p>\n<h2 id=\"the-remotion-side\" data-level=\"3\">The Remotion Side</h2>\n<p>There’s one composition, 1080 by 1350 at 30 fps. That’s a 4:5 portrait frame. The duration comes from the props through <code>calculateMetadata</code>, so each slide renders exactly as many frames as its animation needs:</p>\n<figure class=\"code\" data-lang=\"text\"><figcaption><span class=\"file\">reels/src/carousel/index.tsx</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>const Root: React.FC = () => (</span></span>\n<span class=\"line\"><span>  &#x3C;Composition</span></span>\n<span class=\"line\"><span>    id=\"carousel-slide\"</span></span>\n<span class=\"line\"><span>    component={CarouselSlide as any}</span></span>\n<span class=\"line\"><span>    width={1080}</span></span>\n<span class=\"line\"><span>    height={1350}</span></span>\n<span class=\"line\"><span>    fps={FPS}</span></span>\n<span class=\"line\"><span>    durationInFrames={60}</span></span>\n<span class=\"line\"><span>    defaultProps={{ slide: placeholder, index: 0, total: 1 }}</span></span>\n<span class=\"line\"><span>    calculateMetadata={({ props }) => ({ durationInFrames: timeline((props as any).slide).animFrames })}</span></span>\n<span class=\"line\"><span>  /></span></span>\n<span class=\"line\"><span>);</span></span></code></pre></figure><p>The slide component is ordinary React. Each paragraph splits into words, and each word fades in and rises 16 pixels, starting 1/14 of a second after the one before it:</p>\n<figure class=\"code\" data-lang=\"text\"><figcaption><span class=\"file\">reels/src/carousel/Slide.tsx</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>const ease = Easing.bezier(0.2, 0.8, 0.2, 1);</span></span>\n<span class=\"line\"><span>const inOut = (f: number, start: number, len = 9) => interpolate(f, [start, start + len], [0, 1], { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\", easing: ease });</span></span>\n<span class=\"line\"><span></span></span>\n<span class=\"line\"><span>// inside Para:</span></span>\n<span class=\"line\"><span>{tokens.map((w, i) => {</span></span>\n<span class=\"line\"><span>  const o = inOut(frame, t.start + (i / 14) * 30);</span></span>\n<span class=\"line\"><span>  return (</span></span>\n<span class=\"line\"><span>    &#x3C;span key={i} style={{ display: \"inline-block\", marginRight: \"0.26em\", opacity: o, transform: `translateY(${(1 - o) * 16}px)` }}></span></span>\n<span class=\"line\"><span>      ...</span></span>\n<span class=\"line\"><span>    &#x3C;/span></span></span>\n<span class=\"line\"><span>  );</span></span>\n<span class=\"line\"><span>})}</span></span></code></pre></figure><p>The fonts are Source Sans 3 and JetBrains Mono, loaded with <code>@remotion/google-fonts</code>, the same two the blog uses. The footer shows the domain on the left and “swipe →” on the first slide or “2 / 5” on the rest.</p>\n<h2 id=\"rendering-only-the-moving-part\" data-level=\"3\">Rendering Only The Moving Part</h2>\n<p><code>bun reels/render-carousel.ts &lt;slug&gt;</code> does the whole thing. It bundles the Remotion project once, then for each slide writes the props to a JSON file and renders against the bundle:</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/render-carousel.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> raw</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(out, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`raw-${</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">n</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}.mp4`</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">run</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(remotion, [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"render\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, bundle, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"carousel-slide\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, raw, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`--props=${</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">propsFile</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}`</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"--codec=h264\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"--crf=16\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"--concurrency=4\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"--log=error\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]);</span></span></code></pre></figure><p>That raw render only covers <code>animFrames</code>. The long hold at the end is the last frame repeated, and there’s no reason to make Remotion draw the same frame a few hundred times. ffmpeg’s <code>tpad</code> filter clones the last frame for however long the hold needs to be:</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/render-carousel.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> holdSec</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> ((tl.totalFrames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">-</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> tl.animFrames) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> FPS</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">).</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">toFixed</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">2</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// -t, not -shortest: -shortest cuts the output before tpad's held frames are written.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">run</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"ffmpeg\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-y\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-loglevel\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"error\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-i\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, raw, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-f\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"lavfi\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-i\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"anullsrc=r=44100:cl=stereo\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  \"-vf\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`tpad=stop_mode=clone:stop_duration=${</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">holdSec</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">},scale=out_range=tv,format=yuv420p`</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  \"-t\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, (tl.totalFrames </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">/</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> FPS</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">).</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">toFixed</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">3</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">), </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-c:v\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"libx264\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-crf\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"20\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-preset\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"medium\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  \"-color_range\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"tv\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-r\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">String</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">FPS</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">), </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-c:a\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"aac\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-b:a\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"64k\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-movflags\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"+faststart\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, final]);</span></span></code></pre></figure><p>For the du carousel that meant Remotion rendered 354 frames and ffmpeg wrote 1,536.</p>\n<p>A few other things happen in that pass. It adds a silent stereo AAC track from <code>anullsrc</code>. It converts the color range: ffprobe reports the raw Remotion file as <code>yuvj420p</code> with <code>color_range=pc</code>, and the finished slide as <code>yuv420p</code> with <code>color_range=tv</code>. And <code>+faststart</code> moves the index to the front of the file so playback can start before the whole thing downloads.</p>\n<p>The comment about <code>-t</code> explains a trap. <code>anullsrc</code> never ends, so something has to stop the output, and <code>-shortest</code> sounds like the right tool. It cuts the file off before <code>tpad</code> has written the held frames, though. Passing the exact duration with <code>-t</code> gets the whole hold.</p>\n<h2 id=\"one-joined-file-for-x\" data-level=\"3\">One Joined File For X</h2>\n<p>Threads takes a carousel of videos, so each <code>slide-NN.mp4</code> goes up as its own item. For X I post one video with every slide in order. Since every slide comes out of the same ffmpeg settings, the concat demuxer can join them without re-encoding:</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/render-carousel.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">const</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> list</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(out, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"concat.txt\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">writeFileSync</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(list, parts.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">map</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">((</span><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">p</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=></span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> `file '${</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">p</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}'`</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">).</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">\\n</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">));</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">run</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"ffmpeg\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-y\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-loglevel\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"error\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-f\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"concat\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-safe\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"0\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-i\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, list, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-c\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"copy\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-movflags\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"+faststart\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(out, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"all-slides.mp4\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)]);</span></span></code></pre></figure><p><code>concat.txt</code> is just a list of absolute paths, one <code>file '...'</code> line per slide, and <code>-safe 0</code> lets ffmpeg accept absolute paths. For the du carousel the five slides run 6, 13.8, 9.4, 12.7 and 9.4 seconds and weigh 134 to 265 KB each. The joined file runs 51.2 seconds and comes in at 915 KB.</p>\n<p>Everything lands in <code>reels/out/carousels/&lt;folder&gt;/</code>, and I copy the finished files into <code>public/social/&lt;folder&gt;/threads/</code> and <code>public/social/&lt;folder&gt;/twitter/</code> so they deploy with the site. From there <a href=\"https://octopost.ink/?ref=deallocated-post\">Octopost</a> schedules them alongside the post.</p>\n<h2 id=\"checking-before-posting\" data-level=\"3\">Checking Before Posting</h2>\n<p>Before anything renders, the script gathers the caption, kickers, titles and paragraph text and runs them through a style check based on the blog’s writing rules. Any em or en dash, any word from a short banned list, or anything shaped like “not this, but that” stops the render with a list of problems. Code blocks are skipped, since code is allowed to look however it looks.</p>\n<p>After each slide renders, ffmpeg pulls two stills out of it:</p>\n<figure class=\"code\" data-lang=\"typescript\"><figcaption><span class=\"file\">reels/render-carousel.ts</span><span class=\"lang\">TypeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">run</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"ffmpeg\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-y\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-loglevel\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"error\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-sseof\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-0.1\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-i\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, final, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-frames:v\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"1\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(out, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`slide-${</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">n</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}-end.png`</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)]);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">run</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"ffmpeg\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-y\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-loglevel\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"error\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-i\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, final, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"-frames:v\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"1\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">, </span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">join</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">(out, </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">`slide-${</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">n</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">}-first.png`</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">)]);</span></span></code></pre></figure><p>The end frame shows the finished slide. There’s also a <code>--stills</code> flag that skips video entirely and renders only the last animated frame of each slide as a PNG, a quick layout check while I’m adjusting text.</p>\n<h2 id=\"threads-shows-the-first-frame\" data-level=\"3\">Threads Shows The First Frame</h2>\n<p>The first version animated everything. Code panels came in line by line, every 6 frames, sliding in from the left. Table rows came in one at a time, every 8 frames. It looked nice in motion.</p>\n<p>Then I saw the carousels on Threads. Threads uses each video’s first frame as the preview in the carousel, and on frame 0 of a code slide nothing had arrived yet except the title. Here’s the first frame of the table slide from the Brotli carousel as it was:</p>\n<p><figure class=\"image\"><img src=\"https://deallocatedobjects.com/media/posts/rendering-social-carousels-as-video-with-remotion/first-frame-before.png\" alt=\"The first frame of a carousel slide titled Quality 11, once, with only the kicker and title visible and empty white space where the table should be\" loading=\"lazy\" decoding=\"async\" width=\"1080\" height=\"1350\"><figcaption>Before: frame 0 has only the title</figcaption></figure></p>\n<p>A slide whose whole point is a table of numbers previewed as a heading over empty space. Someone scrolling past had no reason to tap it.</p>\n<p>Titles were already on screen from frame 0 for this exact reason, so the fix was to treat code and tables the same way. The code panel lost its per-line fade:</p>\n<figure class=\"code\" data-lang=\"diff\"><figcaption><span class=\"file\">reels/src/carousel/Slide.tsx</span><span class=\"lang\">Diff</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#B31D28;--shiki-dark:#FDAEB7\">-      const o = inOut(frame, t.start + i * 6);</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#B31D28;--shiki-dark:#FDAEB7\">-      return &#x3C;div key={i} style={{ minHeight: \"1.45em\", opacity: o, transform: `translateX(${(1 - o) * -18}px)` }}>{l}&#x3C;/div>;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">+      // On screen from frame 0: Threads uses each video's first frame as its preview, and an empty code panel looked broken.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">+      return &#x3C;div key={i} style={{ minHeight: \"1.45em\" }}>{l}&#x3C;/div>;</span></span></code></pre></figure><p>Table rows got <code>const o = 1</code>, and <code>timeline()</code> gave both block types zero animation frames, so a paragraph after them starts 6 frames in instead of waiting for a reveal that no longer happens:</p>\n<figure class=\"code\" data-lang=\"diff\"><figcaption><span class=\"file\">reels/src/carousel/types.ts</span><span class=\"lang\">Diff</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#B31D28;--shiki-dark:#FDAEB7\">-    if (b.type === \"code\") { w = b.lines.join(\" \").split(/\\s+/).length; frames = b.lines.length * 6; }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#B31D28;--shiki-dark:#FDAEB7\">-    if (b.type === \"rows\") { w = b.rows.length * 4; frames = b.rows.length * 8; }</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">+    if (b.type === \"code\") { w = b.lines.join(\" \").split(/\\s+/).length; frames = 0; } // shown from frame 0</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">+    if (b.type === \"rows\") { w = b.rows.length * 4; frames = 0; } // shown from frame 0</span></span></code></pre></figure><p>The words in the code still count toward the reading time, so the slide still holds long enough to read it. Here’s the same slide’s first frame after the re-render:</p>\n<p><figure class=\"image\"><img src=\"https://deallocatedobjects.com/media/posts/rendering-social-carousels-as-video-with-remotion/first-frame-after.png\" alt=\"The first frame of the same slide, now showing the full table of gzip and Brotli sizes and times under the title\" loading=\"lazy\" decoding=\"async\" width=\"1080\" height=\"1350\"><figcaption>After: the table is there from frame 0</figcaption></figure></p>\n<p>Paragraphs still animate in word by word, and that’s fine. A preview with the title and a code panel or table reads as a real slide, and the motion is still there once someone taps in. The <code>slide-NN-first.png</code> stills are what I check for this. If the first frame of a slide doesn’t make sense on its own, it isn’t ready to post.</p>","created_at":"2026-11-20T14:00:00.000Z","updated_at":"2026-11-20T14:00:00.000Z"}