@open-take/compositor 0.5.3 → 0.6.0

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 (439) hide show
  1. package/dist/cdp-CzT5BKNY.js +3 -0
  2. package/dist/cdp-QXbQfXna.js +373 -0
  3. package/dist/cdp-QXbQfXna.js.map +1 -0
  4. package/dist/index.d.ts +4327 -195
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +26282 -160
  7. package/dist/index.js.map +1 -1
  8. package/dist/server-841PMF2H.js +163 -0
  9. package/dist/server-841PMF2H.js.map +1 -0
  10. package/dist/server-C2aVv4-t.js +3 -0
  11. package/kit/audio.mjs +2366 -0
  12. package/kit/camera.js +587 -0
  13. package/kit/cursor.js +264 -0
  14. package/kit/cut.js +427 -0
  15. package/kit/draw.js +346 -0
  16. package/kit/look.js +589 -0
  17. package/kit/map.js +170 -0
  18. package/kit/media.js +3568 -0
  19. package/kit/motion.js +1115 -0
  20. package/kit/seams.js +1006 -0
  21. package/kit/stage.js +923 -0
  22. package/kit/time.js +812 -0
  23. package/kit/world.js +1072 -0
  24. package/package.json +7 -3
  25. package/src/ffmpeg.ts +63 -0
  26. package/src/film/beats.ts +1285 -0
  27. package/src/film/carry.ts +221 -0
  28. package/src/film/changes.ts +330 -0
  29. package/src/film/check.ts +996 -0
  30. package/src/film/clock.ts +2530 -0
  31. package/src/film/components-probe.ts +809 -0
  32. package/src/film/components.ts +1566 -0
  33. package/src/film/frames.ts +389 -0
  34. package/src/film/gallery.ts +3276 -0
  35. package/src/film/kit.ts +515 -0
  36. package/src/film/layout.ts +701 -0
  37. package/src/film/listen.ts +1979 -0
  38. package/src/film/look.ts +3829 -0
  39. package/src/film/materials.ts +976 -0
  40. package/src/film/moving.ts +248 -0
  41. package/src/film/part-files.ts +729 -0
  42. package/src/film/picture.ts +74 -0
  43. package/src/film/probe-text.ts +843 -0
  44. package/src/film/probe.ts +3456 -0
  45. package/src/film/provenance.ts +596 -0
  46. package/src/film/render.ts +2447 -0
  47. package/src/film/report.ts +1631 -0
  48. package/src/film/sheet.ts +156 -0
  49. package/src/film/study-declared.ts +123 -0
  50. package/src/film/study-picture.ts +791 -0
  51. package/src/film/study-sound.ts +416 -0
  52. package/src/film/study.ts +864 -0
  53. package/src/film/tuning.ts +155 -0
  54. package/src/film/viewer.ts +174 -0
  55. package/src/html/cdp.ts +575 -0
  56. package/src/html/server.ts +208 -0
  57. package/src/index.ts +202 -0
  58. package/src/launch-render.ts +3 -2
  59. package/src/math.ts +3 -3
  60. package/src/mjpeg-matroska.ts +228 -0
  61. package/src/render.ts +6 -4
  62. package/src/state-diff.ts +215 -0
  63. package/src/state-index.ts +99 -0
  64. package/src/types.ts +59 -1
  65. package/starter/PLAN.md +84 -0
  66. package/starter/START.md +460 -0
  67. package/starter/lib/anim.js +760 -0
  68. package/starter/lib/devices.js +1402 -0
  69. package/starter/lib/handoff.js +421 -0
  70. package/starter/lib/hud.js +1879 -0
  71. package/starter/lib/measure.mjs +154 -0
  72. package/starter/lib/moves.js +1095 -0
  73. package/starter/lib/palette.mjs +803 -0
  74. package/starter/lib/physics-seeds.mjs +198 -0
  75. package/starter/lib/physics.js +738 -0
  76. package/starter/lib/sampler.mjs +242 -0
  77. package/starter/lib/solid.js +727 -0
  78. package/starter/lib/space.js +1227 -0
  79. package/starter/lib/swarm.js +1398 -0
  80. package/starter/reference/motion.md +276 -0
  81. package/starter/reference/structure.md +466 -0
  82. package/starter/reference/travel/motion.md +433 -0
  83. package/starter/reference/travel/sound.md +241 -0
  84. package/starter/reference/travel/structure.md +518 -0
  85. package/starter/samples/NOTICE.txt +55 -0
  86. package/starter/samples/celli/celli_24_1.opus +0 -0
  87. package/starter/samples/celli/celli_24_3.opus +0 -0
  88. package/starter/samples/celli/celli_28_1.opus +0 -0
  89. package/starter/samples/celli/celli_28_3.opus +0 -0
  90. package/starter/samples/celli/celli_31_1.opus +0 -0
  91. package/starter/samples/celli/celli_31_3.opus +0 -0
  92. package/starter/samples/celli/celli_35_1.opus +0 -0
  93. package/starter/samples/celli/celli_35_3.opus +0 -0
  94. package/starter/samples/celli/celli_38_1.opus +0 -0
  95. package/starter/samples/celli/celli_38_3.opus +0 -0
  96. package/starter/samples/celli/celli_41_1.opus +0 -0
  97. package/starter/samples/celli/celli_41_3.opus +0 -0
  98. package/starter/samples/celli/celli_45_1.opus +0 -0
  99. package/starter/samples/celli/celli_45_3.opus +0 -0
  100. package/starter/samples/celli/celli_48_1.opus +0 -0
  101. package/starter/samples/celli/celli_48_3.opus +0 -0
  102. package/starter/samples/celli/celli_52_1.opus +0 -0
  103. package/starter/samples/celli/celli_52_3.opus +0 -0
  104. package/starter/samples/celli/celli_55_1.opus +0 -0
  105. package/starter/samples/celli/celli_55_3.opus +0 -0
  106. package/starter/samples/celli/celli_59_1.opus +0 -0
  107. package/starter/samples/celli/celli_59_3.opus +0 -0
  108. package/starter/samples/celli/celli_62_1.opus +0 -0
  109. package/starter/samples/celli/celli_62_3.opus +0 -0
  110. package/starter/samples/celli/celli_65_1.opus +0 -0
  111. package/starter/samples/celli/celli_65_3.opus +0 -0
  112. package/starter/samples/crash/crash_f_1.flac +0 -0
  113. package/starter/samples/crash/crash_fff_1.flac +0 -0
  114. package/starter/samples/ebass/ebass_0_x.flac +0 -0
  115. package/starter/samples/ebass/ebass_10_x.flac +0 -0
  116. package/starter/samples/ebass/ebass_11_x.flac +0 -0
  117. package/starter/samples/ebass/ebass_1_x.flac +0 -0
  118. package/starter/samples/ebass/ebass_2_x.flac +0 -0
  119. package/starter/samples/ebass/ebass_3_x.flac +0 -0
  120. package/starter/samples/ebass/ebass_4_x.flac +0 -0
  121. package/starter/samples/ebass/ebass_5_x.flac +0 -0
  122. package/starter/samples/ebass/ebass_6_x.flac +0 -0
  123. package/starter/samples/ebass/ebass_7_x.flac +0 -0
  124. package/starter/samples/ebass/ebass_8_x.flac +0 -0
  125. package/starter/samples/ebass/ebass_9_x.flac +0 -0
  126. package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
  127. package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
  128. package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
  129. package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
  130. package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
  131. package/starter/samples/glock/glock_67_x.flac +0 -0
  132. package/starter/samples/glock/glock_72_x.flac +0 -0
  133. package/starter/samples/glock/glock_79_x.flac +0 -0
  134. package/starter/samples/glock/glock_84_x.flac +0 -0
  135. package/starter/samples/glock/glock_91_x.flac +0 -0
  136. package/starter/samples/glock/glock_96_x.flac +0 -0
  137. package/starter/samples/harp/harp_101_f.opus +0 -0
  138. package/starter/samples/harp/harp_28_f.opus +0 -0
  139. package/starter/samples/harp/harp_31_mp.opus +0 -0
  140. package/starter/samples/harp/harp_35_mf.opus +0 -0
  141. package/starter/samples/harp/harp_38_mf.opus +0 -0
  142. package/starter/samples/harp/harp_41_mf.opus +0 -0
  143. package/starter/samples/harp/harp_45_mf.opus +0 -0
  144. package/starter/samples/harp/harp_48_mf.opus +0 -0
  145. package/starter/samples/harp/harp_52_mf.opus +0 -0
  146. package/starter/samples/harp/harp_55_mf.opus +0 -0
  147. package/starter/samples/harp/harp_59_mf.opus +0 -0
  148. package/starter/samples/harp/harp_62_mf.opus +0 -0
  149. package/starter/samples/harp/harp_65_mf.opus +0 -0
  150. package/starter/samples/harp/harp_69_mf.opus +0 -0
  151. package/starter/samples/harp/harp_72_mf.opus +0 -0
  152. package/starter/samples/harp/harp_76_mf.opus +0 -0
  153. package/starter/samples/harp/harp_79_mf.opus +0 -0
  154. package/starter/samples/harp/harp_83_mf.opus +0 -0
  155. package/starter/samples/harp/harp_86_mf.opus +0 -0
  156. package/starter/samples/harp/harp_89_mf.opus +0 -0
  157. package/starter/samples/harp/harp_93_mf.opus +0 -0
  158. package/starter/samples/harp/harp_95_mf.opus +0 -0
  159. package/starter/samples/harp/harp_98_f.opus +0 -0
  160. package/starter/samples/manifest.json +2951 -0
  161. package/starter/samples/marimba/marimba_29_x.flac +0 -0
  162. package/starter/samples/marimba/marimba_36_x.flac +0 -0
  163. package/starter/samples/marimba/marimba_43_x.flac +0 -0
  164. package/starter/samples/marimba/marimba_47_x.flac +0 -0
  165. package/starter/samples/marimba/marimba_53_x.flac +0 -0
  166. package/starter/samples/marimba/marimba_60_x.flac +0 -0
  167. package/starter/samples/marimba/marimba_67_x.flac +0 -0
  168. package/starter/samples/marimba/marimba_71_x.flac +0 -0
  169. package/starter/samples/marimba/marimba_77_x.flac +0 -0
  170. package/starter/samples/marimba/marimba_84_x.flac +0 -0
  171. package/starter/samples/piano/piano_102_12.opus +0 -0
  172. package/starter/samples/piano/piano_102_16.opus +0 -0
  173. package/starter/samples/piano/piano_102_4.opus +0 -0
  174. package/starter/samples/piano/piano_102_8.opus +0 -0
  175. package/starter/samples/piano/piano_105_12.opus +0 -0
  176. package/starter/samples/piano/piano_105_16.opus +0 -0
  177. package/starter/samples/piano/piano_105_4.opus +0 -0
  178. package/starter/samples/piano/piano_105_8.opus +0 -0
  179. package/starter/samples/piano/piano_108_12.opus +0 -0
  180. package/starter/samples/piano/piano_108_16.opus +0 -0
  181. package/starter/samples/piano/piano_108_4.opus +0 -0
  182. package/starter/samples/piano/piano_108_8.opus +0 -0
  183. package/starter/samples/piano/piano_21_12.opus +0 -0
  184. package/starter/samples/piano/piano_21_16.opus +0 -0
  185. package/starter/samples/piano/piano_21_4.opus +0 -0
  186. package/starter/samples/piano/piano_21_8.opus +0 -0
  187. package/starter/samples/piano/piano_24_12.opus +0 -0
  188. package/starter/samples/piano/piano_24_16.opus +0 -0
  189. package/starter/samples/piano/piano_24_4.opus +0 -0
  190. package/starter/samples/piano/piano_24_8.opus +0 -0
  191. package/starter/samples/piano/piano_27_12.opus +0 -0
  192. package/starter/samples/piano/piano_27_16.opus +0 -0
  193. package/starter/samples/piano/piano_27_4.opus +0 -0
  194. package/starter/samples/piano/piano_27_8.opus +0 -0
  195. package/starter/samples/piano/piano_30_12.opus +0 -0
  196. package/starter/samples/piano/piano_30_16.opus +0 -0
  197. package/starter/samples/piano/piano_30_4.opus +0 -0
  198. package/starter/samples/piano/piano_30_8.opus +0 -0
  199. package/starter/samples/piano/piano_33_12.opus +0 -0
  200. package/starter/samples/piano/piano_33_16.opus +0 -0
  201. package/starter/samples/piano/piano_33_4.opus +0 -0
  202. package/starter/samples/piano/piano_33_8.opus +0 -0
  203. package/starter/samples/piano/piano_36_12.opus +0 -0
  204. package/starter/samples/piano/piano_36_16.opus +0 -0
  205. package/starter/samples/piano/piano_36_4.opus +0 -0
  206. package/starter/samples/piano/piano_36_8.opus +0 -0
  207. package/starter/samples/piano/piano_39_12.opus +0 -0
  208. package/starter/samples/piano/piano_39_16.opus +0 -0
  209. package/starter/samples/piano/piano_39_4.opus +0 -0
  210. package/starter/samples/piano/piano_39_8.opus +0 -0
  211. package/starter/samples/piano/piano_42_12.opus +0 -0
  212. package/starter/samples/piano/piano_42_16.opus +0 -0
  213. package/starter/samples/piano/piano_42_4.opus +0 -0
  214. package/starter/samples/piano/piano_42_8.opus +0 -0
  215. package/starter/samples/piano/piano_45_12.opus +0 -0
  216. package/starter/samples/piano/piano_45_16.opus +0 -0
  217. package/starter/samples/piano/piano_45_4.opus +0 -0
  218. package/starter/samples/piano/piano_45_8.opus +0 -0
  219. package/starter/samples/piano/piano_48_12.opus +0 -0
  220. package/starter/samples/piano/piano_48_16.opus +0 -0
  221. package/starter/samples/piano/piano_48_4.opus +0 -0
  222. package/starter/samples/piano/piano_48_8.opus +0 -0
  223. package/starter/samples/piano/piano_51_12.opus +0 -0
  224. package/starter/samples/piano/piano_51_16.opus +0 -0
  225. package/starter/samples/piano/piano_51_4.opus +0 -0
  226. package/starter/samples/piano/piano_51_8.opus +0 -0
  227. package/starter/samples/piano/piano_54_12.opus +0 -0
  228. package/starter/samples/piano/piano_54_16.opus +0 -0
  229. package/starter/samples/piano/piano_54_4.opus +0 -0
  230. package/starter/samples/piano/piano_54_8.opus +0 -0
  231. package/starter/samples/piano/piano_57_12.opus +0 -0
  232. package/starter/samples/piano/piano_57_16.opus +0 -0
  233. package/starter/samples/piano/piano_57_4.opus +0 -0
  234. package/starter/samples/piano/piano_57_8.opus +0 -0
  235. package/starter/samples/piano/piano_60_12.opus +0 -0
  236. package/starter/samples/piano/piano_60_16.opus +0 -0
  237. package/starter/samples/piano/piano_60_4.opus +0 -0
  238. package/starter/samples/piano/piano_60_8.opus +0 -0
  239. package/starter/samples/piano/piano_63_12.opus +0 -0
  240. package/starter/samples/piano/piano_63_16.opus +0 -0
  241. package/starter/samples/piano/piano_63_4.opus +0 -0
  242. package/starter/samples/piano/piano_63_8.opus +0 -0
  243. package/starter/samples/piano/piano_66_12.opus +0 -0
  244. package/starter/samples/piano/piano_66_16.opus +0 -0
  245. package/starter/samples/piano/piano_66_4.opus +0 -0
  246. package/starter/samples/piano/piano_66_8.opus +0 -0
  247. package/starter/samples/piano/piano_69_12.opus +0 -0
  248. package/starter/samples/piano/piano_69_16.opus +0 -0
  249. package/starter/samples/piano/piano_69_4.opus +0 -0
  250. package/starter/samples/piano/piano_69_8.opus +0 -0
  251. package/starter/samples/piano/piano_72_12.opus +0 -0
  252. package/starter/samples/piano/piano_72_16.opus +0 -0
  253. package/starter/samples/piano/piano_72_4.opus +0 -0
  254. package/starter/samples/piano/piano_72_8.opus +0 -0
  255. package/starter/samples/piano/piano_75_12.opus +0 -0
  256. package/starter/samples/piano/piano_75_16.opus +0 -0
  257. package/starter/samples/piano/piano_75_4.opus +0 -0
  258. package/starter/samples/piano/piano_75_8.opus +0 -0
  259. package/starter/samples/piano/piano_78_12.opus +0 -0
  260. package/starter/samples/piano/piano_78_16.opus +0 -0
  261. package/starter/samples/piano/piano_78_4.opus +0 -0
  262. package/starter/samples/piano/piano_78_8.opus +0 -0
  263. package/starter/samples/piano/piano_81_12.opus +0 -0
  264. package/starter/samples/piano/piano_81_16.opus +0 -0
  265. package/starter/samples/piano/piano_81_4.opus +0 -0
  266. package/starter/samples/piano/piano_81_8.opus +0 -0
  267. package/starter/samples/piano/piano_84_12.opus +0 -0
  268. package/starter/samples/piano/piano_84_16.opus +0 -0
  269. package/starter/samples/piano/piano_84_4.opus +0 -0
  270. package/starter/samples/piano/piano_84_8.opus +0 -0
  271. package/starter/samples/piano/piano_87_12.opus +0 -0
  272. package/starter/samples/piano/piano_87_16.opus +0 -0
  273. package/starter/samples/piano/piano_87_4.opus +0 -0
  274. package/starter/samples/piano/piano_87_8.opus +0 -0
  275. package/starter/samples/piano/piano_90_12.opus +0 -0
  276. package/starter/samples/piano/piano_90_16.opus +0 -0
  277. package/starter/samples/piano/piano_90_4.opus +0 -0
  278. package/starter/samples/piano/piano_90_8.opus +0 -0
  279. package/starter/samples/piano/piano_93_12.opus +0 -0
  280. package/starter/samples/piano/piano_93_16.opus +0 -0
  281. package/starter/samples/piano/piano_93_4.opus +0 -0
  282. package/starter/samples/piano/piano_93_8.opus +0 -0
  283. package/starter/samples/piano/piano_96_12.opus +0 -0
  284. package/starter/samples/piano/piano_96_16.opus +0 -0
  285. package/starter/samples/piano/piano_96_4.opus +0 -0
  286. package/starter/samples/piano/piano_96_8.opus +0 -0
  287. package/starter/samples/piano/piano_99_12.opus +0 -0
  288. package/starter/samples/piano/piano_99_16.opus +0 -0
  289. package/starter/samples/piano/piano_99_4.opus +0 -0
  290. package/starter/samples/piano/piano_99_8.opus +0 -0
  291. package/starter/samples/piano/piano_rel_102_x.opus +0 -0
  292. package/starter/samples/piano/piano_rel_105_x.opus +0 -0
  293. package/starter/samples/piano/piano_rel_108_x.opus +0 -0
  294. package/starter/samples/piano/piano_rel_21_x.opus +0 -0
  295. package/starter/samples/piano/piano_rel_24_x.opus +0 -0
  296. package/starter/samples/piano/piano_rel_27_x.opus +0 -0
  297. package/starter/samples/piano/piano_rel_30_x.opus +0 -0
  298. package/starter/samples/piano/piano_rel_33_x.opus +0 -0
  299. package/starter/samples/piano/piano_rel_36_x.opus +0 -0
  300. package/starter/samples/piano/piano_rel_39_x.opus +0 -0
  301. package/starter/samples/piano/piano_rel_42_x.opus +0 -0
  302. package/starter/samples/piano/piano_rel_45_x.opus +0 -0
  303. package/starter/samples/piano/piano_rel_48_x.opus +0 -0
  304. package/starter/samples/piano/piano_rel_51_x.opus +0 -0
  305. package/starter/samples/piano/piano_rel_54_x.opus +0 -0
  306. package/starter/samples/piano/piano_rel_57_x.opus +0 -0
  307. package/starter/samples/piano/piano_rel_60_x.opus +0 -0
  308. package/starter/samples/piano/piano_rel_63_x.opus +0 -0
  309. package/starter/samples/piano/piano_rel_66_x.opus +0 -0
  310. package/starter/samples/piano/piano_rel_69_x.opus +0 -0
  311. package/starter/samples/piano/piano_rel_72_x.opus +0 -0
  312. package/starter/samples/piano/piano_rel_75_x.opus +0 -0
  313. package/starter/samples/piano/piano_rel_78_x.opus +0 -0
  314. package/starter/samples/piano/piano_rel_81_x.opus +0 -0
  315. package/starter/samples/piano/piano_rel_84_x.opus +0 -0
  316. package/starter/samples/piano/piano_rel_87_x.opus +0 -0
  317. package/starter/samples/piano/piano_rel_90_x.opus +0 -0
  318. package/starter/samples/piano/piano_rel_93_x.opus +0 -0
  319. package/starter/samples/piano/piano_rel_96_x.opus +0 -0
  320. package/starter/samples/piano/piano_rel_99_x.opus +0 -0
  321. package/starter/samples/pizz/pizz_24_2.flac +0 -0
  322. package/starter/samples/pizz/pizz_28_2.flac +0 -0
  323. package/starter/samples/pizz/pizz_31_2.flac +0 -0
  324. package/starter/samples/pizz/pizz_35_2.flac +0 -0
  325. package/starter/samples/pizz/pizz_38_2.flac +0 -0
  326. package/starter/samples/pizz/pizz_41_2.flac +0 -0
  327. package/starter/samples/pizz/pizz_45_2.flac +0 -0
  328. package/starter/samples/pizz/pizz_48_2.flac +0 -0
  329. package/starter/samples/pizz/pizz_52_2.flac +0 -0
  330. package/starter/samples/pizz/pizz_57_2.flac +0 -0
  331. package/starter/samples/pizz/pizz_60_2.flac +0 -0
  332. package/starter/samples/pizz/pizz_64_2.flac +0 -0
  333. package/starter/samples/pizz/pizz_67_2.flac +0 -0
  334. package/starter/samples/pizz/pizz_71_2.flac +0 -0
  335. package/starter/samples/pizz/pizz_74_2.flac +0 -0
  336. package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
  337. package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
  338. package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
  339. package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
  340. package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
  341. package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
  342. package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
  343. package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
  344. package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
  345. package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
  346. package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
  347. package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
  348. package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
  349. package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
  350. package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
  351. package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
  352. package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
  353. package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
  354. package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
  355. package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
  356. package/starter/samples/shaker/shaker_1_1.flac +0 -0
  357. package/starter/samples/shaker/shaker_2_1.flac +0 -0
  358. package/starter/samples/snap/snap_r_1.flac +0 -0
  359. package/starter/samples/snap/snap_r_2.flac +0 -0
  360. package/starter/samples/snap/snap_r_3.flac +0 -0
  361. package/starter/samples/snap/snap_r_4.flac +0 -0
  362. package/starter/samples/snap/snap_r_5.flac +0 -0
  363. package/starter/samples/snap/snap_r_6.flac +0 -0
  364. package/starter/samples/tom/tom_3_1.flac +0 -0
  365. package/starter/samples/tom/tom_3_2.flac +0 -0
  366. package/starter/samples/tom/tom_4_1.flac +0 -0
  367. package/starter/samples/tom/tom_4_2.flac +0 -0
  368. package/starter/samples/vibes/vibes_41_1.opus +0 -0
  369. package/starter/samples/vibes/vibes_41_2.opus +0 -0
  370. package/starter/samples/vibes/vibes_45_1.opus +0 -0
  371. package/starter/samples/vibes/vibes_45_2.opus +0 -0
  372. package/starter/samples/vibes/vibes_48_1.opus +0 -0
  373. package/starter/samples/vibes/vibes_48_2.opus +0 -0
  374. package/starter/samples/vibes/vibes_52_1.opus +0 -0
  375. package/starter/samples/vibes/vibes_52_2.opus +0 -0
  376. package/starter/samples/vibes/vibes_55_1.opus +0 -0
  377. package/starter/samples/vibes/vibes_55_2.opus +0 -0
  378. package/starter/samples/vibes/vibes_59_1.opus +0 -0
  379. package/starter/samples/vibes/vibes_59_2.opus +0 -0
  380. package/starter/samples/vibes/vibes_62_1.opus +0 -0
  381. package/starter/samples/vibes/vibes_62_2.opus +0 -0
  382. package/starter/samples/vibes/vibes_65_1.opus +0 -0
  383. package/starter/samples/vibes/vibes_65_2.opus +0 -0
  384. package/starter/samples/vibes/vibes_69_1.opus +0 -0
  385. package/starter/samples/vibes/vibes_69_2.opus +0 -0
  386. package/starter/samples/vibes/vibes_72_1.opus +0 -0
  387. package/starter/samples/vibes/vibes_72_2.opus +0 -0
  388. package/starter/samples/vibes/vibes_76_1.opus +0 -0
  389. package/starter/samples/vibes/vibes_76_2.opus +0 -0
  390. package/starter/samples/violas/violas_36_1.opus +0 -0
  391. package/starter/samples/violas/violas_36_2.opus +0 -0
  392. package/starter/samples/violas/violas_38_1.opus +0 -0
  393. package/starter/samples/violas/violas_38_2.opus +0 -0
  394. package/starter/samples/violas/violas_40_1.opus +0 -0
  395. package/starter/samples/violas/violas_40_2.opus +0 -0
  396. package/starter/samples/violas/violas_43_1.opus +0 -0
  397. package/starter/samples/violas/violas_43_2.opus +0 -0
  398. package/starter/samples/violas/violas_47_1.opus +0 -0
  399. package/starter/samples/violas/violas_47_2.opus +0 -0
  400. package/starter/samples/violas/violas_50_1.opus +0 -0
  401. package/starter/samples/violas/violas_50_2.opus +0 -0
  402. package/starter/samples/violas/violas_53_1.opus +0 -0
  403. package/starter/samples/violas/violas_53_2.opus +0 -0
  404. package/starter/samples/violas/violas_57_1.opus +0 -0
  405. package/starter/samples/violas/violas_57_2.opus +0 -0
  406. package/starter/samples/violas/violas_60_1.opus +0 -0
  407. package/starter/samples/violas/violas_60_2.opus +0 -0
  408. package/starter/samples/violas/violas_64_1.opus +0 -0
  409. package/starter/samples/violas/violas_64_2.opus +0 -0
  410. package/starter/samples/violas/violas_67_1.opus +0 -0
  411. package/starter/samples/violas/violas_67_2.opus +0 -0
  412. package/starter/samples/violas/violas_71_1.opus +0 -0
  413. package/starter/samples/violas/violas_71_2.opus +0 -0
  414. package/starter/samples/violas/violas_74_1.opus +0 -0
  415. package/starter/samples/violas/violas_74_2.opus +0 -0
  416. package/starter/samples/violins/violins_43_1.opus +0 -0
  417. package/starter/samples/violins/violins_43_2.opus +0 -0
  418. package/starter/samples/violins/violins_45_1.opus +0 -0
  419. package/starter/samples/violins/violins_45_2.opus +0 -0
  420. package/starter/samples/violins/violins_47_1.opus +0 -0
  421. package/starter/samples/violins/violins_47_2.opus +0 -0
  422. package/starter/samples/violins/violins_50_1.opus +0 -0
  423. package/starter/samples/violins/violins_50_2.opus +0 -0
  424. package/starter/samples/violins/violins_54_1.opus +0 -0
  425. package/starter/samples/violins/violins_54_2.opus +0 -0
  426. package/starter/samples/violins/violins_57_1.opus +0 -0
  427. package/starter/samples/violins/violins_57_2.opus +0 -0
  428. package/starter/samples/violins/violins_60_1.opus +0 -0
  429. package/starter/samples/violins/violins_60_2.opus +0 -0
  430. package/starter/samples/violins/violins_64_1.opus +0 -0
  431. package/starter/samples/violins/violins_64_2.opus +0 -0
  432. package/starter/samples/violins/violins_67_1.opus +0 -0
  433. package/starter/samples/violins/violins_67_2.opus +0 -0
  434. package/starter/samples/violins/violins_71_1.opus +0 -0
  435. package/starter/samples/violins/violins_71_2.opus +0 -0
  436. package/starter/samples/violins/violins_74_1.opus +0 -0
  437. package/starter/samples/violins/violins_74_2.opus +0 -0
  438. package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
  439. package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
@@ -0,0 +1,208 @@
1
+ // Static files for one directory, so a film's page and everything it loads —
2
+ // fonts, images, clips, saved screens — are same-origin at
3
+ // http://127.0.0.1:<port>/… A file:// page would refuse cross-origin fonts and
4
+ // fetch() of a sibling file; over loopback every asset is a plain relative URL
5
+ // and Chrome caches it for the life of that (throwaway) profile.
6
+ //
7
+ // No dependencies: node:http on loopback, an ephemeral port, GET and HEAD, the
8
+ // MIME types a render page uses, byte ranges (a <video> seeks with them), and
9
+ // nothing else: no directory listing, and a path that escapes the root is a
10
+ // 404 like any other missing file.
11
+
12
+ import { createReadStream } from "node:fs";
13
+ import { stat } from "node:fs/promises";
14
+ import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
15
+ import type { AddressInfo } from "node:net";
16
+ import { extname, join, resolve, sep } from "node:path";
17
+ import { pipeline } from "node:stream";
18
+
19
+ const MIME: Record<string, string> = {
20
+ ".html": "text/html; charset=utf-8",
21
+ ".htm": "text/html; charset=utf-8",
22
+ ".js": "text/javascript; charset=utf-8",
23
+ ".mjs": "text/javascript; charset=utf-8",
24
+ ".json": "application/json; charset=utf-8",
25
+ ".map": "application/json; charset=utf-8",
26
+ ".css": "text/css; charset=utf-8",
27
+ ".txt": "text/plain; charset=utf-8",
28
+ ".png": "image/png",
29
+ ".jpg": "image/jpeg",
30
+ ".jpeg": "image/jpeg",
31
+ ".webp": "image/webp",
32
+ ".gif": "image/gif",
33
+ ".avif": "image/avif",
34
+ ".svg": "image/svg+xml",
35
+ ".ico": "image/x-icon",
36
+ ".woff2": "font/woff2",
37
+ ".woff": "font/woff",
38
+ ".ttf": "font/ttf",
39
+ ".otf": "font/otf",
40
+ ".mp4": "video/mp4",
41
+ ".webm": "video/webm",
42
+ ".m4a": "audio/mp4",
43
+ ".mp3": "audio/mpeg",
44
+ ".wav": "audio/wav",
45
+ ".ogg": "audio/ogg",
46
+ ".wasm": "application/wasm",
47
+ };
48
+
49
+ export type StaticServer = {
50
+ /** `http://127.0.0.1:<port>` — no trailing slash */
51
+ url: string;
52
+ /** serve `dir` under the URL path `prefix` (`/a/b/`): what the server
53
+ * itself made for the page, kept out of the served folder */
54
+ mount(prefix: string, dir: string): void;
55
+ /** stop listening and drop every open connection */
56
+ close(): Promise<void>;
57
+ };
58
+
59
+ /** Serve `root` (a directory) on a loopback ephemeral port until `close()`. */
60
+ export async function serveDirectory(
61
+ root: string,
62
+ /** told the path of every request answered 404 (a film's missing font or
63
+ * image would otherwise just render without it) */
64
+ onMiss?: (urlPath: string) => void,
65
+ ): Promise<StaticServer> {
66
+ const base = resolve(root);
67
+ const info = await stat(base).catch(() => null);
68
+ if (!info?.isDirectory()) throw new Error(`serveDirectory: ${base} is not a directory`);
69
+
70
+ const mounts = new Map<string, string>();
71
+ const server = createServer((req, res) => {
72
+ let url = req.url ?? "/";
73
+ let from = base;
74
+ for (const [prefix, dir] of mounts)
75
+ if (url.startsWith(prefix)) {
76
+ from = dir;
77
+ url = `/${url.slice(prefix.length)}`;
78
+ break;
79
+ }
80
+ serveFile(from, url, req, res, () => onMiss?.((req.url ?? "/").split("?")[0]!)).catch(() => {
81
+ if (!res.headersSent) res.writeHead(500);
82
+ res.end();
83
+ });
84
+ });
85
+ await new Promise<void>((ok, fail) => {
86
+ server.once("error", fail);
87
+ server.listen(0, "127.0.0.1", () => {
88
+ server.off("error", fail);
89
+ ok();
90
+ });
91
+ });
92
+ const { port } = server.address() as AddressInfo;
93
+ return {
94
+ url: `http://127.0.0.1:${port}`,
95
+ mount(prefix, dir) {
96
+ if (!prefix.startsWith("/") || !prefix.endsWith("/"))
97
+ throw new Error(
98
+ `serveDirectory: a mount is a path that starts and ends with "/", not ${prefix}`,
99
+ );
100
+ mounts.set(prefix, resolve(dir));
101
+ },
102
+ close: () =>
103
+ new Promise<void>((ok) => {
104
+ // close() alone waits for keep-alive connections to end on their own;
105
+ // a browser holds them open for a minute, so drop them.
106
+ server.close(() => ok());
107
+ server.closeAllConnections();
108
+ }),
109
+ };
110
+ }
111
+
112
+ /** The file a request path names inside `base`, or null when it names none
113
+ * we would serve (malformed escapes, a NUL, or a path that resolves outside
114
+ * the root — `..` segments and `%2e%2e` alike, since both are decoded and
115
+ * normalised before the containment check). */
116
+ export function fileFor(base: string, rawUrl: string): string | null {
117
+ let pathname: string;
118
+ try {
119
+ pathname = decodeURIComponent(new URL(rawUrl, "http://127.0.0.1").pathname);
120
+ } catch {
121
+ return null;
122
+ }
123
+ if (pathname.includes("\0")) return null;
124
+ const file = resolve(base, `.${pathname}`);
125
+ if (file !== base && !file.startsWith(base + sep)) return null;
126
+ return file;
127
+ }
128
+
129
+ type ByteRange = { start: number; end: number } | "unsatisfiable" | null;
130
+
131
+ /** One `bytes=` range against a file of `size` bytes; null for no/unsupported
132
+ * (multi-)range, so the whole file goes out as a 200. */
133
+ export function parseRange(header: string | undefined, size: number): ByteRange {
134
+ if (!header || size === 0) return null;
135
+ const m = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
136
+ if (!m) return null;
137
+ const [, from, to] = m;
138
+ if (from === "" && to === "") return null;
139
+ let start: number, end: number;
140
+ if (from === "") {
141
+ // suffix range: the last N bytes
142
+ const n = Number(to);
143
+ if (n === 0) return "unsatisfiable";
144
+ start = Math.max(0, size - n);
145
+ end = size - 1;
146
+ } else {
147
+ start = Number(from);
148
+ end = to === "" ? size - 1 : Math.min(Number(to), size - 1);
149
+ }
150
+ if (start >= size || start > end) return "unsatisfiable";
151
+ return { start, end };
152
+ }
153
+
154
+ async function serveFile(
155
+ base: string,
156
+ url: string,
157
+ req: IncomingMessage,
158
+ res: ServerResponse,
159
+ missed: () => void = () => {},
160
+ ): Promise<void> {
161
+ if (req.method !== "GET" && req.method !== "HEAD") {
162
+ res.writeHead(405, { Allow: "GET, HEAD" });
163
+ res.end();
164
+ return;
165
+ }
166
+ let file = fileFor(base, url);
167
+ let info = file ? await stat(file).catch(() => null) : null;
168
+ if (file && info?.isDirectory()) {
169
+ // a directory serves its index.html and nothing else — never a listing
170
+ file = join(file, "index.html");
171
+ info = await stat(file).catch(() => null);
172
+ }
173
+ if (!file || !info?.isFile()) {
174
+ missed();
175
+ res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
176
+ res.end("not found");
177
+ return;
178
+ }
179
+
180
+ const headers: Record<string, string> = {
181
+ "Content-Type": MIME[extname(file).toLowerCase()] ?? "application/octet-stream",
182
+ "Accept-Ranges": "bytes",
183
+ "Last-Modified": info.mtime.toUTCString(),
184
+ // a profile lives for one render, so caching only ever spans that render
185
+ "Cache-Control": "max-age=3600",
186
+ };
187
+ const range = parseRange(req.headers.range, info.size);
188
+ if (range === "unsatisfiable") {
189
+ res.writeHead(416, { "Content-Range": `bytes */${info.size}` });
190
+ res.end();
191
+ return;
192
+ }
193
+ if (range) {
194
+ headers["Content-Range"] = `bytes ${range.start}-${range.end}/${info.size}`;
195
+ headers["Content-Length"] = String(range.end - range.start + 1);
196
+ res.writeHead(206, headers);
197
+ } else {
198
+ headers["Content-Length"] = String(info.size);
199
+ res.writeHead(200, headers);
200
+ }
201
+ if (req.method === "HEAD") {
202
+ res.end();
203
+ return;
204
+ }
205
+ // pipeline (not pipe) so a client that goes away mid-file destroys the
206
+ // read stream too, instead of leaving its descriptor open
207
+ pipeline(createReadStream(file, range ?? {}), res, () => {});
208
+ }
package/src/index.ts CHANGED
@@ -22,7 +22,193 @@ export {
22
22
  resolveFfprobe,
23
23
  resolveManagedFfmpeg,
24
24
  resolveManagedFfprobe,
25
+ SRGB_TAGS,
25
26
  } from "./ffmpeg";
27
+ export {
28
+ type FilmBeats,
29
+ type FilmBeatsOptions,
30
+ filmBeats,
31
+ formatFilmBeats,
32
+ } from "./film/beats";
33
+ export {
34
+ checkFilm,
35
+ type FilmCheck,
36
+ type FilmCheckExpect,
37
+ type FilmCheckIssue,
38
+ formatFilmCheck,
39
+ type PageMaterial,
40
+ pageMaterialNote,
41
+ readPageMaterial,
42
+ } from "./film/check";
43
+ export {
44
+ COMPONENT_ORDER,
45
+ type ComponentAction,
46
+ type ComponentEntry,
47
+ type ComponentProvenance,
48
+ type ComponentRelation,
49
+ type ComponentSource,
50
+ type ComponentSourceKind,
51
+ type ComponentSourceState,
52
+ type ComponentState,
53
+ type ComponentsFile,
54
+ type ComponentTrack,
55
+ type ComponentValue,
56
+ componentCounts,
57
+ componentsLine,
58
+ exampleSource,
59
+ FILM_STAGE,
60
+ fitOf,
61
+ changedLine,
62
+ followedLine,
63
+ formatComponents,
64
+ gatherComponents,
65
+ partsLine,
66
+ phoneOf,
67
+ readComponentSource,
68
+ readNumber,
69
+ writeComponents,
70
+ } from "./film/components";
71
+ export {
72
+ CLIP_CLEAR_CSS,
73
+ COMPONENT_PROBE_JS,
74
+ type ComponentProbeInput,
75
+ type ComponentProbeResult,
76
+ componentProbeExpression,
77
+ type PartCandidate,
78
+ type PartFields,
79
+ type PartKind,
80
+ type PartSkipped,
81
+ type PartsFile,
82
+ pictureClip,
83
+ } from "./film/components-probe";
84
+ export {
85
+ type FilmGalleryOptions,
86
+ type FilmGalleryResult,
87
+ filmGallery,
88
+ type GalleryEntry,
89
+ type GalleryMaterial,
90
+ type GalleryStats,
91
+ } from "./film/gallery";
92
+ export {
93
+ type FilmFiles,
94
+ type FilmInitResult,
95
+ filmInitLines,
96
+ filmKitDir,
97
+ filmStarterDir,
98
+ initFilm,
99
+ } from "./film/kit";
100
+ export {
101
+ type FilmEvent,
102
+ type FilmEvents,
103
+ type FilmListen,
104
+ type FilmListenOptions,
105
+ filmListen,
106
+ formatFilmListen,
107
+ parseFilmEvents,
108
+ } from "./film/listen";
109
+ export {
110
+ contrastRatio,
111
+ type FilmLook,
112
+ type FilmLookOptions,
113
+ type FilmLookResult,
114
+ type FontInfo,
115
+ filmLook,
116
+ filmText,
117
+ formatFilmLook,
118
+ glyphChars,
119
+ glyphCoverage,
120
+ packageFonts,
121
+ parseCssColor,
122
+ parseFont,
123
+ readableSize,
124
+ relativeLuminance,
125
+ sizeForCapHeight,
126
+ subsetFont,
127
+ textWidth,
128
+ } from "./film/look";
129
+ export {
130
+ adHost,
131
+ copyLine,
132
+ formatMaterials,
133
+ imageFileSize,
134
+ imageLine,
135
+ largestSource,
136
+ MATERIALS_PROBE_JS,
137
+ type MaterialCandidate,
138
+ type MaterialImage,
139
+ type MaterialKind,
140
+ type MaterialMeta,
141
+ type MaterialProbeImage,
142
+ type MaterialSheet,
143
+ type MaterialSkipped,
144
+ type MaterialsFile,
145
+ type MaterialsPage,
146
+ type MaterialsProbeResult,
147
+ type MaterialText,
148
+ materialsFromProbe,
149
+ materialsProbeExpression,
150
+ materialsScope,
151
+ materialsSummary,
152
+ pageKey,
153
+ readMaterials,
154
+ } from "./film/materials";
155
+ export {
156
+ PART_DOM_JS,
157
+ type PartDom,
158
+ type PartDomFile,
159
+ type PartDomInput,
160
+ type PartFileEntry,
161
+ type PartFilesIndex,
162
+ type PartFilesResult,
163
+ partDomExpression,
164
+ partFileName,
165
+ partFilesLine,
166
+ stateFontFaces,
167
+ writePartFiles,
168
+ } from "./film/part-files";
169
+ export { type FilmPictureOptions, filmPicture } from "./film/picture";
170
+ export {
171
+ type FilmProbe,
172
+ type FilmProbeOptions,
173
+ filmProbe,
174
+ formatFilmProbe,
175
+ type SheetSegment,
176
+ } from "./film/probe";
177
+ export {
178
+ type FilmProvenance,
179
+ numberTokens,
180
+ type ProvenanceValue,
181
+ } from "./film/provenance";
182
+ export {
183
+ type FilmProgress,
184
+ type FilmRenderOptions,
185
+ type FilmRenderResult,
186
+ type FilmSegment,
187
+ type FilmSource,
188
+ type FilmStillsOptions,
189
+ filmStills,
190
+ muxFilm,
191
+ patchFilm,
192
+ renderFilm,
193
+ } from "./film/render";
194
+ export {
195
+ type FilmReport,
196
+ type FilmReportOptions,
197
+ filmReport,
198
+ formatFilmReport,
199
+ } from "./film/report";
200
+ export { type FilmSheetOptions, filmSheet } from "./film/sheet";
201
+ export { type FilmStudy, type FilmStudyOptions, filmStudy, formatFilmStudy } from "./film/study";
202
+ export {
203
+ checkViewer,
204
+ prepareViewer,
205
+ VIEWER_TOOLS,
206
+ viewerCommand,
207
+ type ViewerRound,
208
+ type ViewerRounds,
209
+ viewerBrief,
210
+ viewerRounds,
211
+ } from "./film/viewer";
26
212
  export {
27
213
  evaluateUiMorph,
28
214
  launchAudioAtS,
@@ -44,6 +230,12 @@ export { launchTemplate } from "./launch-template";
44
230
  export * from "./launch-types";
45
231
  export { formatLaunchIssues, validateLaunchComposition } from "./launch-validate";
46
232
  export * as math from "./math";
233
+ export {
234
+ jpegDimensions,
235
+ matroskaHead,
236
+ mjpegMatroska,
237
+ type TimedFrame,
238
+ } from "./mjpeg-matroska";
47
239
  export { evaluateMotionScene, evaluateMotionTrack, motionGraphemes } from "./motion-evaluate";
48
240
  export { analyzeMotionQuality } from "./motion-quality";
49
241
  export {
@@ -62,6 +254,16 @@ export { validateMotionScene } from "./motion-validate";
62
254
  export { type PlanOpts, planComposition } from "./plan";
63
255
  export * from "./presets";
64
256
  export { type RenderTakeOpts, type RenderTakeResult, renderTake } from "./render";
257
+ export {
258
+ changedBoxes,
259
+ contentOf,
260
+ diffStates,
261
+ elementLabel,
262
+ matchStates,
263
+ type StateChange,
264
+ subtree,
265
+ } from "./state-diff";
266
+ export { cardsOf, readStateIndex, type StateElement, type StateIndex } from "./state-index";
65
267
  export * from "./types";
66
268
  export {
67
269
  type CompositionIssue,
@@ -16,7 +16,7 @@ import { tmpdir } from "node:os";
16
16
  import { basename, dirname, extname, join, resolve, sep } from "node:path";
17
17
  import { fileURLToPath } from "node:url";
18
18
  import { renderVideo } from "@open-take/revideo-renderer";
19
- import { resolveFfmpeg, resolveFfprobe } from "./ffmpeg";
19
+ import { resolveFfmpeg, resolveFfprobe, SRGB_TAGS } from "./ffmpeg";
20
20
  import { launchAudioAtS, launchDurationS } from "./launch-evaluate";
21
21
  import type { LaunchAudioTrack, LaunchComposition, LaunchIssue } from "./launch-types";
22
22
  import { formatLaunchIssues, validateLaunchComposition } from "./launch-validate";
@@ -729,7 +729,8 @@ export async function deliverLaunchMedia(
729
729
  `launch render: renderer produced ${rawMedia.videoDuration.toFixed(6)}s of video for an authored ${total.toFixed(6)}s film; only one output frame (${frameDuration.toFixed(6)}s) of rounding is allowed. Re-render the complete composition before delivery.`,
730
730
  );
731
731
  }
732
- const videoFilter = `tpad=stop_mode=clone:stop_duration=${frameDuration},scale=in_color_matrix=bt601:out_color_matrix=bt709,format=yuv420p,setparams=range=tv:colorspace=bt709:color_primaries=bt709:color_trc=bt709`;
732
+ // the scene's sRGB values, rounded exactly into BT.709 and named sRGB (see SRGB_TAGS)
733
+ const videoFilter = `tpad=stop_mode=clone:stop_duration=${frameDuration},scale=in_color_matrix=bt601:out_color_matrix=bt709:flags=accurate_rnd+full_chroma_int,format=yuv420p,${SRGB_TAGS}`;
733
734
  const args = ["-y", "-loglevel", "error", "-i", raw];
734
735
  const loopSamples: (number | undefined)[] = [];
735
736
  for (const track of tracks) {
package/src/math.ts CHANGED
@@ -109,7 +109,7 @@ export function gradientEndpoints(
109
109
  };
110
110
  }
111
111
 
112
- type KF<T> = [number, T];
112
+ export type KF<T> = [number, T];
113
113
 
114
114
  export function keyvalN(
115
115
  t: number,
@@ -497,7 +497,7 @@ export function buildStageKeyframes(comp: TakeComposition): StageKeyframes {
497
497
  * plus a slow settle pole; at frac 0.04 the tail τ ≈ duration/3.6 (730ms →
498
498
  * ~205ms, 1340ms → ~375ms — the frame-tracked reference tails; a different
499
499
  * frac shifts ω0 and with it τ). */
500
- function settleDecay(frac: number): (u: number) => number {
500
+ export function settleDecay(frac: number): (u: number) => number {
501
501
  const zeta = 1.2;
502
502
  const s = Math.sqrt(zeta * zeta - 1);
503
503
  const l1 = zeta + s;
@@ -522,7 +522,7 @@ function settleDecay(frac: number): (u: number) => number {
522
522
  * build-time-clamped rects, and the valid-rect set is convex (linear
523
523
  * half-plane bounds in cx,cy,w), so in-between rects stay valid exactly as
524
524
  * in the lerped path. */
525
- function settleRectAt(kfs: KF<CamRect>[], decay: (u: number) => number, t: number): CamRect {
525
+ export function settleRectAt(kfs: KF<CamRect>[], decay: (u: number) => number, t: number): CamRect {
526
526
  let from = kfs[0]![1];
527
527
  for (let i = 0; i < kfs.length - 1; i++) {
528
528
  const [t0, r0] = kfs[i]!;
@@ -0,0 +1,228 @@
1
+ // The screencast's JPEG frames reach ffmpeg inside a Matroska stream written
2
+ // here, one cluster per frame with an explicit millisecond timecode.
3
+ //
4
+ // Why not a concat list: the concat demuxer opens each JPEG through image2,
5
+ // whose clock ticks at 1/25 s, and it rounds every file's start time onto that
6
+ // clock — frames at 0/17/50/62 ms come out 0/0/40/80 ms, i.e. the 25 Hz judder
7
+ // 6978155 removed. The `option framerate 1000` directive that lifted the clock
8
+ // only exists in FFmpeg ≥ 5.0; the ffmpeg 4.4 that 0.5.0/0.5.1 bundled (and
9
+ // Ubuntu 22.04's 4.4.2) died on it ("unknown keyword 'option'"), so every
10
+ // zero-config install rendered nothing. Matroska carries the timestamp on each
11
+ // block, so every ffmpeg version reads exactly the timing Chrome reported, and
12
+ // the decoder is the same mjpeg decoder image2 would have reached (yuvj420p,
13
+ // full range, 601).
14
+ //
15
+ // Only what libavformat needs is written: an EBML header, a Segment of unknown
16
+ // size (so nothing has to be patched after the fact and the stream can go
17
+ // straight down a pipe), Info with a 1 ms timecode scale, one MJPEG track, and
18
+ // clusters. No Cues, no SeekHead — the reader only ever plays it forward.
19
+
20
+ import { readFile } from "node:fs/promises";
21
+
22
+ /** A frame and the moment (ms from the capture's t0) the video shows it. */
23
+ export type TimedFrame = { file: string; tMs: number };
24
+
25
+ const ID = {
26
+ EBML: 0x1a45dfa3,
27
+ EBMLVersion: 0x4286,
28
+ EBMLReadVersion: 0x42f7,
29
+ EBMLMaxIDLength: 0x42f2,
30
+ EBMLMaxSizeLength: 0x42f3,
31
+ DocType: 0x4282,
32
+ DocTypeVersion: 0x4287,
33
+ DocTypeReadVersion: 0x4285,
34
+ Segment: 0x18538067,
35
+ Info: 0x1549a966,
36
+ TimecodeScale: 0x2ad7b1,
37
+ Duration: 0x4489,
38
+ MuxingApp: 0x4d80,
39
+ WritingApp: 0x5741,
40
+ Tracks: 0x1654ae6b,
41
+ TrackEntry: 0xae,
42
+ TrackNumber: 0xd7,
43
+ TrackUID: 0x73c5,
44
+ TrackType: 0x83,
45
+ FlagLacing: 0x9c,
46
+ CodecID: 0x86,
47
+ Video: 0xe0,
48
+ PixelWidth: 0xb0,
49
+ PixelHeight: 0xba,
50
+ Cluster: 0x1f43b675,
51
+ Timecode: 0xe7,
52
+ SimpleBlock: 0xa3,
53
+ } as const;
54
+
55
+ /** Element IDs are written with their length marker bits included, so the
56
+ * constant's own big-endian bytes are the encoding. */
57
+ function idBytes(id: number): Buffer {
58
+ const bytes: number[] = [];
59
+ for (let v = id; v > 0; v = Math.floor(v / 256)) bytes.unshift(v % 256);
60
+ return Buffer.from(bytes);
61
+ }
62
+
63
+ /** EBML variable-size integer: a width-w encoding carries 7w bits and the
64
+ * all-ones pattern of each width is reserved for "size unknown". */
65
+ function sizeBytes(n: number): Buffer {
66
+ for (let width = 1; width <= 8; width++) {
67
+ if (n > 2 ** (7 * width) - 2) continue;
68
+ const out = Buffer.alloc(width);
69
+ let v = BigInt(n) | (1n << BigInt(7 * width));
70
+ for (let i = width - 1; i >= 0; i--) {
71
+ out[i] = Number(v & 0xffn);
72
+ v >>= 8n;
73
+ }
74
+ return out;
75
+ }
76
+ throw new Error(`matroska: element of ${n} bytes exceeds the EBML size range`);
77
+ }
78
+
79
+ const UNKNOWN_SIZE = Buffer.from([0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
80
+
81
+ const element = (id: number, payload: Buffer): Buffer =>
82
+ Buffer.concat([idBytes(id), sizeBytes(payload.length), payload]);
83
+
84
+ function uint(id: number, n: number): Buffer {
85
+ if (!Number.isInteger(n) || n < 0) throw new Error(`matroska: ${n} is not an unsigned integer`);
86
+ const bytes: number[] = [];
87
+ let v = BigInt(n);
88
+ do {
89
+ bytes.unshift(Number(v & 0xffn));
90
+ v >>= 8n;
91
+ } while (v > 0n);
92
+ return element(id, Buffer.from(bytes));
93
+ }
94
+
95
+ const utf8 = (id: number, s: string): Buffer => element(id, Buffer.from(s, "utf8"));
96
+
97
+ function float64(id: number, x: number): Buffer {
98
+ const b = Buffer.alloc(8);
99
+ b.writeDoubleBE(x);
100
+ return element(id, b);
101
+ }
102
+
103
+ /** Pixel size from a JPEG's frame header (any SOF marker: baseline,
104
+ * progressive, lossless…), read past APPn/COM/DQT segments by their lengths. */
105
+ export function jpegDimensions(jpeg: Buffer): { width: number; height: number } {
106
+ if (jpeg.length < 4 || jpeg[0] !== 0xff || jpeg[1] !== 0xd8) {
107
+ throw new Error("jpegDimensions: not a JPEG (no SOI marker)");
108
+ }
109
+ let i = 2;
110
+ while (i + 4 <= jpeg.length) {
111
+ if (jpeg[i] !== 0xff) {
112
+ i++;
113
+ continue;
114
+ }
115
+ const marker = jpeg[i + 1]!;
116
+ // 0xFF fill bytes, and the markers that carry no length: RSTn, SOI, TEM.
117
+ if (marker === 0xff) {
118
+ i++;
119
+ continue;
120
+ }
121
+ if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
122
+ i += 2;
123
+ continue;
124
+ }
125
+ const isSof =
126
+ marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc;
127
+ if (isSof) {
128
+ if (i + 9 > jpeg.length) break;
129
+ return { height: jpeg.readUInt16BE(i + 5), width: jpeg.readUInt16BE(i + 7) };
130
+ }
131
+ // Scan data or end of image before any frame header: nothing to find.
132
+ if (marker === 0xda || marker === 0xd9) break;
133
+ i += 2 + jpeg.readUInt16BE(i + 2);
134
+ }
135
+ throw new Error("jpegDimensions: no SOF marker before scan data");
136
+ }
137
+
138
+ /** Everything before the first cluster. `durationMs` is advisory (players and
139
+ * ffprobe report it); the frames themselves carry the timing. */
140
+ export function matroskaHead(width: number, height: number, durationMs: number): Buffer {
141
+ const header = element(
142
+ ID.EBML,
143
+ Buffer.concat([
144
+ uint(ID.EBMLVersion, 1),
145
+ uint(ID.EBMLReadVersion, 1),
146
+ uint(ID.EBMLMaxIDLength, 4),
147
+ uint(ID.EBMLMaxSizeLength, 8),
148
+ utf8(ID.DocType, "matroska"),
149
+ uint(ID.DocTypeVersion, 4),
150
+ uint(ID.DocTypeReadVersion, 2),
151
+ ]),
152
+ );
153
+ const info = element(
154
+ ID.Info,
155
+ Buffer.concat([
156
+ uint(ID.TimecodeScale, 1_000_000), // 1 ms, so cluster timecodes are whole milliseconds
157
+ float64(ID.Duration, durationMs),
158
+ utf8(ID.MuxingApp, "open-take"),
159
+ utf8(ID.WritingApp, "open-take"),
160
+ ]),
161
+ );
162
+ const tracks = element(
163
+ ID.Tracks,
164
+ element(
165
+ ID.TrackEntry,
166
+ Buffer.concat([
167
+ uint(ID.TrackNumber, 1),
168
+ uint(ID.TrackUID, 1),
169
+ uint(ID.TrackType, 1),
170
+ uint(ID.FlagLacing, 0),
171
+ utf8(ID.CodecID, "V_MJPEG"),
172
+ element(
173
+ ID.Video,
174
+ Buffer.concat([uint(ID.PixelWidth, width), uint(ID.PixelHeight, height)]),
175
+ ),
176
+ ]),
177
+ ),
178
+ );
179
+ return Buffer.concat([header, idBytes(ID.Segment), UNKNOWN_SIZE, info, tracks]);
180
+ }
181
+
182
+ /** One frame: a cluster stamped with its absolute time holding a single
183
+ * keyframe SimpleBlock (track 1, relative timecode 0) around the raw JPEG. */
184
+ export function matroskaCluster(tMs: number, jpeg: Buffer): Buffer {
185
+ const block = element(
186
+ ID.SimpleBlock,
187
+ Buffer.concat([Buffer.from([0x81, 0x00, 0x00, 0x80]), jpeg]),
188
+ );
189
+ return element(ID.Cluster, Buffer.concat([uint(ID.Timecode, tMs), block]));
190
+ }
191
+
192
+ /** The whole stream, chunk by chunk, so a minute of Retina frames never sits
193
+ * in memory or on disk twice. Frames must be in non-decreasing tMs order;
194
+ * a file repeated back to back is read once.
195
+ *
196
+ * The track's pixel size comes from the first frame whose header parses.
197
+ * ffmpeg takes the size from each JPEG anyway, so one truncated frame (a
198
+ * write cut short) must not fail the whole encode here when the decoder
199
+ * would have skipped it; only a stream with no readable header at all is an
200
+ * error. */
201
+ export async function* mjpegMatroska(frames: TimedFrame[]): AsyncGenerator<Buffer> {
202
+ if (frames.length === 0) throw new Error("mjpegMatroska: no frames");
203
+ const jpegs = new Map<string, Buffer>();
204
+ let size: { width: number; height: number } | undefined;
205
+ for (const { file } of frames) {
206
+ if (jpegs.has(file)) continue;
207
+ const jpeg = await readFile(file);
208
+ jpegs.set(file, jpeg);
209
+ try {
210
+ size = jpegDimensions(jpeg);
211
+ break;
212
+ } catch {
213
+ // keep looking
214
+ }
215
+ }
216
+ if (!size) throw new Error("mjpegMatroska: no frame has a readable JPEG header");
217
+ yield matroskaHead(size.width, size.height, frames[frames.length - 1]!.tMs);
218
+ let file = "";
219
+ let jpeg: Buffer = Buffer.alloc(0);
220
+ for (const frame of frames) {
221
+ if (frame.file !== file) {
222
+ file = frame.file;
223
+ jpeg = jpegs.get(file) ?? (await readFile(file));
224
+ jpegs.delete(file);
225
+ }
226
+ yield matroskaCluster(frame.tMs, jpeg);
227
+ }
228
+ }