@open-take/compositor 0.5.2 → 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,1631 @@
1
+ // What `open-take film render` prints when it finishes: a few things measured
2
+ // on the film it just made, read with `film probe`'s own machinery, on the
3
+ // path every film already takes. A session that ran the probe changed its
4
+ // film on what the probe said; one that did not, never saw it.
5
+ //
6
+ // It reads, in a few seconds beside a render of minutes:
7
+ // - the picture, as the probe's small grey copy: the one-frame jumps the
8
+ // page did not declare as cuts, and for each how far its content moved
9
+ // (a card that jumps, a saved screen swapped under the camera, a line
10
+ // that re-centres as it is typed) or that it changed in place;
11
+ // - the page, played on the film clock as the probe plays it: where the
12
+ // product's own words (its saved screens) are most of the text on screen
13
+ // and how big they are on a phone; the pictures on screen that their
14
+ // shoot took while the product's screen was still changing; live text
15
+ // that moves under a pixel a frame, which Chrome draws on whole pixels;
16
+ // pictures (<img>, <video>) drawn bigger than their own pixels;
17
+ // - the parts the film named through product() (kit/media.js), read again
18
+ // at the times it used them: in the frame or past an edge, on the screen
19
+ // shown then or not, what the page draws over them, how many frame px
20
+ // each px of the still or recording that shows them takes.
21
+ // Text inside pictures (screenshots, recordings) needs the frames read by a
22
+ // text recognizer, which takes longer: the full probe does that.
23
+ //
24
+ // Facts only, each line saying what it covered: no grade, no target.
25
+
26
+ import { existsSync } from "node:fs";
27
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
28
+ import { tmpdir } from "node:os";
29
+ import { dirname, join, resolve } from "node:path";
30
+ import { resolveFfmpeg, runTool } from "../ffmpeg";
31
+ import { decodeMono } from "./beats";
32
+ import { type BoundaryCarry, boundaryCarries, CARRY_FILL, carryChange } from "./carry";
33
+ import { type SoundChange, soundChanges } from "./changes";
34
+ import {
35
+ halfSeconds,
36
+ momentaryLoudness,
37
+ type PictureAgainstSound,
38
+ parseFilmEvents,
39
+ pictureAgainstSound,
40
+ pictureEnergyOf,
41
+ } from "./listen";
42
+ import { type MovingMaterial, readMovingMaterial } from "./moving";
43
+ import {
44
+ decodeGrey,
45
+ findCuts,
46
+ findSmallSwaps,
47
+ frameEnergy,
48
+ frameTime,
49
+ jumpMove,
50
+ PHONE_SMALL_PX,
51
+ PROBE_W,
52
+ productTextSpans,
53
+ textTimeline,
54
+ } from "./probe";
55
+ import {
56
+ type Box,
57
+ type FrameText,
58
+ type OcrLine,
59
+ ocrHelper,
60
+ type PageTextSample,
61
+ PHONE_W,
62
+ readPageText,
63
+ runOcr,
64
+ } from "./probe-text";
65
+ import {
66
+ checkEvents,
67
+ checkSegments,
68
+ eventsPathFor,
69
+ FINE_SUPERSAMPLE,
70
+ type FilmEvent,
71
+ type FilmEvents,
72
+ type FilmSegment,
73
+ hiddenCutTimes,
74
+ mergeTimes,
75
+ probeFilm,
76
+ type TurnBack,
77
+ } from "./render";
78
+ import { type Tuning, tuning } from "./tuning";
79
+
80
+ /** the page's beat sheet counted: its stretches inside the film */
81
+ export type StretchCount = {
82
+ count: number;
83
+ /** s */
84
+ median: number;
85
+ longest: { from: number; to: number; label?: string };
86
+ };
87
+
88
+ /** The stretches of a beat sheet inside [from, to] of the page's timeline,
89
+ * times from the film's start; null when there are none. Facts: how many,
90
+ * how long at the median, which is longest. */
91
+ export function stretchCount(
92
+ segments: { from: number; to: number; label?: string }[],
93
+ from: number,
94
+ to: number,
95
+ ): StretchCount | null {
96
+ const inside = segments
97
+ .map((s) => ({ ...s, from: Math.max(s.from, from), to: Math.min(s.to, to) }))
98
+ .filter((s) => s.to - s.from > 1e-6)
99
+ .sort((a, b) => a.from - b.from);
100
+ if (!inside.length) return null;
101
+ const lens = inside.map((s) => s.to - s.from).sort((a, b) => a - b);
102
+ const m = lens.length >> 1;
103
+ const median = lens.length % 2 ? lens[m]! : (lens[m - 1]! + lens[m]!) / 2;
104
+ const long = inside.reduce((a, b) => (b.to - b.from > a.to - a.from ? b : a));
105
+ return {
106
+ count: inside.length,
107
+ median: round3(median),
108
+ longest: {
109
+ from: round3(long.from - from),
110
+ to: round3(long.to - from),
111
+ ...(long.label ? { label: long.label } : {}),
112
+ },
113
+ };
114
+ }
115
+
116
+ export type ReportJump = {
117
+ t: number;
118
+ kind: "cut" | "swap";
119
+ /** share of the frame that changed */
120
+ changed: number;
121
+ /** how far the content that changed moved, px of the page's frame; null:
122
+ * changed where it stood */
123
+ px: number | null;
124
+ dx: number;
125
+ dy: number;
126
+ /** of the changed blocks with texture, the share found moved together
127
+ * (`px`): near 1 when a part jumps whole; low when most of what changed
128
+ * changed where it stood and only some of it shifted along — a word
129
+ * rewritten in place, the text after it reflowing. Absent in older reports */
130
+ movedShare?: number;
131
+ };
132
+
133
+ type JumpIntent = "cut" | "hidden-cut" | "lift";
134
+
135
+ /** Match observations to what the page declares. A cut can land within a
136
+ * frame and a half of where it was written. A lift covers a turn when the
137
+ * moment it was measured at is within that same margin of the lift's span. */
138
+ export function reportIntent(
139
+ cuts: readonly number[],
140
+ events: readonly FilmEvent[],
141
+ segments: readonly FilmSegment[],
142
+ fps: number,
143
+ ) {
144
+ const hidden = hiddenCutTimes(events, segments);
145
+ const lifts = segments.filter((s) => s.handoff?.trim().toLowerCase() === "lift");
146
+ const margin = 1.5 / fps;
147
+ const near = (t: number, times: readonly number[]) => times.some((x) => Math.abs(x - t) <= margin);
148
+ const inLift = (t: number, tolerance: number) =>
149
+ lifts.some((s) => t >= s.from - tolerance && t <= s.to + tolerance);
150
+ return {
151
+ // merged as the events file merges them, so one cut written both ways counts once
152
+ declared: mergeTimes([...cuts, ...hidden], 1e-9).length,
153
+ jump(t: number): JumpIntent | null {
154
+ if (near(t, hidden)) return "hidden-cut";
155
+ if (near(t, cuts)) return "cut";
156
+ return inLift(t, 0.0005) ? "lift" : null;
157
+ },
158
+ turn(t: Pick<TurnBack, "at">): boolean {
159
+ return inLift(t.at, margin);
160
+ },
161
+ };
162
+ }
163
+
164
+ /** what this report calls content that moved: at least half of what changed
165
+ * (its textured blocks) found again, moved together */
166
+ export const MOVED_SHARE = 0.5;
167
+ const movedWhole = (j: ReportJump) =>
168
+ j.px != null && (j.movedShare == null || j.movedShare >= MOVED_SHARE);
169
+
170
+ export type ReportSlowText = {
171
+ from: number;
172
+ to: number;
173
+ /** the moving text's median speed, px of the page's frame per film frame
174
+ * (the median of the samples' medians), and the fastest piece's */
175
+ speed: number;
176
+ fastest: number;
177
+ };
178
+
179
+ export type FilmReport = {
180
+ film: string;
181
+ duration: number;
182
+ fps: number;
183
+ /** where the film starts on the page's timeline (a render of part of it);
184
+ * every time here is on the film's own clock, from 0 */
185
+ from: number;
186
+ /** seconds between the page's samples */
187
+ every: number;
188
+ /** the size the page was laid out at: every px here is one of these */
189
+ layout: { width: number; height: number };
190
+ /** how the slow text below is counted: device px per page px and frames
191
+ * a second — this render's, or for a draft a master's (full size, the
192
+ * page's rate, no --supersample) */
193
+ density: number;
194
+ slowFps: number;
195
+ /** the stretches the render drew finer because text moved slowly there
196
+ * (film clock), and how finely */
197
+ fine: { from: number; to: number }[];
198
+ fineSupersample: number;
199
+ draft: boolean;
200
+ /** the product's words on screen: its saved screens' (measured on the
201
+ * page) and those in its pictures (read from their files, estimated) */
202
+ productText: {
203
+ how: "measured" | "not measured";
204
+ note?: string;
205
+ /** pictures on screen read for text: one file per folder and size (a
206
+ * sequence of stills shares its layout); `skipped` folders past the
207
+ * first PICTURE_GROUPS; how: "not read" with no text recognizer here */
208
+ pictures: { how: "read" | "not read" | "none on screen"; files: number; skipped: number };
209
+ spans: { from: number; to: number; share: number; phone: number | null; at: number | null }[];
210
+ };
211
+ /** one-frame jumps of the picture the page did not declare as cuts */
212
+ jumps: {
213
+ how: "measured";
214
+ /** how many cuts the page declared */
215
+ declared: number;
216
+ list: ReportJump[];
217
+ intended?: { t: number; kind: JumpIntent }[];
218
+ };
219
+ moving: MovingMaterial;
220
+ slowText: { how: "measured" | "not measured"; note?: string; spans: ReportSlowText[] };
221
+ /** moves of the picture where what it ends up framing does not head
222
+ * straight for its place (the render's probe, in the events file) */
223
+ turns: { how: "measured" | "not measured"; list: TurnBack[]; intended?: TurnBack[] };
224
+ /** <img>, <video> and <canvas> drawn bigger than their own pixels, and
225
+ * layers under a perspective drawn bigger than Chrome draws them
226
+ * (`why` "tilt"), at the page samples: `ratio` the most frame px per px
227
+ * of the picture */
228
+ pastPixels: {
229
+ how: "measured" | "not measured";
230
+ note?: string;
231
+ list: {
232
+ src?: string;
233
+ label: string;
234
+ from: number;
235
+ to: number;
236
+ ratio: number;
237
+ why?: "tilt";
238
+ }[];
239
+ };
240
+ /** the parts the film named through product() (window.__otParts), each
241
+ * use read at its times; `named` 0: none was (a drag no part of
242
+ * components.json was pressed for is a use of no part) */
243
+ parts: {
244
+ how: "measured" | "not measured";
245
+ note?: string;
246
+ named: number;
247
+ uses: ReportPartUse[];
248
+ };
249
+ /** each boundary of the beat sheet (a segment's end inside the film) and
250
+ * what crossed it: the thing its segment named to `carry`, followed by the
251
+ * render (src/film/carry.ts), or what the segment says instead; `strip`
252
+ * a picture beside the film, one row per boundary: 0.3 s before, the
253
+ * boundary, 0.3 s after */
254
+ seams: {
255
+ how: "measured" | "not measured";
256
+ note?: string;
257
+ list: BoundaryCarry[];
258
+ strip: string | null;
259
+ };
260
+ /** the beat sheet's stretches inside the film, as the page wrote them
261
+ * (`tl.segment`): how many, the median length, the longest; absent when
262
+ * the page wrote none */
263
+ stretches?: StretchCount | null;
264
+ /** where the picture and the sound run opposite, half a second at a time
265
+ * (`film listen`'s own reading, from the events file's picture.energy) */
266
+ against: {
267
+ how: "measured" | "not measured";
268
+ note?: string;
269
+ list: PictureAgainstSound["opposite"];
270
+ };
271
+ /** the sound on its own: where several things in it change at once (the
272
+ * sharpest first), and how in tune it is, by register — `film listen`'s readings */
273
+ sound?:
274
+ | { how: "estimated"; changes: SoundChange[] | null; tuning: Tuning }
275
+ | { how: "not measured"; note: string };
276
+ /** wall time of the report, ms */
277
+ ms: number;
278
+ };
279
+
280
+ /** one use of a part (a camera move, a click, a drag, a mark) and where the
281
+ * part was at its times (its start, and its end when it has one) */
282
+ export type ReportPartUse = {
283
+ name: string;
284
+ /** its element on the screen it was read on at the use, `<state>:<eN>` */
285
+ ref: string;
286
+ use: string;
287
+ t: number;
288
+ end?: number;
289
+ label?: string;
290
+ seen: ReportPartSeen[];
291
+ /** why a time was not read (the page threw there) */
292
+ note?: string;
293
+ };
294
+
295
+ export type ReportPartSeen = {
296
+ t: number;
297
+ /** the screen it was read on; `shown` false: not the one shown then (the
298
+ * nearest screen it is on was read), `on` every screen it is on */
299
+ state: string;
300
+ shown: boolean;
301
+ /** the screen shown then, when the kit says */
302
+ showing?: string;
303
+ on: string[];
304
+ /** where it is in the picture, px of the frame */
305
+ picture: Box;
306
+ /** its share inside the frame, and the edge it is most past when not all */
307
+ inFrame: number;
308
+ edge?: "left" | "right" | "top" | "bottom";
309
+ /** what the page draws over it, by share of it; null: not read */
310
+ covered: { what: string; share: number }[] | null;
311
+ /** what shows it, and frame px per px of the still or recording */
312
+ drawn: "screen" | "still" | "recording";
313
+ sourcePx?: number;
314
+ };
315
+
316
+ export type FilmReportOptions = {
317
+ /** the film just rendered */
318
+ film: string;
319
+ /** its page (an .html file or its folder) and the folder it was served from */
320
+ page: string;
321
+ root?: string;
322
+ chromePath: string;
323
+ /** default: the film's events file beside it */
324
+ events?: string;
325
+ /** the render's --supersample and --draft: how finely it drew text */
326
+ supersample?: number;
327
+ draft?: boolean;
328
+ /** what the render drew finer (FilmRenderResult.fine, on the page's
329
+ * timeline) and how finely */
330
+ fine?: { from: number; to: number }[];
331
+ fineSupersample?: number;
332
+ /** seconds between page samples (default 0.5) */
333
+ every?: number;
334
+ onConsole?: (level: string, text: string) => void;
335
+ };
336
+
337
+ // --- live text moving under a pixel a frame ------------------------------------------------
338
+
339
+ type DriftPick = { node: Text; frame: HTMLIFrameElement | null };
340
+
341
+ // serialized into the page, like the one below: nothing outside its own
342
+ // body. Where each node kept by driftPick draws its first line now (page
343
+ // px), or null when it is gone or off the frame.
344
+ function driftMeasure(): ([number, number] | null)[] {
345
+ const vw = innerWidth;
346
+ const vh = innerHeight;
347
+ const picks = (window as unknown as { __otDrift?: DriftPick[] }).__otDrift ?? [];
348
+ return picks.map(({ node, frame }) => {
349
+ if (!node.isConnected) return null;
350
+ const range = node.ownerDocument.createRange();
351
+ range.selectNodeContents(node);
352
+ const r = Array.from(range.getClientRects()).find((x) => x.width >= 1 && x.height >= 1);
353
+ if (!r) return null;
354
+ let x = r.left;
355
+ let y = r.top;
356
+ if (frame) {
357
+ const fb = frame.getBoundingClientRect();
358
+ const sx = frame.offsetWidth ? fb.width / frame.offsetWidth : 1;
359
+ const sy = frame.offsetHeight ? fb.height / frame.offsetHeight : 1;
360
+ x = fb.left + (frame.clientLeft + r.left) * sx;
361
+ y = fb.top + (frame.clientTop + r.top) * sy;
362
+ }
363
+ if (x < 0 || y < 0 || x > vw || y > vh) return null;
364
+ return [x, y];
365
+ });
366
+ }
367
+
368
+ // Where the nodes kept at the sample before are now (`was`); then the
369
+ // visible text nodes now (the page and its same-origin frames), up to `max`
370
+ // spread over them, kept on window for the next sample, and where they are
371
+ // (`now`).
372
+ function driftPick(max: number, measure: () => ([number, number] | null)[]) {
373
+ const was = measure();
374
+ const all: DriftPick[] = [];
375
+ const visit = (doc: Document, frame: HTMLIFrameElement | null) => {
376
+ if (!doc.body) return;
377
+ const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT);
378
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
379
+ if (!(n.nodeValue ?? "").trim()) continue;
380
+ const el = n.parentElement;
381
+ if (!el || ["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"].includes(el.tagName)) continue;
382
+ if (!el.checkVisibility({ opacityProperty: true, visibilityProperty: true })) continue;
383
+ all.push({ node: n as Text, frame });
384
+ }
385
+ };
386
+ visit(document, null);
387
+ for (const f of Array.from(document.querySelectorAll("iframe"))) {
388
+ try {
389
+ if (f.contentDocument && f.checkVisibility({ opacityProperty: true }))
390
+ visit(f.contentDocument, f);
391
+ } catch {}
392
+ }
393
+ const step = Math.max(1, all.length / max);
394
+ const picks: DriftPick[] = [];
395
+ for (let k = 0; k < all.length && picks.length < max; k += step) picks.push(all[Math.floor(k)]!);
396
+ (window as unknown as { __otDrift: DriftPick[] }).__otDrift = picks;
397
+ return { was, now: measure() };
398
+ }
399
+
400
+ const DRIFT_MAX = 32;
401
+ /** asked of the page at each sample, on the same seek as its text */
402
+ export const DRIFT_JS = `(() => { const __name = (f) => f; return (${driftPick.toString()})(${DRIFT_MAX}, ${driftMeasure.toString()}); })()`;
403
+
404
+ type Place = [number, number] | null;
405
+
406
+ /** text that moves slower than one device pixel a frame, for a second or
407
+ * more. Each step holds the places of the same nodes at its two ends
408
+ * (page px), its speed what they moved over the frames between, so a
409
+ * steady move reads exactly and an uneven one as its average. A node
410
+ * moving at all (≥ 0.02 px a frame) counts; a step is slow when the median
411
+ * of those, in device px (× `density`), is under one. Steps that follow
412
+ * each other run into one span. */
413
+ export function slowTextSpans(
414
+ steps: readonly { from: number; to: number; at: readonly Place[]; next: readonly Place[] }[],
415
+ density: number,
416
+ fps: number,
417
+ ): ReportSlowText[] {
418
+ const spans: { from: number; to: number; speeds: number[]; fastest: number }[] = [];
419
+ for (const s of steps) {
420
+ const frames = (s.to - s.from) * fps;
421
+ if (!(frames > 0)) continue;
422
+ const v: number[] = [];
423
+ s.at.forEach((a, i) => {
424
+ const b = s.next[i];
425
+ if (!a || !b) return;
426
+ const d = Math.hypot(b[0] - a[0], b[1] - a[1]) / frames;
427
+ if (d >= 0.02) v.push(d);
428
+ });
429
+ if (!v.length) continue;
430
+ const m = median(v);
431
+ if (m * density >= 1) continue;
432
+ const open = spans.at(-1);
433
+ if (open && s.from <= open.to + 1e-6) {
434
+ open.to = s.to;
435
+ open.speeds.push(m);
436
+ open.fastest = Math.max(open.fastest, ...v);
437
+ } else spans.push({ from: s.from, to: s.to, speeds: [m], fastest: Math.max(...v) });
438
+ }
439
+ // a second or more: the end of an eased move passes under a pixel a frame too
440
+ return spans
441
+ .filter((s) => s.to - s.from >= 1 - 1e-6 && s.speeds.length >= 2)
442
+ .map((s) => ({
443
+ from: round3(s.from),
444
+ to: round3(s.to),
445
+ speed: round2(median(s.speeds)),
446
+ fastest: round2(s.fastest),
447
+ }));
448
+ }
449
+
450
+ // --- the parts the film named --------------------------------------------------------------
451
+
452
+ type PartUseRead = { use: string; t: number; end?: number; label?: string; ref?: string };
453
+ /** `key` the registry's own (kit/media.js), the same in every playing of
454
+ * the page; `reads` false: a drag no part of components.json was pressed
455
+ * for — nothing to read where it is */
456
+ type PartListed = { key: string; name: string; ref: string; reads: boolean; uses: PartUseRead[] };
457
+
458
+ // serialized into the page, like the two below. Every part product() made
459
+ // (kit/media.js, window.__otParts) and what the film did with it, as plain
460
+ // values.
461
+ function partsList(): PartListed[] {
462
+ type Reg = { key?: unknown; name?: unknown; ref?: unknown; uses?: unknown; at?: unknown };
463
+ const reg = (window as unknown as { __otParts?: Reg[] }).__otParts ?? [];
464
+ const num = (v: unknown) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
465
+ return reg.map((p, i) => ({
466
+ key: typeof p?.key === "string" && p.key ? p.key : `#${i}`,
467
+ name: String(p?.name ?? ""),
468
+ ref: typeof p?.ref === "string" ? p.ref : "",
469
+ reads: typeof p?.at === "function",
470
+ uses: (Array.isArray(p?.uses) ? (p.uses as Record<string, unknown>[]) : []).flatMap((u) => {
471
+ const t = num(u?.t);
472
+ if (t === undefined) return [];
473
+ const end = num(u.end);
474
+ return [
475
+ {
476
+ use: String(u.use ?? ""),
477
+ t,
478
+ ...(end !== undefined ? { end } : {}),
479
+ ...(typeof u.label === "string" ? { label: u.label } : {}),
480
+ ...(typeof u.ref === "string" ? { ref: u.ref } : {}),
481
+ },
482
+ ];
483
+ }),
484
+ }));
485
+ }
486
+
487
+ /** where each part with a use at the page's time `at` shows now, as the
488
+ * part says (at(t), coveredBy(t)) */
489
+ function partsAt(at: number): PartRead[] {
490
+ type Seen = {
491
+ state?: string;
492
+ shown?: boolean;
493
+ showing?: string;
494
+ picture?: { x: number; y: number; width: number; height: number };
495
+ drawn?: string;
496
+ sourcePx?: number;
497
+ };
498
+ type Reg = {
499
+ key?: unknown;
500
+ uses?: { t?: number; end?: number }[];
501
+ at?: (t: number) => Seen;
502
+ coveredBy?: (t: number) => { what: string; share: number }[];
503
+ in?: (state: string) => string | null;
504
+ states?: { state: string }[];
505
+ };
506
+ const reg = (window as unknown as { __otParts?: Reg[] }).__otParts ?? [];
507
+ const near = (v: unknown) => typeof v === "number" && Math.abs(v - at) < 1e-3;
508
+ return reg.flatMap((p, i): PartRead[] => {
509
+ if (typeof p?.at !== "function") return [];
510
+ const key = typeof p.key === "string" && p.key ? p.key : `#${i}`;
511
+ if (!(p.uses ?? []).some((u) => near(u?.t) || near(u?.end))) return [];
512
+ try {
513
+ const a = p.at(at);
514
+ let covered: { what: string; share: number }[] | null = null;
515
+ try {
516
+ covered = typeof p.coveredBy === "function" ? p.coveredBy(at) : null;
517
+ } catch {}
518
+ const b = a.picture ?? { x: 0, y: 0, width: 0, height: 0 };
519
+ return [
520
+ {
521
+ key,
522
+ state: String(a.state ?? ""),
523
+ ref: (a.state && p.in?.(a.state)) || "",
524
+ shown: a.shown !== false,
525
+ ...(typeof a.showing === "string" ? { showing: a.showing } : {}),
526
+ on: (p.states ?? []).map((s) => s.state),
527
+ picture: [b.x, b.y, b.width, b.height] as Box,
528
+ drawn: String(a.drawn ?? "screen"),
529
+ ...(typeof a.sourcePx === "number" ? { sourcePx: a.sourcePx } : {}),
530
+ covered,
531
+ },
532
+ ];
533
+ } catch (e) {
534
+ return [{ key, error: String((e as Error)?.message ?? e).split("\n")[0] }];
535
+ }
536
+ });
537
+ }
538
+
539
+ /** asked of the page at each sample: the drift reading, and the parts named */
540
+ const PAGE_JS = `(() => { const __name = (f) => f; return { ...${DRIFT_JS}, parts: (${partsList.toString()})() }; })()`;
541
+ /** asked of the page at a part's use time (the page's clock) */
542
+ const partsAtJs = (at: number) =>
543
+ `(() => { const __name = (f) => f; return (${partsAt.toString()})(${at}); })()`;
544
+
545
+ type PartRead = {
546
+ key: string;
547
+ error?: string;
548
+ state?: string;
549
+ ref?: string;
550
+ shown?: boolean;
551
+ showing?: string;
552
+ on?: string[];
553
+ picture?: Box;
554
+ drawn?: string;
555
+ sourcePx?: number;
556
+ covered?: { what: string; share: number }[] | null;
557
+ };
558
+
559
+ /** the share of a box inside the frame, and the edge it is most past */
560
+ export function inFrameOf(
561
+ b: Box,
562
+ frame: { width: number; height: number },
563
+ ): { inFrame: number; edge?: ReportPartSeen["edge"] } {
564
+ const [x, y, w, h] = b;
565
+ if (!(w > 0 && h > 0)) return { inFrame: 0 };
566
+ const iw = Math.max(0, Math.min(x + w, frame.width) - Math.max(x, 0));
567
+ const ih = Math.max(0, Math.min(y + h, frame.height) - Math.max(y, 0));
568
+ const inFrame = round3((iw * ih) / (w * h));
569
+ if (inFrame >= 0.999) return { inFrame: 1 };
570
+ const past: [NonNullable<ReportPartSeen["edge"]>, number][] = [
571
+ ["left", Math.max(0, -x) / w],
572
+ ["right", Math.max(0, x + w - frame.width) / w],
573
+ ["top", Math.max(0, -y) / h],
574
+ ["bottom", Math.max(0, y + h - frame.height) / h],
575
+ ];
576
+ past.sort((a, b) => b[1] - a[1]);
577
+ return { inFrame, edge: past[0]![0] };
578
+ }
579
+
580
+ /** every use of every part, once (a use the page makes again on each frame
581
+ * is one), its times on the film's clock; and the readings at those times
582
+ * (the page's clock, by `from`) set on each */
583
+ export function partUses(
584
+ listed: readonly PartListed[],
585
+ reads: readonly { t: number; parts: readonly PartRead[] }[],
586
+ o: { from: number; duration: number; layout: { width: number; height: number } },
587
+ ): ReportPartUse[] {
588
+ const out: ReportPartUse[] = [];
589
+ for (const p of listed) {
590
+ const seen = new Set<string>();
591
+ for (const u of p.uses) {
592
+ const key = `${u.use}|${u.t}|${u.end ?? ""}|${u.label ?? ""}`;
593
+ if (seen.has(key)) continue;
594
+ seen.add(key);
595
+ const times = [u.t, ...(u.end !== undefined && u.end !== u.t ? [u.end] : [])].map(
596
+ (v) => v - o.from,
597
+ );
598
+ const errors: string[] = [];
599
+ const read: ReportPartSeen[] = [];
600
+ // the ref read again at its time, over the one the use was given when
601
+ // the page set it up (the screens played may have changed since)
602
+ let ref = "";
603
+ const inside = times.filter((t) => t >= -1e-6 && t <= o.duration + 1e-6);
604
+ for (const t of inside) {
605
+ const r = reads.find((x) => Math.abs(x.t - t) < 1e-3)?.parts.find((x) => x.key === p.key);
606
+ if (!r) continue;
607
+ if (r.error || !r.picture) {
608
+ errors.push(`${fmt(t)}: ${r.error ?? "no picture"}`);
609
+ continue;
610
+ }
611
+ ref ||= r.ref ?? "";
612
+ const picture = r.picture.map((v) => Math.round(v * 10) / 10) as Box;
613
+ read.push({
614
+ t: round3(t),
615
+ state: r.state ?? "",
616
+ shown: r.shown !== false,
617
+ ...(r.showing ? { showing: r.showing } : {}),
618
+ on: r.on ?? [],
619
+ picture,
620
+ ...inFrameOf(picture, o.layout),
621
+ covered: r.covered
622
+ ? r.covered.map((c) => ({ what: c.what, share: round3(c.share) }))
623
+ : null,
624
+ drawn: r.drawn === "still" || r.drawn === "recording" ? r.drawn : "screen",
625
+ ...(r.sourcePx !== undefined ? { sourcePx: round2(r.sourcePx) } : {}),
626
+ });
627
+ }
628
+ // why nothing was read, when nothing was
629
+ const note = errors.length
630
+ ? `the part could not be read at ${errors.join("; ")}`
631
+ : read.length
632
+ ? undefined
633
+ : !inside.length
634
+ ? "not read (outside the film)"
635
+ : !p.reads
636
+ ? "no part of components.json was pressed: where it is not read"
637
+ : "not read at its times";
638
+ out.push({
639
+ name: p.name,
640
+ ref: ref || u.ref || p.ref,
641
+ use: u.use,
642
+ t: round3(u.t - o.from),
643
+ ...(u.end !== undefined ? { end: round3(u.end - o.from) } : {}),
644
+ ...(u.label !== undefined ? { label: u.label } : {}),
645
+ seen: read,
646
+ ...(note ? { note } : {}),
647
+ });
648
+ }
649
+ }
650
+ return out.sort((a, b) => a.t - b.t);
651
+ }
652
+
653
+ /** <img>, <video>, <canvas> and tilted layers drawn bigger than their own
654
+ * pixels at the samples, by picture: the stretches of samples it was, and
655
+ * the most frame px per px */
656
+ export function pastPixels(
657
+ samples: readonly PageTextSample[],
658
+ every: number,
659
+ ): FilmReport["pastPixels"]["list"] {
660
+ const runs = new Map<
661
+ string,
662
+ {
663
+ src?: string;
664
+ label: string;
665
+ why?: "tilt";
666
+ spans: { from: number; to: number; ratio: number }[];
667
+ }
668
+ >();
669
+ for (const s of samples)
670
+ for (const m of s.media) {
671
+ if (!m.drawn || !m.natural) continue;
672
+ const ratio = Math.max(m.drawn[2] / m.natural[0], m.drawn[3] / m.natural[1]);
673
+ if (!(ratio > 1.01)) continue;
674
+ const key = `${m.why ?? ""} ${m.src ?? m.label}`;
675
+ let r = runs.get(key);
676
+ if (!r) {
677
+ r = {
678
+ ...(m.src ? { src: m.src } : {}),
679
+ label: m.label,
680
+ ...(m.why ? { why: m.why } : {}),
681
+ spans: [],
682
+ };
683
+ runs.set(key, r);
684
+ }
685
+ const open = r.spans.at(-1);
686
+ if (open && s.t - open.to <= every * 1.5 + 1e-6) {
687
+ if (open.to !== s.t) open.to = s.t;
688
+ open.ratio = Math.max(open.ratio, ratio);
689
+ } else r.spans.push({ from: s.t, to: s.t, ratio });
690
+ }
691
+ return [...runs.values()]
692
+ .flatMap((r) =>
693
+ r.spans.map((x) => ({
694
+ ...(r.src ? { src: r.src } : {}),
695
+ label: r.label,
696
+ from: round3(x.from),
697
+ to: round3(x.to),
698
+ ratio: round2(x.ratio),
699
+ ...(r.why ? { why: r.why } : {}),
700
+ })),
701
+ )
702
+ .sort((a, b) => a.from - b.from);
703
+ }
704
+
705
+ // --- text in pictures ----------------------------------------------------------------------
706
+
707
+ /** folders (and sizes) of pictures read for text at most */
708
+ const PICTURE_GROUPS = 16;
709
+ const RASTER = /\.(png|jpe?g|webp|gif|tiff?|bmp|heic)$/i;
710
+
711
+ /** the text in the <img> pictures on screen, read by the system's text
712
+ * recognizer from the files themselves (not from the film's frames, which
713
+ * takes longer): one file per folder and size stands for the rest, and
714
+ * its lines are set where each picture is drawn at each sample, kept where
715
+ * their middle shows. Null frames when nothing could be read. */
716
+ export async function picturesText(
717
+ samples: readonly PageTextSample[],
718
+ root: string,
719
+ layout: { width: number; height: number },
720
+ ): Promise<{ frames: FrameText[] | null; pictures: FilmReport["productText"]["pictures"] }> {
721
+ const groupOf = new Map<string, string>();
722
+ const reps: string[] = [];
723
+ let skipped = 0;
724
+ const keyOf = (m: PageTextSample["media"][number]): string | null => {
725
+ if (!m.src || !m.drawn || !m.natural || /^[a-z]+:/i.test(m.src)) return null;
726
+ const file = resolve(root, `.${m.src.startsWith("/") ? "" : "/"}${m.src}`);
727
+ if (!RASTER.test(file) || !existsSync(file)) return null;
728
+ const key = `${dirname(file)}|${m.natural[0]}x${m.natural[1]}`;
729
+ if (!groupOf.has(key)) {
730
+ if (reps.length >= PICTURE_GROUPS) {
731
+ skipped++;
732
+ groupOf.set(key, "");
733
+ } else {
734
+ groupOf.set(key, file);
735
+ reps.push(file);
736
+ }
737
+ }
738
+ return groupOf.get(key) ? key : null;
739
+ };
740
+ const shown = samples.map((s) => s.media.map((m) => ({ m, key: keyOf(m) })));
741
+ if (!reps.length) return { frames: null, pictures: { how: "none on screen", files: 0, skipped } };
742
+ const bin = await ocrHelper();
743
+ const read = bin ? await runOcr(bin, reps).catch(() => null) : null;
744
+ if (!read) return { frames: null, pictures: { how: "not read", files: reps.length, skipped } };
745
+ const linesOf = new Map<string, NonNullable<(typeof read)[number]>["lines"]>();
746
+ const keys = [...groupOf].filter(([, f]) => f);
747
+ for (const [key, file] of keys) {
748
+ const r = read[reps.indexOf(file)];
749
+ if (r) linesOf.set(key, r.lines);
750
+ }
751
+ const area = layout.width * layout.height;
752
+ const frames: FrameText[] = samples.map((s, i) => {
753
+ const lines: OcrLine[] = [];
754
+ for (const { m, key } of shown[i]!) {
755
+ const L = key ? linesOf.get(key) : undefined;
756
+ if (!L || !m.drawn) continue;
757
+ const [dx, dy, dw, dh] = m.drawn;
758
+ const [bx, by, bw, bh] = m.box;
759
+ for (const l of L) {
760
+ const box: Box = [dx + l.x * dw, dy + l.y * dh, l.w * dw, l.h * dh];
761
+ const cx = box[0] + box[2] / 2;
762
+ const cy = box[1] + box[3] / 2;
763
+ if (cx < bx || cy < by || cx > bx + bw || cy > by + bh) continue;
764
+ lines.push({
765
+ box,
766
+ chars: l.s.replace(/\s+/g, "").length,
767
+ conf: l.c,
768
+ text: l.s.slice(0, 60),
769
+ });
770
+ }
771
+ }
772
+ const share = Math.min(1, lines.reduce((a, l) => a + l.box[2] * l.box[3], 0) / area);
773
+ return { t: s.t, how: "ocr", lines, share: round3(share) };
774
+ });
775
+ return { frames, pictures: { how: "read", files: reps.length, skipped } };
776
+ }
777
+
778
+ // --- the report ------------------------------------------------------------------------------
779
+
780
+ export async function filmReport(opts: FilmReportOptions): Promise<FilmReport> {
781
+ const start = Date.now();
782
+ const every = opts.every ?? 0.5;
783
+ const info = await probeFilm(opts.film);
784
+ const fps = info.fps;
785
+ const duration = info.frames / fps;
786
+ const layout = {
787
+ width: Number(info.record.width) || info.width,
788
+ height: Number(info.record.height) || info.height,
789
+ };
790
+ // a draft draws half size at its own rate: slow text is counted as a
791
+ // master would draw it
792
+ const density = opts.draft ? 1 : Math.max(1, Math.round(opts.supersample ?? 1));
793
+ const eventsFile = opts.events ?? eventsPathFor(opts.film);
794
+ const rawEvents: Record<string, unknown> = existsSync(eventsFile)
795
+ ? (JSON.parse(await readFile(eventsFile, "utf8")) as Record<string, unknown>)
796
+ : {};
797
+ const declared = (Array.isArray(rawEvents.declaredCuts) ? rawEvents.declaredCuts : [])
798
+ .filter((v): v is number => typeof v === "number" && Number.isFinite(v));
799
+ const intent = reportIntent(
800
+ declared, checkEvents(rawEvents.events), checkSegments(rawEvents.segments), fps,
801
+ );
802
+
803
+ const times: number[] = [];
804
+ for (let k = 0; k * every < duration - 0.5 / fps; k++) times.push(round3(k * every));
805
+ const ffmpeg = await resolveFfmpeg();
806
+ // the film's sound, decoded while the picture is read
807
+ const soundPcm = decodeMono(ffmpeg, opts.film).catch((e: Error) => e);
808
+ const gh = Math.max(8, Math.round((PROBE_W * info.height) / info.width / 2) * 2);
809
+ let pageNote: string | undefined;
810
+ const [grey, pageRead] = await Promise.all([
811
+ decodeGrey(ffmpeg, opts.film, PROBE_W, gh, fps),
812
+ readPageText({
813
+ page: opts.page,
814
+ root: opts.root,
815
+ chromePath: opts.chromePath,
816
+ from: info.from,
817
+ times,
818
+ width: layout.width,
819
+ height: layout.height,
820
+ fallback: layout,
821
+ extra: PAGE_JS,
822
+ onConsole: opts.onConsole,
823
+ }).catch((e: Error) => {
824
+ pageNote = `the page could not be played: ${e.message.split("\n")[0]}`;
825
+ return null;
826
+ }),
827
+ ]);
828
+
829
+ // the picture's jumps, and what each did to the content
830
+ const energy = frameEnergy(grey);
831
+ const cuts = findCuts(grey, energy);
832
+ const swaps = findSmallSwaps(grey, energy, cuts).map((s) => s.frame);
833
+ const kx = layout.width / grey.w;
834
+ const ky = layout.height / grey.h;
835
+ const intendedJumps: NonNullable<FilmReport["jumps"]["intended"]> = [];
836
+ const jumps: ReportJump[] = [...cuts, ...swaps]
837
+ .sort((a, b) => a - b)
838
+ .map((f) => ({ f, t: frameTime(grey, f) }))
839
+ .filter(({ t }) => {
840
+ const kind = intent.jump(t + info.from);
841
+ if (kind && kind !== "cut") intendedJumps.push({ t: round3(t), kind });
842
+ return !kind;
843
+ })
844
+ .map(({ f, t }) => {
845
+ const m = jumpMove(grey, f);
846
+ const dx = m.shift ? m.shift.x * kx : 0;
847
+ const dy = m.shift ? m.shift.y * ky : 0;
848
+ return {
849
+ t: round3(t),
850
+ kind: cuts.includes(f) ? "cut" : "swap",
851
+ changed: round2(m.changed),
852
+ px: m.shift ? Math.round(Math.hypot(dx, dy)) : null,
853
+ dx: Math.round(dx),
854
+ dy: Math.round(dy),
855
+ movedShare: m.textured > 0 ? round2(m.moved / m.textured) : 0,
856
+ };
857
+ });
858
+
859
+ // the page: the product's words, how it was shot, text that creeps
860
+ let productText: FilmReport["productText"] = {
861
+ how: "not measured",
862
+ note: pageNote ?? "the page was not played",
863
+ pictures: { how: "not read", files: 0, skipped: 0 },
864
+ spans: [],
865
+ };
866
+ let slowText: FilmReport["slowText"] = {
867
+ how: "not measured",
868
+ note: pageNote ?? "the page was not played",
869
+ spans: [],
870
+ };
871
+ let slowFps = fps;
872
+ if (pageRead) {
873
+ const phoneScale = PHONE_W / layout.width;
874
+ const pics = await picturesText(pageRead.samples, pageRead.root, layout);
875
+ const text = textTimeline(pageRead.samples, pics.frames, {
876
+ width: layout.width,
877
+ height: layout.height,
878
+ segments: [],
879
+ every,
880
+ });
881
+ productText = {
882
+ how: "measured",
883
+ ...(pageRead.failed.length
884
+ ? { note: `the page threw at ${pageRead.failed.length} sample time(s), left out` }
885
+ : {}),
886
+ pictures: pics.pictures,
887
+ spans: productTextSpans(text.samples, phoneScale, every, {
888
+ pictures: pics.pictures.how === "read",
889
+ }).map((s) => {
890
+ // the sample its smallest median is from
891
+ let at: number | null = null;
892
+ let low = Number.POSITIVE_INFINITY;
893
+ for (const x of text.samples)
894
+ if (x.t >= s.from - 1e-6 && x.t < s.to - 1e-6 && x.productMedian != null)
895
+ if (x.productMedian < low) {
896
+ low = x.productMedian;
897
+ at = x.t;
898
+ }
899
+ return { from: s.from, to: s.to, share: s.productShare, phone: s.phoneMedian, at };
900
+ }),
901
+ };
902
+ const pts = (v: unknown): Place[] =>
903
+ (Array.isArray(v) ? v : []).map((p) =>
904
+ Array.isArray(p) && Number.isFinite(p[0]) && Number.isFinite(p[1])
905
+ ? ([p[0], p[1]] as [number, number])
906
+ : null,
907
+ );
908
+ const drift = pageRead.samples.map((s) => {
909
+ const e = (s.extra ?? {}) as { was?: unknown; now?: unknown };
910
+ return { t: s.t, was: pts(e.was), now: pts(e.now) };
911
+ });
912
+ // each sample beside the one before it (a sample the page threw at
913
+ // leaves a gap, not a step)
914
+ const steps = drift.slice(1).flatMap((s, i) => {
915
+ const p = drift[i]!;
916
+ return s.t - p.t <= every * 1.5 + 1e-6
917
+ ? [{ from: p.t, to: s.t, at: p.now, next: s.was }]
918
+ : [];
919
+ });
920
+ slowFps = opts.draft ? (pageRead.info.fps ?? 60) : fps;
921
+ slowText = { how: "measured", spans: slowTextSpans(steps, density, slowFps) };
922
+ }
923
+ const moving = readMovingMaterial(pageRead?.samples ?? null, pageRead?.root ?? null, {
924
+ ...(pageNote ? { note: pageNote } : {}),
925
+ });
926
+
927
+ // the parts the film named: every one, from the samples (a part made late
928
+ // shows in the later ones), then the page played again at their uses' times
929
+ let parts: FilmReport["parts"] = {
930
+ how: "not measured",
931
+ note: pageNote ?? "the page was not played",
932
+ named: 0,
933
+ uses: [],
934
+ };
935
+ if (pageRead) {
936
+ const listed = new Map<string, PartListed>();
937
+ for (const s of pageRead.samples) {
938
+ const got = (s.extra as { parts?: unknown } | undefined)?.parts;
939
+ if (Array.isArray(got)) for (const p of got as PartListed[]) listed.set(p.key, p);
940
+ }
941
+ const all = [...listed.values()];
942
+ const times = [
943
+ ...new Set(
944
+ all
945
+ .flatMap((p) => p.uses.flatMap((u) => [u.t, ...(u.end !== undefined ? [u.end] : [])]))
946
+ .map((v) => round3(v - info.from))
947
+ .filter((t) => t >= -1e-6 && t <= duration + 1e-6),
948
+ ),
949
+ ].sort((a, b) => a - b);
950
+ let note: string | undefined;
951
+ const reads = times.length
952
+ ? await readPageText({
953
+ page: opts.page,
954
+ root: opts.root,
955
+ chromePath: opts.chromePath,
956
+ from: info.from,
957
+ times,
958
+ width: layout.width,
959
+ height: layout.height,
960
+ fallback: layout,
961
+ extra: partsAtJs,
962
+ onConsole: opts.onConsole,
963
+ }).catch((e: Error) => {
964
+ note = `the page could not be played again at the parts' times: ${e.message.split("\n")[0]}`;
965
+ return null;
966
+ })
967
+ : null;
968
+ parts = {
969
+ how: "measured",
970
+ ...(note ? { note } : {}),
971
+ named: all.filter((p) => p.reads).length,
972
+ uses: partUses(
973
+ all,
974
+ (reads?.samples ?? []).map((s) => ({
975
+ t: s.t,
976
+ parts: Array.isArray(s.extra) ? (s.extra as PartRead[]) : [],
977
+ })),
978
+ { from: info.from, duration, layout },
979
+ ),
980
+ };
981
+ }
982
+
983
+ // what crossed each boundary, and a strip of it to look at
984
+ const ev = rawEvents as unknown as FilmEvents;
985
+ let seams: FilmReport["seams"];
986
+ if (!Array.isArray(rawEvents.segments) || !rawEvents.curves)
987
+ seams = {
988
+ how: "not measured",
989
+ note: "no beat sheet in the events file",
990
+ list: [],
991
+ strip: null,
992
+ };
993
+ else {
994
+ const list = boundaryCarries(ev, info.from).filter(
995
+ (b) => b.at > 0 && b.at < duration - 0.5 / fps,
996
+ );
997
+ let strip: string | null = null;
998
+ let note: string | undefined;
999
+ if (list.length)
1000
+ strip = await seamStrip(ffmpeg, opts.film, list, fps, duration).catch((e: Error) => {
1001
+ note = `no strip: ${e.message.split("\n")[0]}`;
1002
+ return null;
1003
+ });
1004
+ seams = { how: "measured", ...(note ? { note } : {}), list, strip };
1005
+ }
1006
+ const stretches = Array.isArray(rawEvents.segments)
1007
+ ? stretchCount(rawEvents.segments as FilmSegment[], info.from, info.from + duration)
1008
+ : null;
1009
+ // the sound on its own
1010
+ let sound: FilmReport["sound"];
1011
+ const pcm = await soundPcm;
1012
+ if (pcm instanceof Error)
1013
+ sound = {
1014
+ how: "not measured",
1015
+ // a render with no soundtrack has no audio stream to decode
1016
+ note: /does not contain any stream|matches no streams|no sound/i.test(pcm.message)
1017
+ ? "the film has no sound"
1018
+ : (pcm.message.split("\n")[0] ?? ""),
1019
+ };
1020
+ else
1021
+ sound = pcm.length
1022
+ ? {
1023
+ how: "estimated",
1024
+ changes: soundChanges(pcm, { max: SOUND_CHANGES }),
1025
+ tuning: tuning(pcm),
1026
+ }
1027
+ : { how: "not measured", note: "the film has no sound" };
1028
+ // the picture against the sound
1029
+ let against: FilmReport["against"];
1030
+ let picEnergy: ReturnType<typeof pictureEnergyOf> = null;
1031
+ try {
1032
+ // on this film's clock: parseFilmEvents moves a range's curve to start at its own 0
1033
+ picEnergy = rawEvents.curves ? pictureEnergyOf(parseFilmEvents(rawEvents)) : null;
1034
+ } catch {
1035
+ // an events file listen cannot read: the line says not measured
1036
+ }
1037
+ if (!picEnergy)
1038
+ against = { how: "not measured", note: "no picture.energy in the events file", list: [] };
1039
+ else {
1040
+ const loud = await momentaryLoudness(ffmpeg, opts.film, duration).catch(() => []);
1041
+ if (!loud.length) against = { how: "not measured", note: "the film has no sound", list: [] };
1042
+ else {
1043
+ against = {
1044
+ how: "measured",
1045
+ list: pictureAgainstSound(halfSeconds(loud, picEnergy, duration)).opposite,
1046
+ };
1047
+ }
1048
+ }
1049
+
1050
+ const turns: FilmReport["turns"] = { how: "not measured", list: [] };
1051
+ if (Array.isArray(rawEvents.turnsBack)) {
1052
+ turns.how = "measured";
1053
+ for (const x of rawEvents.turnsBack as TurnBack[]) {
1054
+ const turn = {
1055
+ ...x,
1056
+ from: round3(x.from - info.from),
1057
+ to: round3(x.to - info.from),
1058
+ at: round3(x.at - info.from),
1059
+ };
1060
+ if (intent.turn(x)) {
1061
+ turns.intended ??= [];
1062
+ turns.intended.push(turn);
1063
+ }
1064
+ else turns.list.push(turn);
1065
+ }
1066
+ }
1067
+
1068
+ return {
1069
+ film: opts.film,
1070
+ duration: round3(duration),
1071
+ fps,
1072
+ from: info.from,
1073
+ every,
1074
+ layout,
1075
+ density,
1076
+ slowFps,
1077
+ fine: (opts.fine ?? []).map((f) => ({
1078
+ from: round3(f.from - info.from),
1079
+ to: round3(f.to - info.from),
1080
+ })),
1081
+ fineSupersample: opts.fineSupersample ?? 1,
1082
+ turns,
1083
+ draft: !!opts.draft,
1084
+ pastPixels: pageRead
1085
+ ? { how: "measured", list: pastPixels(pageRead.samples, every) }
1086
+ : { how: "not measured", note: pageNote ?? "the page was not played", list: [] },
1087
+ parts,
1088
+ productText,
1089
+ jumps: {
1090
+ how: "measured",
1091
+ declared: intent.declared,
1092
+ list: jumps,
1093
+ ...(intendedJumps.length ? { intended: intendedJumps } : {}),
1094
+ },
1095
+ moving,
1096
+ slowText,
1097
+ seams,
1098
+ stretches,
1099
+ against,
1100
+ sound,
1101
+ ms: Date.now() - start,
1102
+ };
1103
+ }
1104
+
1105
+ /** where a film's strip of boundaries goes: `film.mp4` → `film.seams.jpg` */
1106
+ export function seamStripPathFor(film: string): string {
1107
+ return eventsPathFor(film).replace(/\.events\.json$/, ".seams.jpg");
1108
+ }
1109
+
1110
+ /** one row per boundary, 0.3 s before it, on it, 0.3 s after: a picture of
1111
+ * what each boundary looks like, to open beside the numbers */
1112
+ async function seamStrip(
1113
+ ffmpeg: string,
1114
+ film: string,
1115
+ list: readonly BoundaryCarry[],
1116
+ fps: number,
1117
+ duration: number,
1118
+ ): Promise<string> {
1119
+ const last = Math.max(0, Math.round(duration * fps) - 1);
1120
+ const frames = list.flatMap((b) =>
1121
+ [-0.3, 0, 0.3].map((d) => Math.min(last, Math.max(0, Math.round((b.at + d) * fps)))),
1122
+ );
1123
+ // each frame decoded once, in film order; laid out row by row as the
1124
+ // boundaries ask, a frame two boundaries share drawn in both rows
1125
+ const pick = [...new Set(frames)].sort((a, b) => a - b);
1126
+ const out = seamStripPathFor(film);
1127
+ await rm(out, { force: true });
1128
+ const tmp = await mkdtemp(join(tmpdir(), "open-take-seams-"));
1129
+ try {
1130
+ await runTool(ffmpeg, [
1131
+ "-v",
1132
+ "error",
1133
+ "-i",
1134
+ film,
1135
+ "-vf",
1136
+ `select='${pick.map((n) => `eq(n,${n})`).join("+")}',scale=480:-2`,
1137
+ "-fps_mode",
1138
+ "passthrough",
1139
+ join(tmp, "f%05d.png"),
1140
+ ]);
1141
+ const file = (n: number) => join(tmp, `f${String(pick.indexOf(n) + 1).padStart(5, "0")}.png`);
1142
+ const listFile = join(tmp, "rows.txt");
1143
+ await writeFile(listFile, frames.map((n) => `file '${file(n)}'\n`).join(""));
1144
+ await runTool(ffmpeg, [
1145
+ "-v",
1146
+ "error",
1147
+ "-f",
1148
+ "concat",
1149
+ "-safe",
1150
+ "0",
1151
+ "-i",
1152
+ listFile,
1153
+ "-vf",
1154
+ `tile=3x${Math.ceil(frames.length / 3)}:padding=4:color=white`,
1155
+ "-frames:v",
1156
+ "1",
1157
+ "-q:v",
1158
+ "3",
1159
+ "-y",
1160
+ out,
1161
+ ]);
1162
+ } finally {
1163
+ await rm(tmp, { recursive: true, force: true });
1164
+ }
1165
+ return out;
1166
+ }
1167
+
1168
+ const fmt = (t: number) => `${t.toFixed(2)} s`;
1169
+
1170
+ const direction = (dx: number, dy: number) => {
1171
+ const h = dx < 0 ? "left" : "right";
1172
+ const v = dy < 0 ? "up" : "down";
1173
+ const ax = Math.abs(dx);
1174
+ const ay = Math.abs(dy);
1175
+ if (ax >= 2 * ay) return h;
1176
+ if (ay >= 2 * ax) return v;
1177
+ return `${v}-${h}`;
1178
+ };
1179
+
1180
+ /** jumps with moved content, close ones (under a second apart) as one run */
1181
+ function jumpRuns(list: readonly ReportJump[]): { big: number; t: number; text: string }[] {
1182
+ const moved = list.filter(movedWhole);
1183
+ const runs: ReportJump[][] = [];
1184
+ for (const j of moved) {
1185
+ const last = runs.at(-1);
1186
+ if (last && j.t - last.at(-1)!.t < 1) last.push(j);
1187
+ else runs.push([j]);
1188
+ }
1189
+ return runs.map((r) => {
1190
+ const big = Math.max(...r.map((j) => j.changed));
1191
+ if (r.length === 1) {
1192
+ const j = r[0]!;
1193
+ return {
1194
+ big,
1195
+ t: j.t,
1196
+ text: `${fmt(j.t)} ${j.px} px ${direction(j.dx, j.dy)} (${pct(j.changed)} of the frame changed)`,
1197
+ };
1198
+ }
1199
+ const px = r.map((j) => j.px!);
1200
+ const lo = Math.min(...px);
1201
+ const hi = Math.max(...px);
1202
+ const dirs = new Set(r.map((j) => direction(j.dx, j.dy)));
1203
+ const dir = dirs.size === 1 ? [...dirs][0] : "in different directions";
1204
+ return {
1205
+ big,
1206
+ t: r[0]!.t,
1207
+ text: `${fmt(r[0]!.t)}–${fmt(r.at(-1)!.t)} ${r.length} jumps of ${lo === hi ? lo : `${lo}–${hi}`} px ${dir} (up to ${pct(big)} of the frame changed)`,
1208
+ };
1209
+ });
1210
+ }
1211
+
1212
+ const pct = (v: number) => `${Math.round(v * 100)}%`;
1213
+
1214
+ /** the lines `film render` prints: one per thing measured, then where the
1215
+ * full report is */
1216
+ export function formatFilmReport(r: FilmReport, o: { probe: string }): string[] {
1217
+ const L: string[] = [];
1218
+ const w = r.layout.width;
1219
+ const clock = r.from
1220
+ ? `; times from the film's start, ${fmt(r.from)} on the page's timeline`
1221
+ : "";
1222
+ L.push(
1223
+ `measured on this film (px of the ${w}×${r.layout.height} frame${clock}; facts, not grades):`,
1224
+ );
1225
+
1226
+ // the product's words
1227
+ const pt = r.productText;
1228
+ const P = pt.pictures;
1229
+ const from = `its saved screens${
1230
+ P.how === "read"
1231
+ ? `, and text in its pictures read from ${P.files} file(s), one per folder and size${P.skipped ? ` (${P.skipped} more folder(s) not read)` : ""}`
1232
+ : P.how === "not read" && P.files
1233
+ ? "; text in pictures not read — no text recognizer here"
1234
+ : ""
1235
+ }`;
1236
+ if (pt.how === "not measured") L.push(` product's text: not measured — ${pt.note}`);
1237
+ else if (!pt.spans.length)
1238
+ L.push(
1239
+ ` product's text (${from}): in no sample is it most of the text on screen, nor its median under ${PHONE_SMALL_PX} px on a phone ${PHONE_W} px wide`,
1240
+ );
1241
+ else {
1242
+ const scale = PHONE_W / w;
1243
+ const shown = pt.spans.slice(0, 3).map((s) => {
1244
+ const size =
1245
+ s.phone != null
1246
+ ? `, median down to ${s.phone} px on a phone (${Math.round(s.phone / scale)} px here${s.at != null ? `, at ${fmt(s.at)}` : ""})`
1247
+ : "";
1248
+ return `${fmt(s.from)}–${fmt(s.to)} up to ${Math.round(s.share * 100)}% of the text${size}`;
1249
+ });
1250
+ L.push(
1251
+ ` product's text (${from}): most of the text on screen, or its median under ${PHONE_SMALL_PX} px on a phone ${PHONE_W} px wide — ${shown.join("; ")}${pt.spans.length > 3 ? `; ${pt.spans.length - 3} more` : ""}`,
1252
+ );
1253
+ }
1254
+
1255
+ // jumps not declared as cuts
1256
+ const J = r.jumps;
1257
+ const runs = jumpRuns(J.list);
1258
+ const inPlace = J.list.filter((j) => j.px == null);
1259
+ const newPictures = inPlace.filter((j) => j.kind === "cut" && j.changed >= 0.5).length;
1260
+ const swapped = inPlace.length - newPictures;
1261
+ // most of what changed changed where it stood, some of it shifted along
1262
+ const partly = J.list.filter((j) => j.px != null && !movedWhole(j));
1263
+ const rest = [
1264
+ newPictures ? `${newPictures} to a new picture` : "",
1265
+ swapped
1266
+ ? `${swapped} changed in place (a word, a number, a picture swapped where it stood)`
1267
+ : "",
1268
+ partly.length
1269
+ ? `changed in place with part of it shifted along (a word rewritten and the text beside it reflowing reads this way) — ${partly
1270
+ .slice(0, 4)
1271
+ .map(
1272
+ (j) =>
1273
+ `${fmt(j.t)} ${pct(j.changed)} of the frame changed, ${pct(j.movedShare ?? 0)} of that found ${j.px} px ${direction(j.dx, j.dy)}`,
1274
+ )
1275
+ .join("; ")}${partly.length > 4 ? `; ${partly.length - 4} more` : ""}`
1276
+ : "",
1277
+ ].filter(Boolean);
1278
+ const scope = J.declared
1279
+ ? `the page declares ${J.declared} cut(s)`
1280
+ : 'the page declares no cuts: events of kind "cut" or "hidden-cut", a segment whose handoff is "hidden-cut", or "lift" for a whole segment that rises out of the picture';
1281
+ if (!J.list.length) L.push(` one-frame jumps not declared as cuts: none (${scope})`);
1282
+ else
1283
+ L.push(
1284
+ ` one-frame jumps not declared as cuts (${scope}): ${[
1285
+ runs.length
1286
+ ? // the largest changes first in, then in time order
1287
+ `content moved — ${[...runs]
1288
+ .sort((a, b) => b.big - a.big || a.t - b.t)
1289
+ .slice(0, 4)
1290
+ .sort((a, b) => a.t - b.t)
1291
+ .map((x) => x.text)
1292
+ .join("; ")}${runs.length > 4 ? `; ${runs.length - 4} more` : ""}`
1293
+ : "",
1294
+ ...rest,
1295
+ ]
1296
+ .filter(Boolean)
1297
+ .join(
1298
+ "; ",
1299
+ )}${runs.length ? ". A part the product moved between saved screens can be kept in place with `hold()` (kit/media.js), when that is wanted" : ""}`,
1300
+ );
1301
+
1302
+ // material taken while changing
1303
+ const m = r.moving;
1304
+ if (m.how === "not measured") L.push(` pictures taken mid-change: not measured — ${m.note}`);
1305
+ else if (!m.matched)
1306
+ L.push(
1307
+ ` pictures taken mid-change: no picture on screen matched a shoot's log (shots.json, ${m.logs} found)`,
1308
+ );
1309
+ else if (!m.list.length)
1310
+ L.push(
1311
+ ` pictures taken mid-change: none (${m.matched} picture(s) on screen matched to a shoot's log${m.unrecorded ? `, ${m.unrecorded} of them from a shoot that did not record it, which says nothing either way` : ""})`,
1312
+ );
1313
+ else {
1314
+ const shown = m.list.slice(0, 3).map((e) => {
1315
+ const at =
1316
+ e.times.length > 1 ? `${fmt(e.times[0]!)}–${fmt(e.times.at(-1)!)}` : fmt(e.times[0]!);
1317
+ const what = e.texts[0]
1318
+ ? ` ${JSON.stringify(e.texts[0].before)} → ${JSON.stringify(e.texts[0].after)}`
1319
+ : e.moved
1320
+ ? " text moved"
1321
+ : e.animations
1322
+ ? ` ${e.animations} animation(s) running`
1323
+ : "";
1324
+ return `${e.src} on screen ${at}${what}`;
1325
+ });
1326
+ L.push(
1327
+ ` pictures taken while the product's screen was still changing: ${shown.join("; ")}${m.list.length > 3 ? `; ${m.list.length - 3} more` : ""}`,
1328
+ );
1329
+ }
1330
+
1331
+ // pictures drawn bigger than their own pixels
1332
+ const pp = r.pastPixels;
1333
+ const ppScope = `<img>, <video>, <canvas> and tilted layers on the page, every ${fmt(r.every)}`;
1334
+ if (pp.how === "not measured")
1335
+ L.push(` pictures drawn past their own pixels: not measured — ${pp.note}`);
1336
+ else if (!pp.list.length) L.push(` pictures drawn past their own pixels (${ppScope}): none`);
1337
+ else {
1338
+ const shown = pp.list.slice(0, 4).map((x) => {
1339
+ const at = x.from === x.to ? fmt(x.from) : `${fmt(x.from)}–${fmt(x.to)}`;
1340
+ return x.why === "tilt"
1341
+ ? `${x.label} (under a perspective) ${at}, up to ${x.ratio} frame px per px Chrome drew`
1342
+ : `${x.src ?? x.label} ${at}, up to ${x.ratio} frame px per source px`;
1343
+ });
1344
+ L.push(
1345
+ ` pictures drawn past their own pixels (${ppScope}): ${shown.join("; ")}${pp.list.length > 4 ? `; ${pp.list.length - 4} more` : ""}`,
1346
+ );
1347
+ if (pp.list.some((x) => x.why === "tilt"))
1348
+ L.push(
1349
+ " a layer under a CSS perspective that would cover more than the frame's area is drawn by Chrome at about the frame's area and stretched, so its text goes soft (--supersample does not change it); a tilted box no bigger than the part it shows (overflow: hidden around it) is drawn sharp",
1350
+ );
1351
+ }
1352
+
1353
+ // moves that turn back
1354
+ const tb = r.turns;
1355
+ if (tb.how === "not measured")
1356
+ L.push(" moves that turn back: not measured (a draft does not probe its frames)");
1357
+ else if (!tb.list.length)
1358
+ L.push(
1359
+ " moves of the picture where what it ends up framing heads the wrong way first, or past its place and back: none",
1360
+ );
1361
+ else {
1362
+ const shown = tb.list.slice(0, 4).map((x) => {
1363
+ const way = x.axis === "x" ? "across" : "up or down";
1364
+ return `${fmt(x.from)}–${fmt(x.to)} ${x.kind === "back" ? "the wrong way first" : "past its place and back"}, ${x.px} px ${way} (at ${fmt(x.at)})`;
1365
+ });
1366
+ L.push(
1367
+ ` moves of the picture where what it ends up framing does not head straight there: ${shown.join("; ")}${tb.list.length > 4 ? `; ${tb.list.length - 4} more` : ""}. A view whose centre and zoom move apart, or that is kept inside the page every frame rather than once per move, bends this way; kit/camera.js moves straight`,
1368
+ );
1369
+ }
1370
+ const intended: string[] = [];
1371
+ const seen = (kind: JumpIntent) => J.intended?.filter((j) => j.kind === kind).length ?? 0;
1372
+ const count = (n: number, what: string) => `${n} ${what}${n === 1 ? "" : "s"}`;
1373
+ const hidden = seen("hidden-cut");
1374
+ const lifts = seen("lift");
1375
+ const turns = tb.intended?.length ?? 0;
1376
+ if (hidden) intended.push(`${count(hidden, "picture jump")} at cuts hidden in motion`);
1377
+ if (lifts || turns)
1378
+ intended.push(`${[lifts && count(lifts, "picture jump"), turns && count(turns, "turn")]
1379
+ .filter(Boolean).join(" and ")} during layered lifts`);
1380
+ if (intended.length) L.push(` declared intent seen: ${intended.join(", ")}`);
1381
+
1382
+ // live text under a pixel a frame
1383
+ const s = r.slowText;
1384
+ const drawn = r.draft
1385
+ ? ` (counted as a master draws it: full size, ${r.slowFps} fps)`
1386
+ : r.density === 1
1387
+ ? ""
1388
+ : ` (this render draws ${r.density} device px per px)`;
1389
+ if (s.how === "not measured") L.push(` slowly moving live text: not measured — ${s.note}`);
1390
+ else if (!s.spans.length)
1391
+ L.push(` live text moving under a device pixel a frame for a second or more: none${drawn}`);
1392
+ else {
1393
+ const shown = s.spans.slice(0, 3).map((x) => {
1394
+ const covered = r.fine.reduce(
1395
+ (a, f) => a + Math.max(0, Math.min(f.to, x.to) - Math.max(f.from, x.from)),
1396
+ 0,
1397
+ );
1398
+ const share = covered / Math.max(1e-6, x.to - x.from);
1399
+ const finer = share >= 0.9 ? r.fineSupersample : 1;
1400
+ const every = 1 / (x.speed * r.density * finer);
1401
+ const how =
1402
+ share >= 0.9
1403
+ ? `, drawn at ${r.fineSupersample}×`
1404
+ : share > 0.05
1405
+ ? `, drawn at ${r.fineSupersample}× for ${Math.round(share * 100)}% of it`
1406
+ : "";
1407
+ return `${fmt(x.from)}–${fmt(x.to)} ${x.speed} px a frame, the fastest piece ${x.fastest} (at the median, a step about every ${every < 10 ? every.toFixed(1) : Math.round(every)} frames${how})`;
1408
+ });
1409
+ L.push(
1410
+ ` live text moving under a device pixel a frame${drawn}: ${shown.join("; ")}${s.spans.length > 3 ? `; ${s.spans.length - 3} more` : ""}. Chrome draws glyphs on whole device pixels, so such text can move in steps (measured here: where the text is, not the picture); a render without --supersample draws the frames where text moves this slowly at ${FINE_SUPERSAMPLE}× (--supersample 1 does not), and \`film picture\` draws a saved screen as one picture that moves smoothly`,
1411
+ );
1412
+ }
1413
+
1414
+ // the parts the film named
1415
+ const pa = r.parts;
1416
+ if (pa.how === "not measured")
1417
+ L.push(` parts named through product(): not measured — ${pa.note}`);
1418
+ else if (!pa.named && !pa.uses.length)
1419
+ L.push(" parts: none named through product() (kit/media.js)");
1420
+ else if (!pa.uses.length)
1421
+ L.push(
1422
+ ` parts named through product(): ${pa.named}, none used by the camera, the cursor or mark() on the film's clock`,
1423
+ );
1424
+ else {
1425
+ L.push(
1426
+ ` parts the film named (through product(); times on the film's clock)${pa.note ? ` — ${pa.note}` : ""}:`,
1427
+ );
1428
+ for (const u of pa.uses.slice(0, PART_LINES)) L.push(` ${partLine(u)}`);
1429
+ if (pa.uses.length > PART_LINES) L.push(` … ${pa.uses.length - PART_LINES} more use(s)`);
1430
+ }
1431
+
1432
+ // the stretches, counted
1433
+ const sc = r.stretches;
1434
+ if (sc)
1435
+ L.push(
1436
+ ` stretches (the beat sheet's segments, \`tl.segment\`): ${sc.count}, median ${fmt(sc.median)}, the longest ${fmt(sc.longest.to - sc.longest.from)} (${fmt(sc.longest.from)}–${fmt(sc.longest.to)}${sc.longest.label ? `, ${JSON.stringify(sc.longest.label)}` : ""})`,
1437
+ );
1438
+
1439
+ // the boundaries, and what crossed each
1440
+ const sm = r.seams;
1441
+ if (!sm) {
1442
+ // a report made before boundaries were read
1443
+ } else if (sm.how === "not measured") L.push(` boundaries: not measured — ${sm.note}`);
1444
+ else if (!sm.list.length)
1445
+ L.push(
1446
+ " boundaries: none — the beat sheet has no segment ending inside the film (kit/time.js `tl.segment`)",
1447
+ );
1448
+ else {
1449
+ const count = (k: string) => sm.list.filter((b) => b.how.kind === k).length;
1450
+ const tally = [
1451
+ "carried",
1452
+ "anchored",
1453
+ "bare",
1454
+ "cut",
1455
+ "lift",
1456
+ "words",
1457
+ "unwritten",
1458
+ "not rendered",
1459
+ ]
1460
+ .map((k) => [k, count(k)] as const)
1461
+ .filter(([, n]) => n)
1462
+ .map(([k, n]) => `${n} ${k}`)
1463
+ .join(", ");
1464
+ L.push(
1465
+ ` boundaries (segment ends; a segment's \`carry\` followed from 1 s before to 0.4 s after — carried: still there 0.25 s past it, or grown to fill the frame, and moved or resized; anchored: there unchanged, or only fading out across it; bare: gone by then): ${tally}${sm.strip ? `; each one as a row (−0.3 s, the boundary, +0.3 s): ${sm.strip}` : ""}${sm.note ? ` (${sm.note})` : ""}`,
1466
+ );
1467
+ for (const b of sm.list.slice(0, BOUNDARY_LINES)) {
1468
+ const said = b.handoff ? ` "${b.handoff}"` : "";
1469
+ const what = b.carry ? ` ${b.carry}` : "";
1470
+ const h = b.how;
1471
+ const line = h.measured
1472
+ ? `${h.kind}${carryChange(b) ? ` (${carryChange(b)})` : ""}${h.note ? ` — ${h.note}` : ""}`
1473
+ : h.kind === "cut"
1474
+ ? /hidden/i.test(b.handoff ?? "")
1475
+ ? "a cut hidden under motion, on purpose"
1476
+ : "a hard cut, on purpose"
1477
+ : h.kind === "lift"
1478
+ ? "a layer lifting out on its own, declared"
1479
+ : h.kind === "words"
1480
+ ? "nothing named to follow (`carry`)"
1481
+ : h.kind === "unwritten"
1482
+ ? "nothing written"
1483
+ : "outside what was rendered";
1484
+ L.push(` ${fmt(b.at)}${said}${what}: ${line}`);
1485
+ }
1486
+ if (sm.list.length > BOUNDARY_LINES)
1487
+ L.push(` … ${sm.list.length - BOUNDARY_LINES} more boundary(ies)`);
1488
+ // the same change at every carried boundary is easy to miss from inside
1489
+ const carried = sm.list.filter((b) => b.how.measured && b.how.kind === "carried");
1490
+ const filled = carried.filter((b) => b.how.measured && b.how.fill >= CARRY_FILL).length;
1491
+ if (carried.length >= 2 && filled >= 2)
1492
+ L.push(` ${filled} of the ${carried.length} carried thing(s) grew to fill the frame`);
1493
+ }
1494
+
1495
+ // the picture against the sound
1496
+ const ag = r.against;
1497
+ if (!ag) {
1498
+ // a report made before the picture was set against the sound
1499
+ } else if (ag.how === "not measured")
1500
+ L.push(` picture against sound: not measured — ${ag.note}`);
1501
+ else
1502
+ L.push(
1503
+ ` picture against sound (half seconds; one above this film's median, the other below, reaching its top and bottom thirds): ${
1504
+ ag.list.length
1505
+ ? [...ag.list]
1506
+ .sort((a, b) => b.to - b.from - (a.to - a.from) || a.from - b.from)
1507
+ .slice(0, AGAINST_LINES)
1508
+ .sort((a, b) => a.from - b.from)
1509
+ .map(
1510
+ (x) =>
1511
+ `${fmt(x.from)}–${fmt(x.to)} ${x.kind === "busy-quiet" ? "the picture busy while the sound is quiet" : "the picture changing little frame to frame while the sound is loud"}`,
1512
+ )
1513
+ .join("; ") +
1514
+ (
1515
+ ag.list.length > AGAINST_LINES
1516
+ ? `; ${ag.list.length - AGAINST_LINES} shorter one(s) — \`film listen\` lays them all out`
1517
+ : ""
1518
+ )
1519
+ : "nowhere"
1520
+ }`,
1521
+ );
1522
+
1523
+ // the sound on its own
1524
+ const so = r.sound;
1525
+ if (so?.how === "not measured") L.push(` sound: not measured — ${so.note}`);
1526
+ else if (so) {
1527
+ L.push(
1528
+ ` sound, where several things change at once (against the 3 s before; sharpest first): ${
1529
+ !so.changes
1530
+ ? "too short to set 3 s either side of a moment against each other"
1531
+ : so.changes.length
1532
+ ? so.changes
1533
+ .map(
1534
+ (c) =>
1535
+ `${fmt(c.t)} ${c.parts.join(", ")} — ${c.leadIn ?? "nothing leads into it"}`,
1536
+ )
1537
+ .join("; ")
1538
+ : "nowhere stands out"
1539
+ } (${so.changes ? "estimated" : "not measured"})`,
1540
+ );
1541
+ const reg = so.tuning.registers.filter((x) => x.frames >= 20);
1542
+ if (so.tuning.reference != null && reg.length)
1543
+ L.push(
1544
+ ` sound, in tune: ${reg.map((x) => `${x.name} register ${Math.round(x.inTune * 100)}% of its pitched frames within 15 cents of the piece's tuning`).join(", ")} (estimated)`,
1545
+ );
1546
+ }
1547
+
1548
+ L.push(
1549
+ `full report (text in pictures, camera, sound, beat sheet): ${o.probe} — measured in ${(r.ms / 1000).toFixed(1)} s; --no-report leaves this out`,
1550
+ );
1551
+ return L;
1552
+ }
1553
+
1554
+ /** uses of parts listed at most, one line each */
1555
+ const PART_LINES = 8;
1556
+ /** the sound's sharpest changes listed at the end of a render */
1557
+ const SOUND_CHANGES = 3;
1558
+ /** boundaries listed at most, one line each */
1559
+ const BOUNDARY_LINES = 12;
1560
+ /** stretches where picture and sound run opposite, listed at most (the longest) */
1561
+ const AGAINST_LINES = 5;
1562
+
1563
+ const USED: Record<string, string> = {
1564
+ frame: "framed",
1565
+ cut: "cut to",
1566
+ click: "clicked",
1567
+ move: "moved to",
1568
+ type: "typed into",
1569
+ drag: "dragged",
1570
+ mark: "named",
1571
+ };
1572
+
1573
+ /** one use of a part: who, what, when, then the facts at its times */
1574
+ function partLine(u: ReportPartUse): string {
1575
+ const who = [u.name !== u.ref ? u.name : "", u.ref].filter(Boolean).join(" ");
1576
+ const what = `${USED[u.use] ?? u.use}${u.label ? ` (${JSON.stringify(u.label)})` : ""}`;
1577
+ const when = u.end !== undefined && u.end !== u.t ? `${fmt(u.t)}–${fmt(u.end)}` : fmt(u.t);
1578
+ // at which time, when the use has more than one
1579
+ const at = (t: number) => (u.seen.length > 1 ? ` at ${fmt(t)}` : "");
1580
+ const facts: string[] = [];
1581
+ const off = u.seen.find((x) => !x.shown);
1582
+ if (off) {
1583
+ const on =
1584
+ off.on.length > 4
1585
+ ? `${off.on.slice(0, 3).join(", ")}, … ${off.on.length - 3} more`
1586
+ : off.on.join(", ");
1587
+ facts.push(
1588
+ `not on the screen shown then${off.showing ? ` (${off.showing})` : ""}${at(off.t)}; it is on ${on || "no screen"}`,
1589
+ );
1590
+ }
1591
+ if (u.seen.length) {
1592
+ const worst = [...u.seen].sort((a, b) => a.inFrame - b.inFrame)[0]!;
1593
+ if (worst.inFrame >= 1) facts.push("in frame");
1594
+ else if (worst.inFrame <= 0) facts.push(`outside the frame${at(worst.t)}`);
1595
+ else facts.push(`off the frame's ${worst.edge} edge ${pct(1 - worst.inFrame)}${at(worst.t)}`);
1596
+ const read = u.seen.filter((x) => x.covered);
1597
+ const cover = (x: ReportPartSeen) => (x.covered ?? []).reduce((a, c) => a + c.share, 0);
1598
+ const most = [...read].sort((a, b) => cover(b) - cover(a))[0];
1599
+ if (!read.length) facts.push("what covers it not read");
1600
+ else if (most && cover(most) > 0) {
1601
+ const by = most.covered!;
1602
+ facts.push(
1603
+ `${pct(cover(most))} covered by ${by
1604
+ .slice(0, 2)
1605
+ .map((c) => c.what)
1606
+ .join(", ")}${by.length > 2 ? `, ${by.length - 2} more` : ""}${at(most.t)}`,
1607
+ );
1608
+ }
1609
+ const dense = u.seen
1610
+ .filter((x) => x.sourcePx !== undefined)
1611
+ .sort((a, b) => b.sourcePx! - a.sourcePx!)[0];
1612
+ if (dense) {
1613
+ const of = dense.drawn === "recording" ? "recording" : "still";
1614
+ facts.push(
1615
+ `drawn from ${of === "still" ? "a still" : "the recording"} at ${dense.sourcePx!.toFixed(1)} frame px per ${of} px${at(dense.t)}`,
1616
+ );
1617
+ }
1618
+ }
1619
+ if (u.note) facts.push(u.note);
1620
+ if (!facts.length) facts.push("not read");
1621
+ return `${who} ${what} ${when}: ${facts.join("; ")}`;
1622
+ }
1623
+
1624
+ function median(xs: readonly number[]): number {
1625
+ if (!xs.length) return 0;
1626
+ const s = [...xs].sort((a, b) => a - b);
1627
+ const m = s.length >> 1;
1628
+ return s.length % 2 ? s[m]! : (s[m - 1]! + s[m]!) / 2;
1629
+ }
1630
+ const round2 = (v: number) => Math.round(v * 100) / 100;
1631
+ const round3 = (v: number) => Math.round(v * 1000) / 1000;