# Highlight clips Use this procedure to make short captioned podcast highlight clips for kirupa.com interviews. This is a repeatable workflow, not permission to redo proven work. Do not render or re-render real clips unless the user explicitly asks. For a widescreen presentation converted into vertical social video, start with [Vertical social video](vertical-social.md). Its approved stacked layout, 100px captions, hard outline/shadow, and cover-style background override the podcast-specific vertical framing and caption defaults below. Reuse this reference's transcription, cut-point, encoding, and QA practices. ## Working folder model Do not run the highlight scripts in place inside the repo. They create large working folders. 1. Copy the reusable scripts to a scratch workspace outside the repo: ```bash mkdir -p /hl rsync -a skills/kirupa-podcast/scripts/highlights/ /hl/ cd /hl ``` 2. Put helper binaries in the scratch copy: ```bash mkdir -p bin logs swiftc faces.swift -o bin/faces -framework Vision -framework CoreImage -framework Foundation # Put yt-dlp at bin/yt-dlp, or symlink an existing trusted copy. ``` 3. Run every command below from the scratch workspace. 4. Keep media, `sections/`, `wav/`, `whisper/`, `build/`, `out/`, `delivery/`, `frames/`, `analysis/`, `meta/`, and `bin/` out of git. 5. Delete test outputs when done. Previous deliveries, for reference only: - Dave clips: `~/Desktop/Thack/dave-social-clips/`. - All-interview clips: `~/Desktop/kirupa-podcast-highlights/`. - Daniel Hunter clips (eight from one episode, cut from the local recording): `~/Desktop/Videos/Daniel/clips/`. ## Script map | Script | Job | | --- | --- | | `podcast_inventory.py` | Podcast index cards, live page transcripts, context, and YouTube IDs | | `fetch_meta.sh` | yt-dlp metadata and auto-caption json3 for every ID in `ids.txt` | | `pick_prompt.md` | Brief for the sub-agents that pick one moment per episode | | `locate.py` | Finds each pick in the YouTube captions | | `download.py` | Cuts padded sections from YouTube, or from a local video with `--source` | | `whisper_sections.py` | Word-timed Whisper for each section | | `tokens.py` | Timed caption tokens and clip specs (`clips/`), with optional `overrides.json` | | `make_worksheets.py` | Light-edit worksheets (`edit/*.in.txt`) | | `edit_prompt.md` | Brief for the caption light-edit sub-agents | | `captions.py` | Aligns edited captions, picks quiet cut points, writes `final/` | | `faces.swift`, `analyze_frames.py` | Face and frame analysis for 9:16 framing | | `grab_layout.py`, `inset_detect.py` | Layout contact sheets and picture-in-picture inset measurements | | `layouts.json`, `make_plans.py` | Per-episode layout table and 9:16 framing plans | | `clip_engine.py` | Shared caption and render core: font, sizes, shadows, encoding | | `build_highlights.py` | `--list`, `--graph`, render, `--manifest`, `--deliver` | | `validate_highlights.py` | Post-render checks and contact sheets | | `examples/` | Trimmed schema examples for inventory, final, and plan JSON | ## Dependencies Verify the common tools: ```bash ffmpeg -version ffprobe -version python3 - <<'PY' import PIL, numpy print('python deps ok') PY ``` Set up Whisper for section transcription: ```bash python3 -m venv ~/.venvs/mlx-whisper ~/.venvs/mlx-whisper/bin/pip install mlx-whisper==0.4.3 ~/.venvs/mlx-whisper/bin/python - <<'PY' import mlx_whisper print('mlx-whisper ok') PY ``` For back-catalog YouTube work, also verify: ```bash bin/yt-dlp --version swiftc --version ``` The builder checks for `ffmpeg`, `ffprobe`, and the caption font. Default font: `~/Library/Fonts/Born2bSportyV10.ttf`. ## Outputs and naming Render both formats for each clip: - `1920x1080` for LinkedIn and YouTube. - `1080x1920` for X, TikTok, YouTube Shorts, and Instagram Reels. People mostly watch X on phones, where a vertical clip fills more of the screen. `social-posts.md` covers the copy that goes with each channel. Name files: - `NN-guest-slug-file-slug-1920x1080.mp4` - `NN-guest-slug-file-slug-1080x1920.mp4` Write `manifest.json` beside delivered files with clip metadata, platform notes, source times, and vertical layout mode. ## Entry point: Back-catalog interviews from YouTube Use this when starting from the live podcast index and YouTube videos. ### 1. Inventory, pages, transcripts, context, and IDs Reads: - `https://www.kirupa.com/podcast/index.htm` - `https://www.kirupa.com/podcast/ai/.md` - fallback `https://www.kirupa.com/podcast/.htm` Writes: - `inventory.json` - `ids.txt` - `pages/.md` or `pages/.htm` - `transcripts/.json` - `transcripts/.txt` - `context/.txt` Command: ```bash python3 podcast_inventory.py --out . ``` Use `--only ` for a subset. ### 2. YouTube metadata and auto captions Reads: - `ids.txt` Writes: - `meta/.info.json` - `meta/.*.json3` - `logs/meta-.log` Command: ```bash bash fetch_meta.sh ``` ### 3. Pick moments Reads: - `inventory.json` - `context/.txt` - `transcripts/.txt` - `pick_prompt.md` Writes: - `picks/.json` Use sub-agents or a careful direct pass to choose one primary moment per episode. Aim for one 45-75 second clip unless the user asks for more. Store the passage, featured speaker, title, post hook, approximate transcript turn, word count, and important names or terms. ### 4. Locate moments on YouTube Reads: - `picks/.json` - `meta/.en-orig.json3` or other caption json3 files Writes: - `locations.json` Command: ```bash python3 locate.py ``` The locator narrows by turn time and matches the passage head and tail. Do not use a whole-transcript global match when timings are available. ### 5. Download padded sections Reads: - `locations.json` - `picks/.json` - `bin/yt-dlp` Writes: - `sections/.mkv` - `sections/.json` Command: ```bash python3 download.py ``` The script resolves stream URLs with yt-dlp and cuts with ffmpeg `-copyts` so source timestamps stay absolute. ### 6. Transcribe sections Reads: - `sections/.mkv` - `sections/.json` - `picks/.json` Writes: - `whisper/.json` - temporary `wav/.wav` while running Command: ```bash ~/.venvs/mlx-whisper/bin/python whisper_sections.py ``` ### 7. Timed tokens and clip specs Reads: - `picks/.json` - `transcripts/.json` - `whisper/.json` - optional `overrides.json` Writes: - `clips/.json` - a token report on stdout (redirect it to `tokens_report.txt` to keep it) Command: ```bash python3 tokens.py [slug ...] > tokens_report.txt ``` Whisper decides what was said; the pick's passage supplies only punctuation, casing, and name spellings. Each clip spec holds the title, file slug, post hook, speaker, start, end, timed tokens, and a report. Read the `MISSING`, `KEEP+`, and `WHISPER` flags in the report. When a clip's span or a word is wrong, add an entry to `overrides.json` and rerun: ```json {"": {"start_at": "first words", "end_at": "last words", "start_shift": -0.2, "end_shift": 0.3, "replace": [["wrong token", "right token"]]}} ``` ### 8. Worksheets for light-editing Reads: - `clips/.json` - `picks/.json` - `whisper/.json` - `sections/.json` - `transcripts/.json` Writes: - `edit/.in.txt` Command: ```bash python3 make_worksheets.py ``` ### 9. Caption edit pass Reads: - `edit_prompt.md` - `edit/.in.txt` Writes: - `edit/.json` Follow the light-edit rules exactly: improve readability, but do not paraphrase, reorder, or change meaning. Validate each JSON: ```bash python3 -m json.tool edit/.json > /dev/null ``` ### 10. Align captions and choose cut points Reads: - `edit/.json` - `clips/.json` - `sections/.json` - `whisper/.json` Writes: - `final/.json` - QA text printed to stdout Command: ```bash python3 captions.py ``` Rerun until no critical deletion, unlisted substitution, loud cut, or sentence-end warning remains. ### 11. Analyze frames Reads: - `clips/.json` - `sections/.mkv` - `sections/.json` - `bin/faces` Writes: - `frames//*.jpg` - `analysis/.json` - `analysis/.jpg` Command: ```bash python3 analyze_frames.py ``` Use `grab_layout.py` for quick episode layout sheets and `inset_detect.py` for picture-in-picture inset measurements when needed. ### 12. Write vertical framing plans Reads: - `layouts.json` - `final/.json` - `analysis/.json` - any per-episode layout tables or manual measurements Writes: - `plans/.json` - optional plan diagnostics Command: ```bash python3 make_plans.py ``` Every new episode needs a `layouts.json` entry. Plan modes are `crop` and `box`; region crops are represented as crop plans with constrained bounds. ### 13. Caption and graph checks Reads: - `inventory.json` - `final/.json` - `plans/.json` - `sections/.json` Writes: - no media Commands: ```bash python3 build_highlights.py --only --list --formats landscape vertical python3 build_highlights.py --only --graph --formats landscape vertical ``` Confirm captions, line breaks, font glyphs, format settings, and crop or box expressions before rendering. ### 14. Render only on request Reads: - `sections/.mkv` - `final/.json` - `plans/.json` - `inventory.json` Writes: - `build/` caption PNGs, concat files, and logs - `out/*-1920x1080.mp4` - `out/*-1080x1920.mp4` Command: ```bash python3 build_highlights.py --jobs 4 ``` For a sample that is safe to delete: ```bash python3 build_highlights.py --only --sample-seconds 5 --jobs 1 ``` ### 15. Validate and make the manifest Reads: - `out/*.mp4` - `inventory.json` - `final/.json` - `plans/.json` Writes: - `build/validation.json` - `build/sheets/*.jpg` - `out/manifest.json` when requested Commands: ```bash python3 validate_highlights.py out python3 build_highlights.py --manifest --output-dir out ``` ## Entry point: New episode from a local recording Use the same pipeline, with these differences: 1. Copy the scripts to a scratch workspace first, exactly as above. 2. Picks can come from the editorial JSON transcript instead of the live index. 3. `transcripts/.json` can be written from the editorial JSON `transcript[]`; use the same shape as the back-catalog output: ```json {"slug":"...","guest":"...","youtube":"...","turns":[{"seconds":38,"timestamp":"0:38","speaker":"Guest","paragraphs":["..."]}]} ``` 4. Also write `transcripts/.txt` in the `[turn N | M:SS | Ns] Speaker:` format. 5. Write `context/.txt` with the slug, guest, card title, date/runtime if known, YouTube ID if known, and episode summary or transcript context. 6. Picks come from the editorial transcript and user notes. 7. `locations.json` can be written by hand when the local recording is the source: ```json {"slug":{"slug":"slug","vid":"local","approx_start":120.0,"approx_end":180.0,"coverage":1.0}} ``` 8. Once YouTube captions exist, `locate.py` can locate the same pick from captions instead. 9. Cut sections from a local final video with: ```bash python3 download.py --source /path/to/final-recording.mp4 --only ``` 10. Or cut from YouTube with normal `download.py` after publication. 11. Add the episode to `layouts.json` before `make_plans.py`. 12. Continue with Whisper, worksheets, edit JSON, `captions.py`, frame analysis, plans, `--list`, `--graph`, render only on request, validation, and manifest. ### Several clips from one episode The scripts key everything by slug, so give each clip its own slug, `__NN` (Daniel's are `daniel_hunter_age_of_the_artist__01` to `__08`): - Write `picks/`, `context/`, and a `locations.json` entry per clip slug, and copy the episode transcript to `transcripts/.json`. `make_worksheets.py` reads it by clip slug. - `download.py --source` doesn't pad, so pad each `approx_start` and `approx_end` yourself (about 15 seconds before and 20 after). - Write one `inventory.json` entry per clip, in delivery order. Each keeps the episode's `href`, so the manifest links the real page, and adds `"clip_slug": "__NN"`. - `make_plans.py` falls back from a clip slug to the episode's `layouts.json` entry, so add the episode once. - In a split-screen layout, the 9:16 crop starts on the clip's featured speaker, which is Kirupa's side when `speaker` is `Kirupa`, and follows the captions to the other side whenever both people speak. When the mixed audio has crosstalk (the guest's "It would have looked like complete slop" under Kirupa's echo), transcribe the guest's isolated Riverside track for that span. Find its offset with `scripts/transcript/check_alignment.py` (Daniel's was `+46.926`), caption the guest's words, and list them in `fixes`. ## Choosing moments Choose moments before rendering. - Aim for one clip per episode unless asked for more. - Target 45-75 seconds; 35-45 seconds can work when the thought is complete. - Avoid clips over 75 seconds unless the context is necessary. - Prefer complete ideas that stand alone. - Prefer one speaker or a clean handoff. - Avoid cross-talk, transcript uncertainty, or visual context that will not appear in the clip. - Favor concrete advice, a strong analogy, a memorable opinion, or a useful surprise. - Use `pick_prompt.md` for back-catalog selection. ## Cut-point rules - Start and end on sentence boundaries. - Never clip the first word, last word, intake breath, or release breath. - Use Whisper words for first and last spoken words. - Use audio RMS to find nearby quiet points. - Use manual `cut.start` or `cut.end` only when automatic quiet-point choices are wrong. - Check the `IN` and `OUT` lines from `captions.py` before accepting final JSON. ## Caption font The user may call the style "Birdy font captions," but the proven font is **Born2bSportyV10**. - Default path: `~/Library/Fonts/Born2bSportyV10.ttf`. - Font family: `Born2bSportyV10`. - Francis started with "a pixel font like Birdy" and then switched to Born2bSportyV10. - Dave and the all-interview clips use Born2bSportyV10. - `~/Library/Fonts/Birdy.ttf` exists, but Birdy is caps-only and lacks apostrophe, dash, and ellipsis glyphs. - The builder accepts `--font ~/Library/Fonts/Birdy.ttf`, but use it only if the user explicitly accepts those glyph limits. ## Caption layout Landscape: - Frame: `1920x1080`. - Font size: `60`. - Center y: `900`. - Center x: frame center. - Max width: `1500` px. - Max characters: `56`. - Max words: `12`. - Shadow offset: `(6, 8)`. Vertical: - Frame: `1080x1920`. - Font size: `66`. - Center y: `1480`. - Center x: `525`. - Max width: `870` px. - Max characters: `36`. - Max words: `8`. - Shadow offset: `(6, 8)`. - Vertical captions are nested inside the landscape line breaks. Style: white text, one-pixel dark stroke, soft black shadow, no bars, no labels, burned in. ## Caption text rules - Captions must match the spoken words. - Light cleanup is OK: drop fillers, stutters, abandoned false starts, and pure backchannels. - Never paraphrase, summarize, reorder, or change meaning. - Never remove or invert a negation. - Watch `not`, `no`, `never`, `without`, `can't`, `don't`, `didn't`, and `doesn't`. - Preserve names, numbers, technical terms, and content words. - Use sentence case, not all caps, for burned captions. - Use glyph-safe punctuation: straight quotes and apostrophes, ` - ` for em dash, and `...` for ellipsis unless the chosen font proves otherwise. - Run `--list` and read the captions before rendering. ## Framing for 9:16 Plan modes: - `crop`: full-bleed 9:16 crop from the source. - `box`: speaker tile scaled to 1080 wide over a blurred, darkened copy of itself. - Region crops are `crop` plans constrained to a framed region or tile. Use `crop` when a 9:16 window can keep the speaker's face and avoid insets. Use `box` when the speaker is in a small split-screen tile, screen-share tile, or layout that would upscale badly. Crop plans can use static `x`, `x_shots` for scene cuts, or `x_by_speaker` for speaker-side switches. Box plans can use `rect` or `rect_by_speaker`. ## Encoding Keep the proven settings: `h264_videotoolbox`, `avc1`, `yuv420p`, AAC `192k`, 48 kHz audio, two-pass `loudnorm=I=-16:LRA=11:TP=-1.5` (the builder measures each clip first, because a single pass left quiet clips near -18 LUFS), short fades, `+faststart`, landscape bitrates `9M/13M/18M`, vertical bitrates `8M/12M/16M`, 30 fps for sources above 30.5 fps, and otherwise rounded native fps. ## QA checklist Before render: - Captions match the exact audio span. - No negation disappeared. - Substitutions do not change meaning. - Clip edges are clean. - Last caption ends on a sentence boundary. - Glyph check passes. - Plan bounds match final bounds. - 9:16 follows the active speaker or chosen subject. After render: - `python3 validate_highlights.py out` passes. - Dimensions, codec, pixel format, audio, fps, and duration are expected. - Loudness is about `-16 LUFS`. - Peak stays below about `-0.5 dBFS`. - First frame is not black. - Frame grabs show Born2bSportyV10 at the expected positions. - 9:16 framing is checked near each speaker or shot switch. Frame grabs: ```bash ffmpeg -v error -y -ss 1.0 -i out/NN-guest-file-1920x1080.mp4 -frames:v 1 check-landscape.png ffmpeg -v error -y -ss 1.0 -i out/NN-guest-file-1080x1920.mp4 -frames:v 1 check-vertical.png ``` ## Single-clip fix and re-render 1. Identify the exact slug and caption event. 2. Compare caption text against audio and Whisper words for the exact final span. 3. Search raw words around the span for negations. 4. Edit the source input: - Caption wording: edit `edit/.json` and rerun `captions.py `. - Wrong timed token or span: add a `replace`, `start_at`, or `end_at` entry to `overrides.json`, rerun `tokens.py `, then redo the worksheet, edit, and `captions.py` steps for that slug. - The original Dave social clips came from a one-off engine whose `Override(match, replacement, near)` entries did the same job. `clip_engine.py` is that engine's caption and render core, without the Dave clip list. 5. Run `--list` for both formats and confirm only the intended caption changed. 6. Render only that clip and both formats, only if the user asked. 7. Regenerate the manifest when delivered files change. 8. Validate both files and extract frames around the fixed caption. Real incident: in Dave clip 6, "There was always an Undo," Kirupa says "That option existed..." but meant "That option did not exist...". The caption matched the audio, and Kirupa asked for his intended meaning. The fix replaced the tokens near `4676s` with `did`, `not`, `exist` and re-rendered both formats, and the same correction went into the page transcript (`a41f9edf`, see `page.md`). When a caption changes meaning on purpose, change the page transcript in the same pass so the two never disagree. ## Pitfalls learned - Do not trust "Birdy font" literally. - Do not run the scripts inside the repo. - Do not let polished captions change meaning. - A missing `not` is a high-severity bug. - Do not render real clips just to inspect a plan. - YouTube `--download-sections` can drift; use `-copyts` sections. - Keep absolute timestamps through sections, Whisper, finals, and rendering. - Register importlib-loaded dataclass modules in `sys.modules` before `exec_module` on Python 3.9. - Use process workers for rendering. - Vertical crop switches should land on the first caption from the new speaker. - Box mode beats an over-upscaled crop for small tiles. - Contact sheets catch framing mistakes faster than watching every clip. - Trust audio and video over stale page speaker labels.