@arbidocs/blocks 0.5.191 → 0.5.192

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/bin/arbidocs-mix-take.mjs +34 -0
  2. package/bin/arbidocs-record-take.mjs +77 -11
  3. package/bin/arbidocs-voice-take.mjs +32 -0
  4. package/dist/{ConnectedCallDock-PVBDNOTA.cjs → ConnectedCallDock-7GGYYQNK.cjs} +23 -23
  5. package/dist/{ConnectedCallDock-PVBDNOTA.cjs.map → ConnectedCallDock-7GGYYQNK.cjs.map} +1 -1
  6. package/dist/{ConnectedCallRoom-H2OWGUEN.cjs → ConnectedCallRoom-ZZ7RBGGY.cjs} +16 -16
  7. package/dist/{ConnectedCallRoom-H2OWGUEN.cjs.map → ConnectedCallRoom-ZZ7RBGGY.cjs.map} +1 -1
  8. package/dist/{ConnectedNativeDocxComparison-NKVGPLSK.cjs → ConnectedNativeDocxComparison-PPVXDQY3.cjs} +20 -20
  9. package/dist/{ConnectedNativeDocxComparison-NKVGPLSK.cjs.map → ConnectedNativeDocxComparison-PPVXDQY3.cjs.map} +1 -1
  10. package/dist/{ConnectedPresentation-N6HNSYRH.cjs → ConnectedPresentation-LNDESKYE.cjs} +19 -19
  11. package/dist/{ConnectedPresentation-N6HNSYRH.cjs.map → ConnectedPresentation-LNDESKYE.cjs.map} +1 -1
  12. package/dist/{ConnectedProductionSetDialog-KT6BPSRE.cjs → ConnectedProductionSetDialog-SHDI7KP6.cjs} +6 -6
  13. package/dist/{ConnectedProductionSetDialog-KT6BPSRE.cjs.map → ConnectedProductionSetDialog-SHDI7KP6.cjs.map} +1 -1
  14. package/dist/{ConnectedSlidesTab-J7OPUXI4.cjs → ConnectedSlidesTab-SYDDGJWM.cjs} +16 -16
  15. package/dist/{ConnectedSlidesTab-J7OPUXI4.cjs.map → ConnectedSlidesTab-SYDDGJWM.cjs.map} +1 -1
  16. package/dist/{ConnectedStreamedWordArtifact-BLSAP7NY.cjs → ConnectedStreamedWordArtifact-GAACBGTY.cjs} +20 -20
  17. package/dist/{ConnectedStreamedWordArtifact-BLSAP7NY.cjs.map → ConnectedStreamedWordArtifact-GAACBGTY.cjs.map} +1 -1
  18. package/dist/{DocumentReviewCard-C2ZXJ2ZL.cjs → DocumentReviewCard-Q3NKJLSM.cjs} +19 -19
  19. package/dist/{DocumentReviewCard-C2ZXJ2ZL.cjs.map → DocumentReviewCard-Q3NKJLSM.cjs.map} +1 -1
  20. package/dist/{FilesViewerDialog-NUPMAEIC.cjs → FilesViewerDialog-4JWDTDO7.cjs} +53 -53
  21. package/dist/{FilesViewerDialog-NUPMAEIC.cjs.map → FilesViewerDialog-4JWDTDO7.cjs.map} +1 -1
  22. package/dist/{WorkspaceTableView-CSOPEZFT.cjs → WorkspaceTableView-QT63XYII.cjs} +10 -10
  23. package/dist/{WorkspaceTableView-CSOPEZFT.cjs.map → WorkspaceTableView-QT63XYII.cjs.map} +1 -1
  24. package/dist/agents/index.cjs +287 -287
  25. package/dist/{ai-2B4BMS6O.cjs → ai-A5YTWIEC.cjs} +25 -25
  26. package/dist/ai-A5YTWIEC.cjs.map +1 -0
  27. package/dist/auth/index.cjs +12 -12
  28. package/dist/calls/index.cjs +125 -125
  29. package/dist/chat/index.cjs +23 -23
  30. package/dist/{chunk-VNUBBRJM.cjs → chunk-2K5DLB7B.cjs} +3 -3
  31. package/dist/{chunk-VNUBBRJM.cjs.map → chunk-2K5DLB7B.cjs.map} +1 -1
  32. package/dist/{chunk-GOLLGCGK.cjs → chunk-33236Q7Y.cjs} +70 -70
  33. package/dist/{chunk-GOLLGCGK.cjs.map → chunk-33236Q7Y.cjs.map} +1 -1
  34. package/dist/{chunk-NTXII2XQ.cjs → chunk-3EIO4ZH5.cjs} +6 -6
  35. package/dist/{chunk-NTXII2XQ.cjs.map → chunk-3EIO4ZH5.cjs.map} +1 -1
  36. package/dist/{chunk-B5AOYT4U.cjs → chunk-5FSULBPE.cjs} +3 -3
  37. package/dist/{chunk-B5AOYT4U.cjs.map → chunk-5FSULBPE.cjs.map} +1 -1
  38. package/dist/{chunk-3P6KGC46.cjs → chunk-5OD6DRG7.cjs} +3 -3
  39. package/dist/{chunk-3P6KGC46.cjs.map → chunk-5OD6DRG7.cjs.map} +1 -1
  40. package/dist/{chunk-R37KPMUZ.cjs → chunk-5RUY5THD.cjs} +7 -7
  41. package/dist/{chunk-R37KPMUZ.cjs.map → chunk-5RUY5THD.cjs.map} +1 -1
  42. package/dist/{chunk-GEVBY536.cjs → chunk-633ZCYVN.cjs} +37 -37
  43. package/dist/{chunk-GEVBY536.cjs.map → chunk-633ZCYVN.cjs.map} +1 -1
  44. package/dist/{chunk-E62542RM.cjs → chunk-65NQW4RR.cjs} +18 -18
  45. package/dist/{chunk-E62542RM.cjs.map → chunk-65NQW4RR.cjs.map} +1 -1
  46. package/dist/{chunk-DFQWX2XY.cjs → chunk-7GVKG3G4.cjs} +13 -13
  47. package/dist/{chunk-DFQWX2XY.cjs.map → chunk-7GVKG3G4.cjs.map} +1 -1
  48. package/dist/{chunk-SOJYSRO4.cjs → chunk-A7MGQMOV.cjs} +10 -10
  49. package/dist/{chunk-SOJYSRO4.cjs.map → chunk-A7MGQMOV.cjs.map} +1 -1
  50. package/dist/{chunk-KJ5M72M2.cjs → chunk-AWQEN6WW.cjs} +7 -7
  51. package/dist/{chunk-KJ5M72M2.cjs.map → chunk-AWQEN6WW.cjs.map} +1 -1
  52. package/dist/{chunk-3U6XE7SF.cjs → chunk-AZUPMHZI.cjs} +4 -4
  53. package/dist/{chunk-3U6XE7SF.cjs.map → chunk-AZUPMHZI.cjs.map} +1 -1
  54. package/dist/{chunk-CUYELFKB.cjs → chunk-EAH7LFJN.cjs} +4 -4
  55. package/dist/{chunk-CUYELFKB.cjs.map → chunk-EAH7LFJN.cjs.map} +1 -1
  56. package/dist/{chunk-GY4T4JSC.cjs → chunk-EFV52SZ6.cjs} +4 -4
  57. package/dist/{chunk-GY4T4JSC.cjs.map → chunk-EFV52SZ6.cjs.map} +1 -1
  58. package/dist/{chunk-SLVWSTFY.cjs → chunk-ELN3YOXF.cjs} +28 -28
  59. package/dist/{chunk-SLVWSTFY.cjs.map → chunk-ELN3YOXF.cjs.map} +1 -1
  60. package/dist/{chunk-YNFETLNZ.cjs → chunk-ER2MRSLT.cjs} +3 -3
  61. package/dist/{chunk-YNFETLNZ.cjs.map → chunk-ER2MRSLT.cjs.map} +1 -1
  62. package/dist/{chunk-5UNZO4FA.cjs → chunk-GLNL5AL5.cjs} +50 -50
  63. package/dist/{chunk-5UNZO4FA.cjs.map → chunk-GLNL5AL5.cjs.map} +1 -1
  64. package/dist/{chunk-YK3GUFZX.cjs → chunk-GZPNBSRE.cjs} +15 -15
  65. package/dist/{chunk-YK3GUFZX.cjs.map → chunk-GZPNBSRE.cjs.map} +1 -1
  66. package/dist/{chunk-H3CYXI46.cjs → chunk-HH5MKRBL.cjs} +7 -7
  67. package/dist/{chunk-H3CYXI46.cjs.map → chunk-HH5MKRBL.cjs.map} +1 -1
  68. package/dist/{chunk-4GMPS6VX.cjs → chunk-IRDL2EC6.cjs} +49 -49
  69. package/dist/{chunk-4GMPS6VX.cjs.map → chunk-IRDL2EC6.cjs.map} +1 -1
  70. package/dist/{chunk-VJFU2KKF.cjs → chunk-J46Y2L26.cjs} +4 -4
  71. package/dist/{chunk-VJFU2KKF.cjs.map → chunk-J46Y2L26.cjs.map} +1 -1
  72. package/dist/{chunk-PVT4EZUR.cjs → chunk-KD37PODE.cjs} +5 -5
  73. package/dist/{chunk-PVT4EZUR.cjs.map → chunk-KD37PODE.cjs.map} +1 -1
  74. package/dist/{chunk-JGU6YLIA.cjs → chunk-KQJUY2OE.cjs} +11 -11
  75. package/dist/{chunk-JGU6YLIA.cjs.map → chunk-KQJUY2OE.cjs.map} +1 -1
  76. package/dist/{chunk-MXM4BTXY.cjs → chunk-KZH6HMJL.cjs} +4 -4
  77. package/dist/{chunk-MXM4BTXY.cjs.map → chunk-KZH6HMJL.cjs.map} +1 -1
  78. package/dist/{chunk-XKQKHXRU.cjs → chunk-L3MYUPSH.cjs} +5 -5
  79. package/dist/{chunk-XKQKHXRU.cjs.map → chunk-L3MYUPSH.cjs.map} +1 -1
  80. package/dist/{chunk-SNYCK354.cjs → chunk-LYDSETR7.cjs} +5 -5
  81. package/dist/{chunk-SNYCK354.cjs.map → chunk-LYDSETR7.cjs.map} +1 -1
  82. package/dist/{chunk-X6TSOKEP.cjs → chunk-LYJFE37D.cjs} +3 -3
  83. package/dist/{chunk-X6TSOKEP.cjs.map → chunk-LYJFE37D.cjs.map} +1 -1
  84. package/dist/{chunk-NBW67JUB.cjs → chunk-OHWYQI3B.cjs} +12 -12
  85. package/dist/{chunk-NBW67JUB.cjs.map → chunk-OHWYQI3B.cjs.map} +1 -1
  86. package/dist/{chunk-CM2LUZ7K.cjs → chunk-QDIIOZBP.cjs} +30 -30
  87. package/dist/{chunk-CM2LUZ7K.cjs.map → chunk-QDIIOZBP.cjs.map} +1 -1
  88. package/dist/{chunk-WXRAU2FF.cjs → chunk-QSY2VW7V.cjs} +6 -6
  89. package/dist/{chunk-WXRAU2FF.cjs.map → chunk-QSY2VW7V.cjs.map} +1 -1
  90. package/dist/{chunk-ZLOPSDVW.cjs → chunk-RNQ3MDTR.cjs} +4 -4
  91. package/dist/{chunk-ZLOPSDVW.cjs.map → chunk-RNQ3MDTR.cjs.map} +1 -1
  92. package/dist/{chunk-QOTDPA62.cjs → chunk-SXC4ZIN4.cjs} +10 -10
  93. package/dist/{chunk-QOTDPA62.cjs.map → chunk-SXC4ZIN4.cjs.map} +1 -1
  94. package/dist/{chunk-W7TSEN3J.cjs → chunk-TLIZD6DV.cjs} +6 -6
  95. package/dist/{chunk-W7TSEN3J.cjs.map → chunk-TLIZD6DV.cjs.map} +1 -1
  96. package/dist/{chunk-NS7PWOL7.cjs → chunk-VD3HI5RF.cjs} +3 -3
  97. package/dist/{chunk-NS7PWOL7.cjs.map → chunk-VD3HI5RF.cjs.map} +1 -1
  98. package/dist/{chunk-6N7QT2DH.cjs → chunk-VDHBLDQC.cjs} +3 -3
  99. package/dist/{chunk-6N7QT2DH.cjs.map → chunk-VDHBLDQC.cjs.map} +1 -1
  100. package/dist/{chunk-6ZJBUMNK.cjs → chunk-VDT7TEAH.cjs} +3 -3
  101. package/dist/{chunk-6ZJBUMNK.cjs.map → chunk-VDT7TEAH.cjs.map} +1 -1
  102. package/dist/{chunk-SKIQ54TG.cjs → chunk-VJHDCYKE.cjs} +13 -13
  103. package/dist/{chunk-SKIQ54TG.cjs.map → chunk-VJHDCYKE.cjs.map} +1 -1
  104. package/dist/{chunk-MWJPCTBV.cjs → chunk-XKXKEVHH.cjs} +6 -6
  105. package/dist/{chunk-MWJPCTBV.cjs.map → chunk-XKXKEVHH.cjs.map} +1 -1
  106. package/dist/{chunk-DJ7LSKBJ.cjs → chunk-XQPJWPWE.cjs} +3 -3
  107. package/dist/{chunk-DJ7LSKBJ.cjs.map → chunk-XQPJWPWE.cjs.map} +1 -1
  108. package/dist/{chunk-XYMM6ZPS.cjs → chunk-Z6M2CI63.cjs} +65 -65
  109. package/dist/{chunk-XYMM6ZPS.cjs.map → chunk-Z6M2CI63.cjs.map} +1 -1
  110. package/dist/collaboration/index.cjs +13 -13
  111. package/dist/connect/docx.cjs +23 -23
  112. package/dist/connect/index.cjs +1204 -1204
  113. package/dist/connect/viewer.cjs +41 -41
  114. package/dist/dashboards/index.cjs +1 -1
  115. package/dist/embed/index.cjs +48 -48
  116. package/dist/facts/index.cjs +39 -39
  117. package/dist/files/index.cjs +221 -221
  118. package/dist/home/index.cjs +9 -9
  119. package/dist/index.cjs +1797 -1797
  120. package/dist/pages/index.cjs +31 -31
  121. package/dist/record/band.d.ts +95 -0
  122. package/dist/record/index.cjs +414 -13
  123. package/dist/record/index.cjs.map +1 -1
  124. package/dist/record/index.d.ts +35 -2
  125. package/dist/record/index.js +402 -15
  126. package/dist/record/index.js.map +1 -1
  127. package/dist/record/narration.d.ts +71 -0
  128. package/dist/settings/index.cjs +139 -139
  129. package/dist/shell/index.cjs +81 -81
  130. package/dist/studio/index.cjs +29 -29
  131. package/dist/styles.css +1 -1
  132. package/dist/workflow-canvas/index.cjs +64 -64
  133. package/dist/workspaces/index.cjs +5 -5
  134. package/node_modules/@arbidocs/coedit/package.json +1 -1
  135. package/package.json +11 -6
  136. package/record/SKILL.md +178 -26
  137. package/record/mix-take.py +320 -0
  138. package/record/recap-slide.mjs +118 -0
  139. package/record/voice-take.py +129 -0
  140. package/dist/ai-2B4BMS6O.cjs.map +0 -1
package/record/SKILL.md CHANGED
@@ -1,25 +1,78 @@
1
1
  ---
2
2
  name: arbi-record-demo-video
3
- description: Record a custom site's demo video with @arbidocs/blocks/record — prepare a disposable workspace, drive the story with Playwright against the deployed backend, render the cut/zoomed/branded 1080p edit, check it, and deliver it to OVH. Use when asked to record, re-record or fix a demo/client video of any ARBI custom site (Clarum and the sites after it).
3
+ description: Record a custom site's demo video with @arbidocs/blocks/record in the house style (a caption band above the app, a strip below for the player's controls, a narrator's voice-over, a recap slide to close) — prepare a disposable workspace, drive the story with Playwright against the deployed backend, render and mix the branded 1080p video, check it, and deliver it without overwriting an earlier take. Use when asked to record, re-record or fix a demo/client video of any ARBI custom site (Clarum and the sites after it).
4
4
  ---
5
5
 
6
6
  # Recording a custom site's demo video
7
7
 
8
8
  Every custom site (a site = kits + config + content) records its demo videos the same way, with
9
- `@arbidocs/blocks/record`:
9
+ `@arbidocs/blocks/record`, and in the same style: **read [The house style](#the-house-style-the-default)
10
+ before writing a story.** The kit does most of it by default; the rest is how the story is written.
10
11
 
11
12
  | Piece | What it does |
12
13
  |-------|--------------|
13
- | `createCinematic({ brand, testIds })` | the stage: a cursor that glides, click ripples, `caption`, `chapter`/`cover`/`uncover`, `lowerThird`, `focusOn`, `readDown`; `click` waits for toasts first; `signInAs` |
14
+ | `createCinematic({ brand, testIds })` | the stage: a cursor that glides, `caption`, `chapter`/`cover`/`uncover`, `lowerThird`, `focusOn`, `readDown`; `click` waits for toasts first; `signInAs`. In the house style (`style: 'band'`, the default) it also frames the app: the caption band, the player strip, the click pulse; `feature`, `pulseAt`, `interlude`, `still` |
14
15
  | `cine.take(page, { name, dir })` / `Take` | the take's clock: logs waits (`take.wait`) and the focus timeline for the edit |
16
+ | `cine.narrator(take, '<story>')` / `Narrator` | the voice-over: `say(id)` captions a line in the band and holds while it is said, `hush()` waits for it to end; logs every line for the mix |
15
17
  | `createRunKit(cine, { prefix })` | following a workflow run: `driveRun`, `whileWorking`, `approveStep`, `pickTile`, `stepChip`, `currentStep`, `resumeRun` |
16
- | `openWordById`, `spaGo`, `fillSecret` | open a document by id in Word, navigate without a reload, type a password without recording it |
17
- | `arbidocs-record-take` (bin) | one take end to end: prepare → record → render → upload |
18
- | `arbidocs-render-take` (bin, `record/render-take.py`) | the edit alone: cut long waits, zoom/pan, picture-in-picture, brand overlays, 1080p H.264 |
18
+ | `openWordById`, `spaGo`, `fillSecret` | open a document by id in Word, navigate without a reload (off camera only), type a password without recording it |
19
+ | `arbidocs-voice-take` (bin, `record/voice-take.py`) | speak the narration script into one clip per line (the house voice), with a manifest the take is paced by |
20
+ | `arbidocs-record-take` (bin) | one take end to end: prepare → record → render → (`--narrate`) mix → upload |
21
+ | `arbidocs-render-take` (bin, `record/render-take.py`) | the edit alone: cut long waits, brand cards, 1080p H.264 (and, in `'overlay'`, zoom/pan, picture-in-picture, captions) |
22
+ | `arbidocs-mix-take` (bin, `record/mix-take.py`) | lay the voice on the edit, close on the recap slide, `--publish` as the next take |
19
23
 
20
24
  The site keeps only what is its own: its brand (`CinematicBrand` from its theme tokens and font
21
- files), its stories (`e2e/record/*.record.ts`), its fixtures and its workspace prepare script.
22
- Labels on screen (chapter cards, lower-thirds, captions) come from the story, never from the kit.
25
+ files), its stories (`e2e/record/*.record.ts`) and their narration scripts
26
+ (`e2e/record/<story>.narration.json`), its fixtures and its workspace prepare script.
27
+ Words on screen (the band's feature names and captions, chapter cards, the recap) come from the
28
+ story, never from the kit.
29
+
30
+ ## The house style (the default)
31
+
32
+ These rules hold for every demo video. "Kit" means `createCinematic` does it unless the story
33
+ passes `style: 'overlay'`; "story" means it is up to how the story is written, so check it in the
34
+ frames before publishing.
35
+
36
+ 1. **Captions never sit on the app** *(kit)*. They go in a band at the top, with the feature being
37
+ shown named on its left for the whole section: `cine.feature(page, kicker, name)` at the start
38
+ of each scene.
39
+ 2. **A strip at the bottom of the frame stays empty** *(kit)*, so a video player's pause/seek bar
40
+ covers nothing of the app. Chrome's controls are about 56 CSS px tall whatever the video's size,
41
+ so a 1600x900 video shown at 0.68 scale needs about 82 px clear: the strip is 84 px
42
+ (`PLAYER_STRIP`; 64 px was measured too small). A site's own elements sized from the viewport
43
+ are refitted with `band.css` (see [Consistent styling](#consistent-styling-across-sites)).
44
+ 3. **Captions appear fast, a phrase at a time** *(kit)*: up to 3 words, about 0.1 s apart, not one
45
+ word at a time and not all at once; they stay while their line is spoken.
46
+ 4. **Captions read as a narrator explaining how the platform works** *(story)*: "Notice the
47
+ colours: amber means private…", not titles or labels.
48
+ 5. **A voice-over of the narration, and the take paced by the voice** *(kit + story)*, so the edit
49
+ never cuts into a sentence. Start each line as the screen begins to change
50
+ (`voice.say(id, { over: true })`), so the speech covers the change instead of waiting for it:
51
+ speech cannot be cut, and silence between lines makes the video long.
52
+ 6. **The last slide reads as a conclusion** *(kit, from the script's `recap`)*: a recap of what was
53
+ shown, a closing line, a thank-you; not just another chapter card. `arbidocs-mix-take` refuses a
54
+ script without one.
55
+ 7. **The frame holds still into and out of each chapter card** *(story; `cine.still`)*: no dialog
56
+ closing, caption clearing or toast moving under the card's fade. Call `voice.hush()`, clear the
57
+ caption and `await cine.still(page)` before a card.
58
+ 8. **Every click shows a visible pulse** *(kit)*. For a pick the test makes without a pointer press
59
+ (a native select's option, a file chosen for an upload), `cine.pulseAt(page, box)`.
60
+ 9. **Every navigation happens through a visible click with a bridging caption** *(story)*, never a
61
+ jump (`spaGo`, `page.goto`) on camera. Jumps are for setup behind a card.
62
+ 10. **What the video is about must be obvious at a glance** *(story)*: e.g. private and shared
63
+ documents told apart in the gallery by more than two grey pills that look alike. If the app
64
+ does not show it clearly, fix the app before the take.
65
+ 11. **A published take is never overwritten** *(kit)*. Each take is published under its own name
66
+ (`<site>-<story>.take<N>.narrated.mp4`, `arbidocs-mix-take --publish <dir>`) and added as a new
67
+ row on the page that lists the recordings; earlier files and rows stay. In the archive, a
68
+ second upload of a story on one day goes to `<date>-<story>.take2.mp4`. Never copy a video onto
69
+ an existing file (viewers also get the old one from their browser's cache at the same URL).
70
+
71
+ The format: a 1600x900 page, rendered to 1920x1080 H.264 at 25 fps with AAC audio (MP4). The voice: Kokoro's `bf_lily`, British English (see [The voice](#the-voice)). Keep a
72
+ video as short as its story allows; the narrated video's length is in `.narrated.json`.
73
+
74
+ `style: 'overlay'` is the earlier look (captions drawn by the edit over the app, zoom and
75
+ picture-in-picture, no voice): only for a recording that already exists in it.
23
76
 
24
77
  ## Prerequisites
25
78
 
@@ -28,8 +81,12 @@ Labels on screen (chapter cards, lower-thirds, captions) come from the story, ne
28
81
  the site's prepare script must refuse any other account.
29
82
  - **A deployed backend** (the site itself, or the site's dev server proxied to the deployed
30
83
  backend). Never a local mock: the video shows the real AI.
31
- - For the render: `python3` with `numpy` and `opencv-python` (`RENDER_VENV=<venv>` puts a venv's
32
- python first), `ffmpeg`, and Playwright's Chromium (it draws the overlays).
84
+ - For the render and the mix: `python3` with `numpy` and `opencv-python` (`RENDER_VENV=<venv>`
85
+ puts a venv's python first), `ffmpeg`, and Playwright's Chromium (it draws the cards and the
86
+ recap slide).
87
+ - For the voice: see [The voice](#the-voice) (`VOICE_VENV=<venv>`).
88
+ - A story that plays H.264 video on camera needs Google Chrome (`channel: 'chrome'` in the record
89
+ config): Playwright's own Chromium has no H.264 decoder.
33
90
  - For delivery: the aws CLI with the OVH S3 keys in its environment (`AWS_ACCESS_KEY_ID` /
34
91
  `AWS_SECRET_ACCESS_KEY`; they are `vault_s3_access_key` / `vault_s3_secret_key` in
35
92
  arbicity/ansible's vault — extract those two keys with a regex, never pipe the vault into a
@@ -48,32 +105,85 @@ It runs the prepare command (skipped for a resumed take), then
48
105
  `<videos>/<site>-<story>.webm` with its `.waits.json` / `.focus.json` to `<site>-<story>.cut.mp4`,
49
106
  and with `--upload` copies a passed, non-resumed take to
50
107
  `s3://arbi-archive/demo-videos/<site>/<YYYY-MM-DD>-<story>.mp4` (OVH UK,
51
- `https://s3.uk.io.cloud.ovh.net`) and prints a 7-day presigned link. Options: `--config`,
52
- `--videos` (default `e2e/videos`), `--name`, `--out`, `--date`, and renderer flags after `--`
53
- (`-- --max-zoom 1.6 --no-pip`). It exits with the recording's status: a failed take still renders
54
- what it recorded, to see where it stopped.
108
+ `https://s3.uk.io.cloud.ovh.net`) and prints a 7-day presigned link (a story already delivered
109
+ that day goes to `.take2.mp4`, never over the first). Options: `--config`, `--videos` (default
110
+ `e2e/videos`), `--name`, `--out`, `--date`, and renderer flags after `--` (`-- --head 1 --tail 0.6`).
111
+ For a story with a voice-over add `--narrate` (and `--speed 1.2`, `--publish <dir>`): it then mixes
112
+ the voice and delivers `<site>-<story>.narrated.mp4`. It exits with the recording's status: a
113
+ failed take still renders what it recorded, to see where it stopped.
55
114
 
56
115
  A site usually wraps it in a two-line script (Clarum: `e2e/record/tools/take.sh`).
57
116
 
117
+ ## A narrated video, end to end
118
+
119
+ 1. **Write the script**, `e2e/record/<story>.narration.json`: the lines the narrator says, in the
120
+ words of rule 4, and the recap slide.
121
+
122
+ ```json
123
+ {
124
+ "voice": "bf_lily", "lang": "en-gb", "speed": 1,
125
+ "lines": [
126
+ { "id": "intro", "text": "This is Clarum. Let's follow one investigation." },
127
+ { "id": "upload", "text": "Evidence arrives from anywhere: a folder, a mailbox, a ZIP.", "speech": "…" }
128
+ ],
129
+ "recap": {
130
+ "kicker": "Project Harrier · Recap", "title": "From evidence to answers.",
131
+ "lede": "One investigation, start to finish, in one secure workspace.",
132
+ "points": [{ "title": "Every source, one workspace", "detail": "…", "line": "outro-2" }],
133
+ "open": "outro-1", "close": "outro-3", "closing": "Thank you for watching"
134
+ },
135
+ "spoken": [["\\bZIP\\b", "zip"]]
136
+ }
137
+ ```
138
+
139
+ `text` is what the band shows; `speech` (or the `spoken` rules) is what is said when that
140
+ differs. `recap.open`, each point's `line` and `recap.close` are ids of lines said over the
141
+ slide: each point is ticked as the voice names it.
142
+ 2. **Write the story** with `cine.narrator` (below). Rehearse it before speaking anything: without
143
+ clips a line lasts as long as it takes to read, and the take still runs.
144
+ 3. **Speak the script**: `npx arbidocs-voice-take e2e/record/<story>.narration.json
145
+ e2e/videos/narration/<story> --model <kokoro dir>`. Only changed lines are spoken again.
146
+ 4. **Record, render, mix**: `npx arbidocs-record-take --site <site> --story <story> --grep "<title>"
147
+ --narrate --speed 1.2 --publish public/recordings -- --head 1 --tail 0.6` (or the steps one by
148
+ one: `arbidocs-render-take`, then `arbidocs-mix-take <story> --site <site>`).
149
+ 5. **Check it** (rule by rule, in the frames), read `.narrated.json`'s `problems` (a line the edit
150
+ cut into, a line not said, a caption that showed late), and compare the lines said with the
151
+ script.
152
+ 6. **Publish as a new take** (rule 11) and add its row to the recordings page.
153
+
58
154
  ## Writing a story
59
155
 
60
156
  ```ts
61
157
  const cine = createCinematic({ brand: SITE_BRAND, testIds: { email: 'email-input', … } })
62
158
  const runs = createRunKit(cine, { prefix: 'run' }) // the runner's testIdPrefix
63
159
 
64
- test('Client onboarding', async ({ page }) => {
65
- const take = await cine.take(page, { name: 'site-20-onboarding', dir: 'e2e/videos' })
66
- await cine.installStage(page)
160
+ test('From evidence to answers', async ({ page }) => {
161
+ const take = await cine.take(page, { name: 'site-32-demo', dir: 'e2e/videos' })
162
+ const voice = cine.narrator(take, '32-demo') // e2e/record/32-demo.narration.json
163
+ await cine.installStage(page) // the stage, the band, the strip
67
164
  await take.markSync() // before the first navigation
68
165
  await page.goto('/app/login')
69
- await cine.chapter(page, { kicker: 'Onboarding', title: '…' }) // setup behind the card
166
+ await voice.say('intro', { over: true, caption: false }) // said over the title card
167
+ await cine.chapter(page, { kicker: 'Evidence & AI', title: '…' }, 8600) // setup behind the card
70
168
  … sign in, open the workspace …
71
169
  await cine.uncover(page)
72
- if (!(await runs.resumeRun(page, { readyTestId: 'page-run' }))) { … start the run … }
73
- await runs.driveRun(take, { ai: ['conflicts'], captions: { … }, handlers: { … } })
170
+
171
+ await cine.feature(page, 'Part 1 · Evidence', 'Bringing files in') // named in the band
172
+ await voice.say('upload', { over: true }) // starts as the screen changes
173
+ await cine.click(page, 'add-button') // a visible click, with its pulse
174
+ await voice.hush() // before a wait the edit may cut
175
+ await take.wait('indexing', () => expect(row).toHaveText(/Indexed/))
176
+
177
+ await voice.hush(); await cine.clearCaption(page); await cine.still(page) // a still frame…
178
+ await voice.say('ch2', { over: true, caption: false })
179
+ await cine.interlude(page, { kicker: 'Part 2', title: 'Search and answers' }, 3200) // …then the card
74
180
  })
75
181
  ```
76
182
 
183
+ A workflow run is followed with the run kit as before:
184
+ `await runs.driveRun(take, { ai: ['conflicts'], captions: { … }, handlers: { … } })`; its captions
185
+ go to the band.
186
+
77
187
  The record config: `video: { mode: 'on', size: { width: 1600, height: 900 } }` and the same
78
188
  viewport, `workers: 1`, a long `timeout`; the edit scales 1600x900 to 1080p.
79
189
 
@@ -118,12 +228,54 @@ viewport, `workers: 1`, a long `timeout`; the edit scales 1600x900 to 1080p.
118
228
  brand into `focus.json`; the overlays are drawn from it.
119
229
  - **1600x900 → 1080p.** Record at 1600x900 CSS pixels (video size = viewport); `render-take.py`
120
230
  outputs 1920x1080 H.264 at 25 fps. A take of another shape is letterboxed.
121
- - **Overlays from the edit.** With a take running, captions, chapter cards, lower-thirds and
122
- callouts are drawn by `render-take.py` (`render-overlays.mjs` PNGs), outside any zoom — never
123
- painted in the page. Check one still of each kind against the site's look: the card gradient
124
- (`cover`), the accent rule and kicker, the caption bar (`ink`), the cursor colour.
125
- - **The camera.** Zoom at most `maxZoom` (default 1.8), picture-in-picture for long typing; turn
126
- either off per story in `cine.take` (`zoom: false`, `pip: false`) rather than per render.
231
+ - **The band is the frame, not part of the app.** Its accent comes from the
232
+ brand; its dark ground and its typeface (Space Grotesk by default) are apart from the app's on purpose. The band
233
+ shrinks the app's root (`#root`, or `band.root`) to the space between band and strip, and
234
+ refits Tailwind's `h-screen`/`h-dvh` classes. A site's own heights sized from the viewport
235
+ (`h-[calc(100dvh-11rem)]`…) stay too tall and clip the page's bottom (a hidden bulk bar, a cut
236
+ composer): refit each in `createCinematic({ band: { css } })` with `BAND_FRAME`, e.g.
237
+ `` `[class~="h-[calc(100dvh-11rem)]"] { height: calc(${BAND_FRAME} - 11rem) !important; }` ``.
238
+ - **Cards from the edit.** With a take running, full-screen chapter cards (`chapter`/`cover`),
239
+ lower-thirds and callouts are drawn by `render-take.py` (`render-overlays.mjs` PNGs). The edit
240
+ fades a card in over the 0.4 s *before* `chapter()` was called, so the page must already be
241
+ still then (rule 7). `interlude` is a card painted in the page, over the dimmed app. Check one
242
+ still of each kind against the site's look: the card gradient (`cover`), the accent rule and
243
+ kicker, the band, the cursor colour.
244
+ - **The camera.** The band style does not zoom (a zoom crops the band) and has no
245
+ picture-in-picture. In `'overlay'`: zoom at most `maxZoom` (default 1.8), picture-in-picture for
246
+ long typing; turn either off per story in `cine.take` rather than per render.
247
+
248
+ ## The voice
249
+
250
+ The house voice is **Kokoro `bf_lily`, British English, speed 1**: an 82M-parameter model that
251
+ runs offline on a CPU. Set up once: `pip install kokoro-onnx soundfile` in a venv
252
+ (`VOICE_VENV=<venv>`), and a folder holding `model.onnx` and `voices/bf_lily.bin` from the Hugging
253
+ Face repo `onnx-community/Kokoro-82M-v1.0-ONNX` (`--model <folder>`).
254
+
255
+ A script may instead set `"engine": "chatterbox"` (with `exaggeration`, `cfg`) to clone the voice
256
+ of a reference clip (`--ref <clip.wav>`; `pip install chatterbox-tts`). It sounds more natural and
257
+ is far heavier: about 4.6 GB of memory on a machine without a GPU, so never while a take is
258
+ recording. The reference clip is the voice: keep it with the site's recordings, and use the same
259
+ clip for every video of a series.
260
+
261
+ - **Speech cannot be cut, so a voice-over lengthens the edit**: the take's waits finish under the
262
+ voice. Start lines as the screen begins to change (rule 5) and read the gaps in `.narrated.json`.
263
+ - **Hush first.** `voice.hush()` before any `take.wait` and before a card. A line said over a card
264
+ must fit inside the card's hold, and uses `caption: false`: a caption painted under a fading
265
+ card shows as a change.
266
+ - **Narrated stretches are logged** as focus events over the band (`say` does it), or the edit's
267
+ dead-air rule (12 s with nothing logged) cuts them. A long silent hold the story wants kept needs
268
+ its own `take.record({ kind: 'read', mode: 'none', … })`.
269
+ - **Kokoro's speed is not linear** (1.05 shortens a line by about 2.4%); speed the finished video
270
+ up instead (`--speed 1.2`: the voice keeps its pitch).
271
+ - **Pronunciation.** The phonemiser misreads some names, stresses, acronyms mid-sentence ("ZIP")
272
+ and times ("08:00" as digits). Fix them in the script: `speech` for one line, `spoken` rules for
273
+ every line, `phonemes` (Kokoro) or `respell` (Chatterbox) for a name. Listen to each new line.
274
+ - **Never edit the site's files during a take**: a dev server reloads the page, and a reload in
275
+ the middle of an upload skips it. Voice, render and mix only between takes.
276
+ - **The AI's free prose slips.** Its tables and totals are usually right; a sentence around them
277
+ may not be ("9 of 10 approved" when 8 were). Check what is on screen against the fixtures before
278
+ publishing, not only the log.
127
279
 
128
280
  ## Audio and captured video clocks
129
281
 
@@ -0,0 +1,320 @@
1
+ """Lay a narrated take's voice on its edit, and close the edit on the recap slide.
2
+
3
+ arbidocs-mix-take <story stem> --site <site> [--videos e2e/videos] [--script <story>.narration.json]
4
+ [--clips <dir>] [--recap recap] [--no-recap] [--speed 1.2] [--out <mp4>] [--publish <dir>]
5
+
6
+ Run from the site's root after the edit (`arbidocs-render-take`). For <videos>/<site>-<stem>.* it
7
+ reads the take (.webm, for its clock), the edit (.cut.mp4 and .cut.plan.json), the focus timeline
8
+ (.focus.json: the brand) and the narration log (.narration.json: each line's start on the take's
9
+ clock); the clips and their manifest (<videos>/narration/<stem>/); and the story's script
10
+ (e2e/record/<stem>.narration.json), whose `recap` is the closing slide.
11
+
12
+ A line starts on the edit where its start falls there, mapped as render-take.py maps everything:
13
+ the take's clock onto the video's (the timecode in its frames), then the edit's cuts. The edit's
14
+ closing card gives way to the recap slide (recap-slide.mjs), its points ticked off as the voice
15
+ names them: the last slide of a video is a conclusion (a recap of what was shown, a closing line,
16
+ a thank-you), never just another chapter card. Writes <site>-<stem>.narrated.mp4 and, beside it,
17
+ .narrated.json: where every line landed, and what to look at (`problems`).
18
+
19
+ `--publish <dir>` copies the video there as `<site>-<stem>.take<N>.narrated.mp4`, N one more than
20
+ the takes already there: a published take is never overwritten.
21
+
22
+ Needs ffmpeg, node (with @playwright/test) and the python render-take.py needs (numpy, opencv).
23
+ """
24
+ import argparse
25
+ import importlib.util
26
+ import json
27
+ import re
28
+ import shutil
29
+ import subprocess
30
+ import sys
31
+ import tempfile
32
+ from pathlib import Path
33
+
34
+ HERE = Path(__file__).resolve().parent
35
+ RENDER = HERE / "render-take.py"
36
+ RECAP = HERE / "recap-slide.mjs"
37
+ FPS = 25
38
+ XFADE = 0.6 # s: the edit's last frame dissolves into the slide
39
+ LEAD = 0.7 # s from the slide's first frame to its first line
40
+ GAP = 0.6 # s between the slide's lines
41
+ STEP_FADE = 0.3 # s: a point's tick dissolving in
42
+ HOLD = 2.0 # s on the slide after its last line
43
+ FADE_OUT = 1.0 # s to black, at the very end
44
+ # The band's captions in the page (src/record/band.ts: a 64 px band, its label 360 px wide), a
45
+ # little inside their edges.
46
+ BAND_CAPTIONS = (367, 3.4, 1583, 60)
47
+
48
+
49
+ def run(cmd):
50
+ done = subprocess.run(cmd, capture_output=True, text=True)
51
+ if done.returncode:
52
+ sys.exit(f"{cmd[0]} failed:\n{done.stderr[-3000:]}")
53
+ return done.stdout
54
+
55
+
56
+ def load_render():
57
+ spec = importlib.util.spec_from_file_location("render_take", RENDER)
58
+ module = importlib.util.module_from_spec(spec)
59
+ spec.loader.exec_module(module)
60
+ return module
61
+
62
+
63
+ def next_take(existing, base, suffix):
64
+ """The name a new take is published under: `<base>.take<N><suffix>`, N one more than the highest
65
+ take among `existing` names (1 when there is none). Earlier takes keep their names."""
66
+ pattern = re.compile(re.escape(base) + r"\.take(\d+)" + re.escape(suffix) + "$")
67
+ taken = [int(m.group(1)) for m in map(pattern.match, existing) if m]
68
+ return f"{base}.take{max(taken, default=0) + 1}{suffix}"
69
+
70
+
71
+ def publish(video, folder, base):
72
+ """Copy `video` into `folder` under the next take's name, never onto an existing file."""
73
+ folder = Path(folder)
74
+ folder.mkdir(parents=True, exist_ok=True)
75
+ target = folder / next_take([p.name for p in folder.iterdir()], base, ".narrated.mp4")
76
+ with open(video, "rb") as src, open(target, "xb") as dst: # "x": fails if it exists
77
+ shutil.copyfileobj(src, dst)
78
+ return target
79
+
80
+
81
+ def caption_box(frame_width, page_width):
82
+ """Where the band's captions are in the edit's frames (x0, y0, x1, y1)."""
83
+ s = frame_width / page_width
84
+ x0, y0, x1, y1 = BAND_CAPTIONS
85
+ return round(x0 * s), round(y0 * s), round(x1 * s), round(y1 * s)
86
+
87
+
88
+ def take_clock(rt, src, tl):
89
+ """render-take.py's clock (take seconds -> video seconds): the timecode, else the sync marker, else
90
+ the cards' dark frames."""
91
+ import numpy as np
92
+ sw, sh, _ = rt.probe(src)
93
+ vp = tl.get("viewport") or {}
94
+ clock = rt.read_timecode(src, vp.get("width", sw), vp.get("height", sh), sw, sh) if tl.get("focus") is not None else None
95
+ offset = 0.0
96
+ if clock is None and tl.get("sync") is not None:
97
+ at = rt.find_sync(src, tl["sync"])
98
+ if at is not None:
99
+ offset = at - tl["sync"]
100
+ if clock is None and tl.get("cards") and tl.get("focus") is not None:
101
+ clock = rt.card_anchors(src, tl["cards"], offset)
102
+
103
+ def v(t):
104
+ if not clock:
105
+ return t + offset
106
+ tt, vt = clock
107
+ if t <= tt[0]:
108
+ return vt[0] + (t - tt[0])
109
+ if t >= tt[-1]:
110
+ return vt[-1] + (t - tt[-1])
111
+ return float(np.interp(t, tt, vt))
112
+
113
+ return v, (f"timecode, {len(clock[0])} anchors" if clock else f"offset {offset:+.2f} s")
114
+
115
+
116
+ def caption_onset(video, at, box, before=0.25, after=3.0):
117
+ """When a line's caption shows in the band: the first frame from just before its voice that
118
+ differs, with text in the band a moment later (a caption clearing is not the next one showing).
119
+ None if nothing shows."""
120
+ import numpy as np
121
+ x0, y0, x1, y1 = box
122
+ w, h = x1 - x0, y1 - y0
123
+ raw = subprocess.run(["ffmpeg", "-v", "error", "-ss", f"{max(at - before, 0):.3f}", "-i", str(video), "-t", f"{before + after:.3f}",
124
+ "-vf", f"fps={FPS},crop={w}:{h}:{x0}:{y0},format=gray", "-f", "rawvideo", "-"],
125
+ capture_output=True, check=True).stdout
126
+ f = np.frombuffer(raw, np.uint8).reshape(-1, h, w).astype(np.int16)
127
+ if not len(f):
128
+ return None
129
+ text = (f > 150).sum(axis=(1, 2))
130
+ for i in range(1, len(f)):
131
+ if (np.abs(f[i] - f[0]) > 60).sum() > 120 and text[min(i + 5, len(f) - 1)] > 80:
132
+ return max(at - before, 0) + i / FPS
133
+ return None
134
+
135
+
136
+ def recap_lines(recap):
137
+ """The script lines the recap slide is said with, in order: its opening, a line per point, its close."""
138
+ return [recap["open"], *[p["line"] for p in recap["points"]], recap["close"]]
139
+
140
+
141
+ def recap_slide(rt_dims, brand, recap, manifest, work):
142
+ """The slide's steps as PNGs, and when each shows and each line is said (slide seconds)."""
143
+ w, h = rt_dims
144
+ spec = work / "recap.json"
145
+ spec.write_text(json.dumps({"width": w, "height": h, "brand": brand, "recap": recap}))
146
+ run(["node", str(RECAP), str(spec), str(work / "recap")])
147
+ lines, t = [], LEAD
148
+ for line in recap_lines(recap):
149
+ lines.append({"id": line, "at": round(t, 3), "duration": manifest[line]["duration"], "file": manifest[line]["file"]})
150
+ t += manifest[line]["duration"] + GAP
151
+ length = t - GAP + HOLD
152
+ said = {l["id"]: l["at"] for l in lines}
153
+ steps = [("step-0", 0.0)] + [(f"step-{i + 1}", said[p["line"]] + 0.1) for i, p in enumerate(recap["points"])]
154
+ steps.append(("step-final", said[recap["close"]]))
155
+ return steps, lines, length
156
+
157
+
158
+ def slide_video(steps, length, work):
159
+ """The steps, each dissolving into the next as it shows, and a fade to black at the end."""
160
+ out = work / "slide.mp4"
161
+ cmd = ["ffmpeg", "-v", "error", "-y"]
162
+ for i, (name, at) in enumerate(steps):
163
+ until = steps[i + 1][1] + STEP_FADE if i + 1 < len(steps) else length
164
+ cmd += ["-loop", "1", "-framerate", str(FPS), "-t", f"{until - at:.3f}", "-i", str(work / "recap" / f"{name}.png")]
165
+ graph, last = [], "0:v"
166
+ for i in range(1, len(steps)):
167
+ graph.append(f"[{last}][{i}:v]xfade=transition=fade:duration={STEP_FADE}:offset={steps[i][1]:.3f}[x{i}]")
168
+ last = f"x{i}"
169
+ graph.append(f"[{last}]fade=t=out:st={length - FADE_OUT:.3f}:d={FADE_OUT},format=yuv420p[v]")
170
+ run(cmd + ["-filter_complex", ";".join(graph), "-map", "[v]", "-r", str(FPS), "-c:v", "libx264", "-preset", "medium",
171
+ "-crf", "18", "-pix_fmt", "yuv420p", str(out)])
172
+ return out
173
+
174
+
175
+ def main():
176
+ ap = argparse.ArgumentParser()
177
+ ap.add_argument("stem", help="the story, e.g. 32-demo-5min")
178
+ ap.add_argument("--site", required=True)
179
+ ap.add_argument("--videos", default="e2e/videos", help="where the take's files are")
180
+ ap.add_argument("--script", help="the story's narration script (default e2e/record/<stem>.narration.json)")
181
+ ap.add_argument("--clips", help="the spoken clips and their manifest (default <videos>/narration/<stem>)")
182
+ ap.add_argument("--recap", default="recap", help="the script's key holding the recap slide (a story with two endings has two)")
183
+ ap.add_argument("--no-recap", action="store_true", help="a clip that is part of a longer video: no closing slide")
184
+ ap.add_argument("--out")
185
+ ap.add_argument("--publish", help="copy the video to this folder as the next take, never over an earlier one")
186
+ ap.add_argument("--speed", type=float, default=1.0,
187
+ help="play the narrated video this much faster (1.2: a sixth shorter), the voice kept at its pitch")
188
+ args = ap.parse_args()
189
+ if not 0.5 <= args.speed <= 2.0:
190
+ ap.error("--speed must be between 0.5 and 2 (ffmpeg's atempo range)")
191
+
192
+ name = f"{args.site}-{args.stem}"
193
+ base = Path(args.videos) / name
194
+
195
+ def beside(suffix): # a story stem may hold dots: never Path.with_suffix
196
+ return base.parent / f"{base.name}{suffix}"
197
+
198
+ src, cut = beside(".webm"), beside(".cut.mp4")
199
+ plan = json.loads(beside(".cut.plan.json").read_text())
200
+ tl = json.loads(beside(".focus.json").read_text())
201
+ said = json.loads(beside(".narration.json").read_text())["lines"]
202
+ clips = Path(args.clips) if args.clips else Path(args.videos) / "narration" / args.stem
203
+ manifest = json.loads((clips / "manifest.json").read_text())["lines"]
204
+ script = json.loads(Path(args.script or f"e2e/record/{args.stem}.narration.json").read_text())
205
+ recap = None if args.no_recap else script.get(args.recap)
206
+ if recap is None and not args.no_recap:
207
+ sys.exit(f'the script has no "{args.recap}": a video ends on a recap slide (see record/SKILL.md), '
208
+ "or pass --no-recap for a clip that is part of a longer video")
209
+ if recap:
210
+ unspoken = [line for line in recap_lines(recap) if line not in manifest]
211
+ if unspoken:
212
+ sys.exit(f"the recap's lines are not spoken yet (arbidocs-voice-take): {', '.join(unspoken)}")
213
+ out = Path(args.out) if args.out else beside(".narrated.mp4")
214
+ out.parent.mkdir(parents=True, exist_ok=True)
215
+
216
+ rt = load_render()
217
+ v, how = take_clock(rt, str(src), tl)
218
+ cuts = [tuple(c) for c in plan["cuts"]]
219
+ m = rt.make_map(cuts)
220
+ print(f"clock: {how}; {len(cuts)} cuts; edit {plan['duration']:.1f} s")
221
+
222
+ # 1. Each line where it starts on the edit; a line the edit cuts into, or that runs into the next, is reported.
223
+ placed, problems = [], []
224
+ for line in said:
225
+ if not line.get("file"):
226
+ problems.append(f"{line['id']}: no clip (not spoken when the take ran), left silent")
227
+ continue
228
+ a, b = v(line["start"]), v(line["start"] + line["duration"])
229
+ into = [c for c in cuts if c[0] < b - 0.05 and c[1] > a + 0.05]
230
+ placed.append({**line, "at": round(m(a), 3), "cutInto": [c[2] for c in into]})
231
+ # A caption the page painted late (it was busy): the voice waits for it. Only ever later.
232
+ box = caption_box(rt.W, (tl.get("viewport") or {}).get("width", 1600))
233
+ for p in placed:
234
+ if p.get("caption") is False:
235
+ continue
236
+ shown = caption_onset(cut, p["at"], box)
237
+ if shown is not None and shown - p["at"] > 0.15:
238
+ problems.append(f"{p['id']}: its caption showed {shown - p['at']:.2f} s after the voice was due: the voice waits for it")
239
+ p["at"] = round(shown, 3)
240
+ placed.sort(key=lambda p: p["at"])
241
+ for prev, p in zip(placed, placed[1:]):
242
+ if p["at"] < prev["at"] + prev["duration"] - 0.05:
243
+ problems.append(f"{p['id']} starts {prev['at'] + prev['duration'] - p['at']:.2f} s before {prev['id']} ends: moved after it")
244
+ p["at"] = round(prev["at"] + prev["duration"] + 0.45, 3)
245
+ problems += [f"{p['id']}: the edit cuts into it ({', '.join(p['cutInto'])})" for p in placed if p["cutInto"]]
246
+
247
+ # 2. The edit up to its closing card, then the recap slide.
248
+ end_card = plan["cards"][-1] if plan["cards"] and plan["cards"][-1].get("kind") == "end" else None
249
+ t_end = end_card["start"] if end_card and recap else plan["duration"]
250
+ late = [p["id"] for p in placed if p["at"] + p["duration"] > t_end + 0.05]
251
+ if late:
252
+ problems.append(f"said past the end of the edit{' (its closing card gives way to the slide)' if recap else ''}: {', '.join(late)}")
253
+ w, h = rt.W, rt.H
254
+ with tempfile.TemporaryDirectory() as tmp:
255
+ work = Path(tmp)
256
+ video = work / "video.mp4"
257
+ steps, start, length = [], t_end, 0.0
258
+ if recap:
259
+ steps, slide_lines, length = recap_slide((w, h), tl.get("brand") or {}, recap, manifest, work)
260
+ slide = slide_video(steps, length, work)
261
+ start = t_end - XFADE
262
+ for line in slide_lines:
263
+ placed.append({"id": line["id"], "start": None, "duration": line["duration"], "file": str(clips / line["file"]),
264
+ "at": round(start + line["at"], 3), "cutInto": []})
265
+ run(["ffmpeg", "-v", "error", "-y", "-i", str(cut), "-i", str(slide), "-filter_complex",
266
+ f"[0:v]trim=end={t_end:.3f},setpts=PTS-STARTPTS,fps={FPS},format=yuv420p,settb=AVTB[m];"
267
+ f"[1:v]fps={FPS},format=yuv420p,settb=AVTB[s];"
268
+ f"[m][s]xfade=transition=fade:duration={XFADE}:offset={start:.3f},format=yuv420p[v]",
269
+ "-map", "[v]", "-c:v", "libx264", "-preset", "medium", "-crf", "18", "-pix_fmt", "yuv420p", str(video)])
270
+ else:
271
+ run(["ffmpeg", "-v", "error", "-y", "-i", str(cut), "-an", "-vf", f"fps={FPS},format=yuv420p",
272
+ "-c:v", "libx264", "-preset", "medium", "-crf", "18", "-pix_fmt", "yuv420p", str(video)])
273
+ total = start + length
274
+
275
+ # 3. The voice: every clip at its time over silence the video's length, levelled for speech.
276
+ audio = work / "voice.m4a"
277
+ cmd = ["ffmpeg", "-v", "error", "-y", "-f", "lavfi", "-t", f"{total:.3f}", "-i", "anullsrc=r=24000:cl=mono"]
278
+ graph = []
279
+ for i, p in enumerate(placed, start=1):
280
+ cmd += ["-i", p["file"]]
281
+ graph.append(f"[{i}:a]adelay=delays={max(0, round(p['at'] * 1000))}:all=1[a{i}]")
282
+ graph.append("[0:a]" + "".join(f"[a{i}]" for i in range(1, len(placed) + 1))
283
+ + f"amix=inputs={len(placed) + 1}:duration=first:normalize=0,loudnorm=I=-16:TP=-1.5:LRA=11,aresample=48000[out]")
284
+ run(cmd + ["-filter_complex", ";".join(graph), "-map", "[out]", "-c:a", "aac", "-b:a", "160k", str(audio)])
285
+
286
+ if args.speed == 1:
287
+ run(["ffmpeg", "-v", "error", "-y", "-i", str(video), "-i", str(audio), "-map", "0:v", "-map", "1:a",
288
+ "-c", "copy", "-shortest", "-movflags", "+faststart", str(out)])
289
+ else:
290
+ # Faster as a whole: the picture's clock and the voice's tempo together (atempo keeps the pitch).
291
+ run(["ffmpeg", "-v", "error", "-y", "-i", str(video), "-i", str(audio), "-filter_complex",
292
+ f"[0:v]setpts=PTS/{args.speed},fps={FPS}[v];[1:a]atempo={args.speed}[a]", "-map", "[v]", "-map", "[a]",
293
+ "-c:v", "libx264", "-preset", "medium", "-crf", "18", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "160k",
294
+ "-shortest", "-movflags", "+faststart", str(out)])
295
+
296
+ # Times on the delivered video's clock (a line's `start` stays on the take's).
297
+ k = args.speed
298
+ scripted = [line["id"] for line in script["lines"]]
299
+ unsaid = [i for i in scripted if i not in {p["id"] for p in placed}]
300
+ if unsaid:
301
+ problems.append(f"in the script but not said in this take: {', '.join(unsaid)}")
302
+ report = {"video": str(out), "speed": k, "duration": round(total / k, 2), "editEnd": round(t_end / k, 3),
303
+ "slide": {"start": round(start / k, 3), "length": round(length / k, 3),
304
+ "steps": [{"step": s, "at": round((start + at) / k, 3)} for s, at in steps]} if recap else None,
305
+ "lines": [{"id": p["id"], "start": p["start"], "at": round(p["at"] / k, 3), "duration": round(p["duration"] / k, 3)}
306
+ for p in sorted(placed, key=lambda p: p["at"])],
307
+ "problems": problems}
308
+ out.parent.joinpath(out.name[: -len(out.suffix)] + ".json").write_text(json.dumps(report, indent=1))
309
+ speech = sum(p["duration"] for p in placed)
310
+ print(f"{len(placed)} lines ({speech / k:.1f} s of voice) on {total / k:.1f} s of video at {k}x"
311
+ + (f"; the slide from {start / k:.1f} s" if recap else ""))
312
+ for p in problems:
313
+ print(f"warning: {p}")
314
+ print(f"wrote {out}")
315
+ if args.publish:
316
+ print(f"published {publish(out, args.publish, name)} (earlier takes kept)")
317
+
318
+
319
+ if __name__ == "__main__":
320
+ main()