@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,996 @@
1
+ // `open-take film check`: what a finished film can be measured for without
2
+ // eyes or ears — the defects its author cannot perceive, reported with times.
3
+ //
4
+ // Picture: the format, frames that freeze for one frame while everything around
5
+ // them moves (a dropped or repeated frame), runs of alternating still/moving
6
+ // frames (a lower-rate cadence showing through), hard cuts, black frames,
7
+ // flashes — a few frames unlike the frames on both sides (a clip cut on its
8
+ // transition frame) — and shots that start on near-blank frames (the cut came
9
+ // before the shot's content).
10
+ // Sound: loudness (integrated, range, true peak), silences, and clicks — single-
11
+ // sample jumps the waveform around them does not explain (a cut envelope, a
12
+ // splice).
13
+ // With the film's page: text over text, text into a small painted element and
14
+ // text cut by the frame's edge, read from the page over the film's time, and
15
+ // the smallest text on screen (layout.ts).
16
+ // A film may flash on purpose: what the page marks as intended
17
+ // (window.__film.marks, carried in the film by `film render`) is listed as
18
+ // marked, not as a defect.
19
+ // Nothing here judges taste; every finding is a time to go and look at. The
20
+ // report ends by saying what it measured and what it does not (motion between
21
+ // frames, how text looks while it moves), so an empty list reads as no more
22
+ // than that.
23
+
24
+ import { spawn } from "node:child_process";
25
+ import { readdir, readFile } from "node:fs/promises";
26
+ import { join, relative } from "node:path";
27
+ import { resolveFfmpeg, resolveFfprobe, runTool } from "../ffmpeg";
28
+ import { type FilmMark, filmMarks } from "./clock";
29
+ import { type LayoutSpan, readPageLayout } from "./layout";
30
+ import { FILM_TAG, type FilmRecord, resolveFilmPage } from "./render";
31
+
32
+ export type FilmCheckIssue = { severity: "error" | "warn" | "info"; message: string };
33
+
34
+ export type FilmCheck = {
35
+ file: string;
36
+ durationS: number;
37
+ video: {
38
+ codec: string;
39
+ profile: string | null;
40
+ width: number;
41
+ height: number;
42
+ fps: number;
43
+ pixFmt: string;
44
+ frames: number;
45
+ } | null;
46
+ audio: {
47
+ codec: string;
48
+ sampleRate: number;
49
+ channels: number;
50
+ /** integrated loudness, LUFS */
51
+ lufs: number | null;
52
+ /** loudness range, LU */
53
+ lra: number | null;
54
+ /** true peak, dBFS */
55
+ truePeak: number | null;
56
+ } | null;
57
+ /** seconds where one frame repeats inside motion */
58
+ stalls: number[];
59
+ /** runs of alternating still/moving frames: where they start and how many
60
+ * frames; with `every`, a frame held about every that many frames (held
61
+ * frames a few apart, four or more, rather than alternating) */
62
+ cadence: { at: number; frames: number; every?: number }[];
63
+ /** seconds of hard cuts */
64
+ cuts: number[];
65
+ /** frames unlike the frames on both sides: where they start and how many */
66
+ flashes: { at: number; frames: number }[];
67
+ /** near-blank frames a shot starts on (or the film does): where, how many */
68
+ blanks: { at: number; frames: number }[];
69
+ black: { start: number; end: number }[];
70
+ silences: { start: number; end: number }[];
71
+ /** seconds of isolated sample jumps */
72
+ clicks: number[];
73
+ /** what the page marks as intended, in the film's own time (its first frame is 0) */
74
+ marks: FilmMark[];
75
+ /** the page read for its layout (the size it was laid out at), when given */
76
+ page: { file: string; width: number; height: number; every: number } | null;
77
+ /** text that collides or leaves the frame, from when to when; null without the page */
78
+ layout: LayoutSpan[] | null;
79
+ /** text drawn turned, skewed or mirrored: named, not read; null without the page */
80
+ unreadText: string[] | null;
81
+ /** the smallest text drawn — information, not a verdict; null without the page */
82
+ smallestText: { px: number; at: number; text: string } | null;
83
+ /** the shoot logs and saved screens in the folder served to the page —
84
+ * information; null without the page */
85
+ material?: PageMaterial | null;
86
+ /** what this check measured and what it does not: plain lines, no grade */
87
+ scope?: FilmCheckScope;
88
+ issues: FilmCheckIssue[];
89
+ };
90
+
91
+ export type FilmCheckScope = { measured: string; notMeasured: string };
92
+
93
+ export type FilmCheckExpect = { width?: number; height?: number; fps?: number };
94
+
95
+ /** the film's page, to read its layout over the film's time */
96
+ export type FilmCheckPage = {
97
+ /** an .html file, or a directory holding index.html */
98
+ page: string;
99
+ /** the directory served to it (as for `film render`) */
100
+ root?: string;
101
+ chromePath: string;
102
+ /** seconds between layout samples (default 0.25) */
103
+ every?: number;
104
+ onConsole?: (level: string, text: string) => void;
105
+ };
106
+
107
+ export async function checkFilm(
108
+ file: string,
109
+ expect: FilmCheckExpect = {},
110
+ page?: FilmCheckPage,
111
+ ): Promise<FilmCheck> {
112
+ const [ffmpeg, ffprobe] = await Promise.all([resolveFfmpeg(), resolveFfprobe()]);
113
+ const probe = JSON.parse(
114
+ await runTool(ffprobe, ["-v", "error", "-show_streams", "-show_format", "-of", "json", file]),
115
+ ) as {
116
+ streams?: Record<string, string | number | undefined>[];
117
+ format?: { duration?: string; tags?: Record<string, string> };
118
+ };
119
+ const vs = probe.streams?.find((s) => s.codec_type === "video");
120
+ const as = probe.streams?.find((s) => s.codec_type === "audio");
121
+ const durationS = Number(probe.format?.duration ?? 0);
122
+ const rate = (r: unknown) => {
123
+ const [n, d] = String(r ?? "0/1")
124
+ .split("/")
125
+ .map(Number);
126
+ return d ? n! / d : 0;
127
+ };
128
+ const video = vs
129
+ ? {
130
+ codec: String(vs.codec_name),
131
+ profile: vs.profile ? String(vs.profile) : null,
132
+ width: Number(vs.width),
133
+ height: Number(vs.height),
134
+ fps: Math.round(rate(vs.avg_frame_rate) * 1000) / 1000,
135
+ pixFmt: String(vs.pix_fmt),
136
+ frames: Number(vs.nb_frames ?? 0),
137
+ }
138
+ : null;
139
+ const record = filmRecord(probe.format?.tags?.[FILM_TAG]);
140
+
141
+ const result: FilmCheck = {
142
+ file,
143
+ durationS,
144
+ video,
145
+ audio: null,
146
+ stalls: [],
147
+ cadence: [],
148
+ cuts: [],
149
+ flashes: [],
150
+ blanks: [],
151
+ black: [],
152
+ silences: [],
153
+ clicks: [],
154
+ marks: [],
155
+ page: null,
156
+ layout: null,
157
+ unreadText: null,
158
+ smallestText: null,
159
+ issues: [],
160
+ };
161
+ if (video) {
162
+ const fps = video.fps || 60;
163
+ const { picture, log } = await readFilmPicture(ffmpeg, file, video.width, video.height, fps);
164
+ Object.assign(result, motionFindings(picture.diffs, fps));
165
+ result.flashes = picture.flashes;
166
+ result.blanks = picture.blanks;
167
+ // a frame held between the cut into a flash or a blank start and the cut
168
+ // out of it is that finding, not a frame repeating inside motion
169
+ const held = [...picture.flashes, ...picture.blanks];
170
+ result.stalls = result.stalls.filter(
171
+ (t) => !held.some((r) => t > r.at - 1e-6 && t < r.at + r.frames / fps - 1e-6),
172
+ );
173
+ for (const m of log.matchAll(/black_start:([\d.]+) black_end:([\d.]+)/g))
174
+ result.black.push({ start: Number(m[1]), end: Number(m[2]) });
175
+ }
176
+ if (as) {
177
+ const log = await runTool(
178
+ ffmpeg,
179
+ [
180
+ "-nostats",
181
+ "-v",
182
+ "info",
183
+ "-i",
184
+ file,
185
+ "-vn",
186
+ "-af",
187
+ "ebur128=peak=true,silencedetect=n=-45dB:d=0.4",
188
+ "-f",
189
+ "null",
190
+ "-",
191
+ ],
192
+ { stderr: true },
193
+ );
194
+ const summary = log.slice(log.lastIndexOf("Summary:"));
195
+ const num = (re: RegExp) => {
196
+ const m = re.exec(summary);
197
+ return m ? Number(m[1]) : null;
198
+ };
199
+ result.audio = {
200
+ codec: String(as.codec_name),
201
+ sampleRate: Number(as.sample_rate),
202
+ channels: Number(as.channels),
203
+ lufs: num(/I:\s+(-?[\d.]+) LUFS/),
204
+ lra: num(/LRA:\s+(-?[\d.]+) LU/),
205
+ truePeak: num(/Peak:\s+(-?[\d.]+) dBFS/),
206
+ };
207
+ let start: number | null = null;
208
+ for (const m of log.matchAll(/silence_(start|end): (-?[\d.]+)/g)) {
209
+ if (m[1] === "start") start = Number(m[2]);
210
+ else if (start != null) {
211
+ result.silences.push({ start, end: Number(m[2]) });
212
+ start = null;
213
+ }
214
+ }
215
+ if (start != null) result.silences.push({ start, end: durationS });
216
+ result.clicks = findClicks(await pcm(ffmpeg, file), 48_000);
217
+ }
218
+ // where the film starts on the page's timeline (a render from the middle)
219
+ const from = record?.from ?? 0;
220
+ let marks = record?.marks ?? [];
221
+ if (page) {
222
+ const every = page.every ?? 0.25;
223
+ const read = await readPageLayout({
224
+ page: page.page,
225
+ root: page.root,
226
+ chromePath: page.chromePath,
227
+ from,
228
+ duration: durationS,
229
+ every,
230
+ // the size the film was laid out at; without it, the page's own size
231
+ width: record?.width || undefined,
232
+ height: record?.height || undefined,
233
+ fallback: { width: video?.width ?? 1920, height: video?.height ?? 1080 },
234
+ onConsole: page.onConsole,
235
+ });
236
+ result.page = { file: page.page, width: read.width, height: read.height, every };
237
+ result.layout = read.spans;
238
+ result.unreadText = read.unread;
239
+ result.smallestText = read.smallest;
240
+ result.material = await readPageMaterial(page.page, page.root).catch(() => null);
241
+ // the page as it is now says what is meant: a mark added since the
242
+ // render counts without rendering again
243
+ marks = filmMarks(read.marks);
244
+ }
245
+ result.marks = marks
246
+ .map((m) => ({ at: ms(m.at - from), until: ms(m.until - from), what: m.what }))
247
+ .filter((m) => m.until >= -MARK_SLACK && m.at <= durationS + MARK_SLACK);
248
+ result.issues = judgeFilm(result, expect);
249
+ result.scope = filmCheckScope(result);
250
+ return result;
251
+ }
252
+
253
+ /** what a check covered, from what it read: the streams it had and whether
254
+ * the page was played — so an empty list of findings is not read as more
255
+ * than it is. Motion between frames is `film probe`'s; how text looks while
256
+ * it moves no tool here reads. */
257
+ export function filmCheckScope(c: FilmCheck): FilmCheckScope {
258
+ const parts = ["the format"];
259
+ if (c.video)
260
+ parts.push(
261
+ "frames repeating inside motion, a lower-rate cadence, cuts, black, flash and blank frames",
262
+ );
263
+ if (c.audio) parts.push("loudness, silences and clicks");
264
+ if (c.page)
265
+ parts.push(
266
+ `text over text, into painted elements and off the frame's edge, and the smallest text (the page read every ${c.page.every}s)`,
267
+ );
268
+ return {
269
+ measured: parts.join("; "),
270
+ notMeasured: `${c.page ? "" : "the text's layout (it reads the page with --page); "}how far things move from one frame to the next (a part of the picture jumping, a push and its speed) — \`film probe\` reads one-frame jumps and the picture's zoom and travel; how text looks while it moves (on a live page under a slow push it can step a pixel at a time) — \`film still\` at times one frame apart shows it`,
271
+ };
272
+ }
273
+
274
+ const ms = (s: number) => Math.round(s * 1000) / 1000;
275
+
276
+ /** what `film render` wrote into the film about its page (FILM_TAG); null for
277
+ * a film from anywhere else. A size it does not have is 0. */
278
+ function filmRecord(raw: string | undefined): FilmRecord | null {
279
+ if (!raw) return null;
280
+ try {
281
+ const r = JSON.parse(raw) as Partial<FilmRecord>;
282
+ const positive = (v: unknown) => (typeof v === "number" && v > 0 ? v : 0);
283
+ return {
284
+ from: positive(r.from),
285
+ width: positive(r.width),
286
+ height: positive(r.height),
287
+ marks: filmMarks(r.marks),
288
+ };
289
+ } catch {
290
+ return null;
291
+ }
292
+ }
293
+
294
+ // --- the picture ------------------------------------------------------------------
295
+
296
+ /** the picture is read in grey at this width, as tall as the film keeps it */
297
+ const READ_WIDTH = 320;
298
+ /** a flash's spread is counted on a grid of this many cells */
299
+ const GRID_X = 16;
300
+ const GRID_Y = 9;
301
+
302
+ // A flash: up to FLASH_MAX_S of frames unlike the frames on both sides — a clip
303
+ // cut on its transition frame, a frame from another scene, a white frame. Read
304
+ // from the twelve exploration films, every version (60 fps masters, 30 fps
305
+ // drafts): the two flashes a judge saw (a game's flat transition frame, 2 and 4
306
+ // frames long at 60 fps) against the moments that came closest to them —
307
+ // - they arrive with a change 3.3–12× the change before them and inside them,
308
+ // where the near misses this leaves out arrive at 2.1–2.7×;
309
+ // - it moves a cell of a 16×9 grid by 8 of 255 or more in 85–92 % of the
310
+ // picture, where a number ticking over in a count-up moves 12–19 %;
311
+ // - they leave by 11–14 of 255, 1.6–2.8× the change after them, where a
312
+ // white flash that fades out leaves at 1.4×;
313
+ // - arriving and leaving add up to 2.0–2.8× the change from the frame before
314
+ // them to the frame after (the picture comes back, or goes on to something
315
+ // like it), where a cut followed by a fade or motion adds up to 1.3–1.55×
316
+ // and a lower-rate clip stepping through a growing shape 1.3–1.65×.
317
+ // Nothing else in the twelve films meets all four.
318
+ const FLASH_MAX_S = 1 / 15; // 4 frames at 60 fps, 2 at 30
319
+ const FLASH_ARRIVE = 3;
320
+ const FLASH_SPREAD = 0.5;
321
+ const SPREAD_LEVEL = 8;
322
+ const FLASH_LEAVE = 8;
323
+ const FLASH_DEPART = 1.5;
324
+ const FLASH_DETOUR = 1.8;
325
+
326
+ // A shot that starts blank: a cut onto near-blank frames, before the shot's
327
+ // content arrives. In the twelve films — and in versions from before their
328
+ // authors fixed it — those frames measure 0–1.9 of 255 in standard deviation,
329
+ // and the first one with the shot's content fading in 2 and up (a vignette with
330
+ // nothing on it, 3.5); they last 1–4 frames (up to 0.13 s), where a black or
331
+ // white beat held on purpose lasts 0.22 s and more; and the change into them is
332
+ // a cut, 6–236 of 255 at least 3× the change before it, where a fade to black
333
+ // steps by 0–4 like the steps around it. The film's first frame counts as a
334
+ // shot's start: it is the film's poster.
335
+ const BLANK_SD = 2;
336
+ const BLANK_MAX_S = 0.2;
337
+ const BLANK_CUT = 3;
338
+
339
+ /** what the picture measured to */
340
+ export type Picture = {
341
+ /** mean change (0–255) between consecutive frames: `diffs[i]` compares
342
+ * frames i and i+1 */
343
+ diffs: number[];
344
+ flashes: { at: number; frames: number }[];
345
+ blanks: { at: number; frames: number }[];
346
+ };
347
+
348
+ /** Grey frames in, one at a time (width × height bytes each, in order): how
349
+ * much the picture changes from frame to frame, its flashes and its blank
350
+ * shot starts. A flash is judged against frames a few apart, so the last
351
+ * few are kept — a film of any length reads in little memory. */
352
+ export function readPicture(width: number, height: number, fps: number) {
353
+ const size = width * height;
354
+ const longest = Math.max(1, Math.round(fps * FLASH_MAX_S));
355
+ // the grid cell each pixel falls in, and how many pixels each cell holds
356
+ const cellOf = new Uint16Array(size);
357
+ const cellSize = new Float64Array(GRID_X * GRID_Y);
358
+ for (let y = 0; y < height; y++)
359
+ for (let x = 0; x < width; x++) {
360
+ const c =
361
+ Math.min(GRID_Y - 1, Math.floor((y * GRID_Y) / height)) * GRID_X +
362
+ Math.min(GRID_X - 1, Math.floor((x * GRID_X) / width));
363
+ cellOf[y * width + x] = c;
364
+ cellSize[c]!++;
365
+ }
366
+ /** change[k]: mean |difference| between frames k−1 and k (change[0] = 0) */
367
+ const change: number[] = [];
368
+ /** spread[k]: the share of grid cells whose brightness moved from k−1 to k */
369
+ const spread: number[] = [];
370
+ /** each frame's standard deviation: how near it is to one colour */
371
+ const deviation: number[] = [];
372
+ /** for a frame entered by a change a flash could leave by: how far it is
373
+ * from each of the frames 2 … longest+1 before it */
374
+ const apart = new Map<number, number[]>();
375
+ const recent: Uint8Array[] = [];
376
+ let lastCells: Float64Array | null = null;
377
+ const differ = (a: Uint8Array, b: Uint8Array) => {
378
+ let s = 0;
379
+ for (let k = 0; k < size; k++) s += Math.abs(a[k]! - b[k]!);
380
+ return s / size;
381
+ };
382
+ return {
383
+ push(frame: Uint8Array): void {
384
+ let sum = 0;
385
+ let squares = 0;
386
+ const cells = new Float64Array(GRID_X * GRID_Y);
387
+ for (let k = 0; k < size; k++) {
388
+ const v = frame[k]!;
389
+ sum += v;
390
+ squares += v * v;
391
+ cells[cellOf[k]!]! += v;
392
+ }
393
+ for (let c = 0; c < cells.length; c++) cells[c]! /= cellSize[c]!;
394
+ const mean = sum / size;
395
+ deviation.push(Math.sqrt(Math.max(0, squares / size - mean * mean)));
396
+ const last = recent.at(-1);
397
+ if (last && lastCells) {
398
+ const d = differ(last, frame);
399
+ change.push(d);
400
+ let moved = 0;
401
+ for (let c = 0; c < cells.length; c++)
402
+ if (Math.abs(cells[c]! - lastCells[c]!) >= SPREAD_LEVEL) moved++;
403
+ spread.push(moved / cells.length);
404
+ if (d >= FLASH_LEAVE) {
405
+ const far: number[] = [];
406
+ for (let m = 2; m <= Math.min(longest + 1, recent.length); m++)
407
+ far.push(differ(recent[recent.length - m]!, frame));
408
+ apart.set(change.length - 1, far);
409
+ }
410
+ } else {
411
+ change.push(0);
412
+ spread.push(0);
413
+ }
414
+ recent.push(frame);
415
+ if (recent.length > longest + 1) recent.shift();
416
+ lastCells = cells;
417
+ },
418
+ done(): Picture {
419
+ const n = change.length;
420
+ const at = (k: number) => ms(k / fps);
421
+ // frames [i, i + len): what arrives at i and leaves at i + len
422
+ const runs: [number, number][] = [];
423
+ for (let i = 1; i < n - 1; i++)
424
+ for (let len = 1; len <= longest && i + len < n; len++) {
425
+ const enter = change[i]!;
426
+ const leave = change[i + len]!;
427
+ const across = apart.get(i + len)?.[len - 1];
428
+ if (leave < FLASH_LEAVE || across === undefined || spread[i]! < FLASH_SPREAD) continue;
429
+ let inside = 0;
430
+ for (let k = i + 1; k < i + len; k++) inside = Math.max(inside, change[k]!);
431
+ const before = change[i - 1]!;
432
+ const after = change[i + len + 1] ?? 0;
433
+ if (
434
+ enter >= FLASH_ARRIVE * Math.max(before, inside, 0.5) &&
435
+ leave >= FLASH_DEPART * Math.max(after, inside, 0.5) &&
436
+ enter + leave >= FLASH_DETOUR * Math.max(across, 0.5)
437
+ )
438
+ runs.push([i, i + len]);
439
+ }
440
+ // one flash may read as runs of more than one length: one finding
441
+ const merged: [number, number][] = [];
442
+ for (const r of runs.sort((a, b) => a[0] - b[0] || a[1] - b[1])) {
443
+ const last = merged.at(-1);
444
+ if (last && r[0] < last[1]) last[1] = Math.max(last[1], r[1]);
445
+ else merged.push([r[0], r[1]]);
446
+ }
447
+ const blanks: Picture["blanks"] = [];
448
+ for (let k = 0; k < n; ) {
449
+ if (deviation[k]! >= BLANK_SD) {
450
+ k++;
451
+ continue;
452
+ }
453
+ let j = k;
454
+ while (j < n && deviation[j]! < BLANK_SD) j++;
455
+ const cut =
456
+ k === 0 ||
457
+ (change[k]! >= BLANK_CUT && change[k]! >= FLASH_ARRIVE * Math.max(change[k - 1]!, 0.5));
458
+ // content follows, soon: a longer blank is a beat; one inside a flash is the flash
459
+ if (
460
+ cut &&
461
+ j < n &&
462
+ (j - k) / fps < BLANK_MAX_S &&
463
+ !merged.some(([a, b]) => a <= k && j <= b)
464
+ )
465
+ blanks.push({ at: at(k), frames: j - k });
466
+ k = j;
467
+ }
468
+ return {
469
+ diffs: change.slice(1),
470
+ flashes: merged.map(([a, b]) => ({ at: at(a), frames: b - a })),
471
+ blanks,
472
+ };
473
+ },
474
+ };
475
+ }
476
+
477
+ /** One decode for the picture: grey frames at READ_WIDTH into readPicture,
478
+ * and black frames found by ffmpeg in the full picture. */
479
+ function readFilmPicture(
480
+ ffmpeg: string,
481
+ file: string,
482
+ width: number,
483
+ height: number,
484
+ fps: number,
485
+ ): Promise<{ picture: Picture; log: string }> {
486
+ const w = READ_WIDTH;
487
+ // as tall as the film keeps it, even — what scale=320:-2 picks
488
+ const h = Math.max(2, Math.round((height * w) / width / 2) * 2);
489
+ const size = w * h;
490
+ const reader = readPicture(w, h, fps);
491
+ return new Promise((ok, fail) => {
492
+ const p = spawn(
493
+ ffmpeg,
494
+ [
495
+ "-nostats",
496
+ "-v",
497
+ "info",
498
+ "-i",
499
+ file,
500
+ "-filter_complex",
501
+ `[0:v]split[s][b];[s]scale=${w}:${h},format=gray[g];[b]blackdetect=d=0.1:pix_th=0.06[bo]`,
502
+ "-map",
503
+ "[g]",
504
+ // every decoded frame once: a constant-rate output may add or drop one
505
+ "-fps_mode",
506
+ "passthrough",
507
+ "-f",
508
+ "rawvideo",
509
+ "-",
510
+ "-map",
511
+ "[bo]",
512
+ "-f",
513
+ "null",
514
+ "-",
515
+ ],
516
+ { stdio: ["ignore", "pipe", "pipe"] },
517
+ );
518
+ let pending: Buffer | null = null;
519
+ let log = "";
520
+ p.stdout.on("data", (d: Buffer) => {
521
+ const buf = pending ? Buffer.concat([pending, d]) : d;
522
+ let off = 0;
523
+ for (; buf.length - off >= size; off += size)
524
+ reader.push(new Uint8Array(buf.subarray(off, off + size)));
525
+ pending = off < buf.length ? buf.subarray(off) : null;
526
+ });
527
+ p.stderr.on("data", (d: Buffer) => {
528
+ log += d.toString();
529
+ });
530
+ p.on("error", fail);
531
+ p.on("close", (code) =>
532
+ code === 0
533
+ ? ok({ picture: reader.done(), log })
534
+ : fail(new Error(`ffmpeg exited ${code} reading the picture: ${log.trim().slice(-600)}`)),
535
+ );
536
+ });
537
+ }
538
+
539
+ /** Per-frame mean difference (0–255) between consecutive frames → the picture
540
+ * findings. `diffs[i]` compares frames i and i+1. */
541
+ export function motionFindings(
542
+ diffs: readonly number[],
543
+ fps: number,
544
+ ): Pick<FilmCheck, "stalls" | "cadence" | "cuts"> {
545
+ const at = (i: number) => Math.round(((i + 1) / fps) * 1000) / 1000;
546
+ // the differences are means over a small grey copy (0–255): below 0.02 two
547
+ // frames are the same picture (encoder noise aside), above 0.4 something
548
+ // visibly moved
549
+ const still = (v: number) => v < 0.02;
550
+ const cadence: { at: number; frames: number; every?: number }[] = [];
551
+ // moving and still frames taking turns for 8 frames and more: what changes
552
+ // updates at a lower rate than the film, not one repeated frame
553
+ const alternating: [number, number][] = [];
554
+ let run = 0;
555
+ for (let i = 1; i <= diffs.length; i++) {
556
+ const flips =
557
+ i < diffs.length &&
558
+ still(diffs[i]!) !== still(diffs[i - 1]!) &&
559
+ Math.max(diffs[i]!, diffs[i - 1]!) > 0.3;
560
+ if (flips) run++;
561
+ else {
562
+ if (run >= 8) {
563
+ cadence.push({ at: at(i - run - 1), frames: run });
564
+ alternating.push([i - run - 1, i]);
565
+ }
566
+ run = 0;
567
+ }
568
+ }
569
+ const held: number[] = [];
570
+ for (let i = 2; i < diffs.length - 2; i++)
571
+ if (
572
+ still(diffs[i]!) &&
573
+ diffs[i - 1]! > 0.4 &&
574
+ diffs[i + 1]! > 0.4 &&
575
+ !alternating.some(([a, b]) => i >= a && i <= b)
576
+ )
577
+ held.push(i);
578
+ // a held frame on its own inside motion is a hitch; held frames that keep
579
+ // coming back a few frames apart are the picture changing at a lower rate
580
+ // than the film — a number counting 40 a second holds every third frame —
581
+ // and are told as a cadence, not as so many hitches (the frame differences
582
+ // cannot tell motion from a number or a word changing)
583
+ const stalls: number[] = [];
584
+ for (let k = 0; k < held.length; ) {
585
+ let e = k;
586
+ while (e + 1 < held.length && held[e + 1]! - held[e]! <= 4) e++;
587
+ if (e - k + 1 >= 4) {
588
+ const gaps = held.slice(k + 1, e + 1).map((h, j) => h - held[k + j]!);
589
+ gaps.sort((a, b) => a - b);
590
+ cadence.push({
591
+ at: at(held[k]! - 1),
592
+ frames: held[e]! - held[k]! + 2,
593
+ every: gaps[Math.floor(gaps.length / 2)]!,
594
+ });
595
+ } else for (let j = k; j <= e; j++) stalls.push(at(held[j]!));
596
+ k = e + 1;
597
+ }
598
+ // a cut: most of the picture changes at once (a mean change of 30 of 255),
599
+ // three times more than the frames on either side of it
600
+ const cuts: number[] = [];
601
+ for (let i = 1; i < diffs.length - 1; i++) {
602
+ const v = diffs[i]!;
603
+ if (v > 30 && v > 3 * Math.max(diffs[i - 1]!, diffs[i + 1]!, 0.5)) cuts.push(at(i));
604
+ }
605
+ cadence.sort((a, b) => a.at - b.at);
606
+ return { stalls, cadence, cuts };
607
+ }
608
+
609
+ /** Isolated single-sample jumps: a step between two samples far larger than
610
+ * anything the waveform does in the 5 ms on EITHER side of it. The onset of a
611
+ * noisy sound (a hat, a whoosh) is busy right after its first sample, so it is
612
+ * not a click; a tone that starts or stops mid-cycle is smooth on both sides. */
613
+ export function findClicks(x: Float32Array, rate: number): number[] {
614
+ const out: number[] = [];
615
+ const half = Math.round(rate * 0.005);
616
+ // running sum of squared first differences: sq[k] = Σ_{m<k} (x[m] - x[m-1])²
617
+ const sq = new Float64Array(x.length + 1);
618
+ for (let n = 1; n < x.length; n++) {
619
+ const d = x[n]! - x[n - 1]!;
620
+ sq[n + 1] = sq[n]! + d * d;
621
+ }
622
+ const rms = (a: number, b: number) => Math.sqrt((sq[b + 1]! - sq[a]!) / (b - a + 1));
623
+ let last = -1;
624
+ for (let n = half + 3; n < x.length - half - 3; n++) {
625
+ // a step of 8 % of full scale or more, 8 times what the waveform does
626
+ // around it (by its rms step), is a click; below that it is the sound
627
+ const d = Math.abs(x[n]! - x[n - 1]!);
628
+ if (d < 0.08) continue;
629
+ const around = Math.max(rms(n - half, n - 3), rms(n + 3, n + half));
630
+ if (d > 8 * around) {
631
+ const t = n / rate;
632
+ if (last < 0 || t - last > 0.05) out.push(Math.round(t * 1000) / 1000);
633
+ last = t;
634
+ if (out.length >= 30) break;
635
+ }
636
+ }
637
+ return out;
638
+ }
639
+
640
+ // --- judging --------------------------------------------------------------------
641
+
642
+ /** a mark covers its moment, or its stretch, and this much either side: the
643
+ * check reads times to the frame, an author writes them by hand */
644
+ const MARK_SLACK = 0.1;
645
+ /** times are read to the millisecond: closer than this is the same time */
646
+ const SAME_TIME = 1e-6;
647
+
648
+ const LAYOUT_SAYS: Record<LayoutSpan["kind"], string> = {
649
+ "text-over-text": "text over text",
650
+ "text-over-badge": "text into a small painted element",
651
+ "text-off-frame": "text cut by the frame's edge",
652
+ };
653
+
654
+ export function judgeFilm(c: FilmCheck, expect: FilmCheckExpect): FilmCheckIssue[] {
655
+ const issues: FilmCheckIssue[] = [];
656
+ const v = c.video;
657
+ const fps = v?.fps || 60;
658
+ /** the findings the marks do not cover from end to end; the others are
659
+ * listed as marked as intended, and a mark that covers a finding only in
660
+ * part is named beside it */
661
+ const unmarked = <T>(xs: readonly T[], span: (x: T) => [number, number], say: (x: T) => string) =>
662
+ xs.filter((x) => {
663
+ const [from, to] = span(x);
664
+ const touching = c.marks
665
+ .filter(
666
+ (m) => from <= m.until + MARK_SLACK + SAME_TIME && to >= m.at - MARK_SLACK - SAME_TIME,
667
+ )
668
+ .sort((a, b) => a.at - b.at);
669
+ if (!touching.length) return true;
670
+ let reach = from;
671
+ for (const m of touching) {
672
+ if (m.at - MARK_SLACK > reach + SAME_TIME) break;
673
+ reach = Math.max(reach, m.until + MARK_SLACK);
674
+ }
675
+ const whole = reach + SAME_TIME >= to;
676
+ const whats = touching.flatMap((m) => (m.what ? [`"${m.what}"`] : []));
677
+ const named = touching.map((m) =>
678
+ m.what ? `"${m.what}"` : `${m.at === m.until ? m.at : `${m.at}–${m.until}`}s`,
679
+ );
680
+ issues.push({
681
+ severity: "info",
682
+ message: whole
683
+ ? `marked as intended${whats.length ? ` (${whats.join(", ")})` : ""}: ${say(x)}`
684
+ : `a mark covers only part of it (${named.join(", ")}): ${say(x)}`,
685
+ });
686
+ return !whole;
687
+ });
688
+ const frames = (n: number) => `${n} frame${n === 1 ? "" : "s"}`;
689
+ const runOf = (r: { at: number; frames: number }): [number, number] => [
690
+ r.at,
691
+ r.at + r.frames / fps,
692
+ ];
693
+ if (!v) issues.push({ severity: "error", message: "no video stream" });
694
+ else {
695
+ if (expect.width && expect.height && (v.width !== expect.width || v.height !== expect.height))
696
+ issues.push({
697
+ severity: "error",
698
+ message: `size ${v.width}×${v.height}, expected ${expect.width}×${expect.height}`,
699
+ });
700
+ if (expect.fps && Math.abs(v.fps - expect.fps) > 0.01)
701
+ issues.push({ severity: "error", message: `${v.fps} fps, expected ${expect.fps}` });
702
+ if (v.codec !== "h264")
703
+ issues.push({ severity: "warn", message: `video codec ${v.codec}, not H.264` });
704
+ if (v.pixFmt !== "yuv420p")
705
+ issues.push({
706
+ severity: "warn",
707
+ message: `pixel format ${v.pixFmt} — players expect yuv420p`,
708
+ });
709
+ }
710
+ const stalls = unmarked(
711
+ c.stalls,
712
+ (t) => [t, t],
713
+ (t) => `a frame repeats inside motion at ${t}s`,
714
+ );
715
+ if (stalls.length)
716
+ issues.push({
717
+ severity: "error",
718
+ message: `a frame repeats inside motion (a hitch) at ${list(stalls)}s`,
719
+ });
720
+ const cadence = unmarked(c.cadence, runOf, (r) =>
721
+ r.every
722
+ ? `a frame held about every ${r.every} frames for ${r.frames} frames from ${r.at}s`
723
+ : `still/moving frames alternate for ${r.frames} frames from ${r.at}s`,
724
+ );
725
+ for (const r of cadence)
726
+ issues.push(
727
+ r.every
728
+ ? {
729
+ // the frame differences cannot tell what changes: a count of 40 a
730
+ // second holds one frame in 3 as a 40 fps move does
731
+ severity: "warn",
732
+ message: `a frame held about every ${r.every} frames for ${r.frames} frames from ${r.at}s — what changes there changes at a lower rate than the film: a move stepping, or a number or text updated that often (a count of 40 a second holds one frame in 3)`,
733
+ }
734
+ : {
735
+ severity: "error",
736
+ message: `still/moving frames alternate for ${r.frames} frames from ${r.at}s — what changes there (a move, or a number or text) is updating at a lower rate than the film`,
737
+ },
738
+ );
739
+ const flashes = unmarked(c.flashes, runOf, (f) => `a flash at ${f.at}s (${frames(f.frames)})`);
740
+ if (flashes.length)
741
+ issues.push({
742
+ severity: "warn",
743
+ message: `a flash — frames unlike the frames on both sides — at ${flashes.map((f) => `${f.at}s (${frames(f.frames)})`).join(", ")}: a clip cut on its transition frame, or a flash meant to be there (say so in window.__film.marks)`,
744
+ });
745
+ const blanks = unmarked(
746
+ c.blanks,
747
+ runOf,
748
+ (b) => `a shot starts on near-blank frames at ${b.at}s (${frames(b.frames)})`,
749
+ );
750
+ if (blanks.length)
751
+ issues.push({
752
+ severity: "warn",
753
+ message: `a shot starts on near-blank frames at ${blanks.map((b) => `${b.at}s (${frames(b.frames)})`).join(", ")}: its content arrives after the cut${blanks[0]!.at === 0 ? " — and a blank first frame is the film's poster" : ""}`,
754
+ });
755
+ const edge = 0.05;
756
+ const black = unmarked(
757
+ c.black.filter((b) => b.start > edge && b.end < c.durationS - edge),
758
+ (b) => [b.start, b.end],
759
+ (b) => `black frames ${b.start}–${b.end}s`,
760
+ );
761
+ for (const b of black)
762
+ issues.push({
763
+ severity: "warn",
764
+ message: `black frames ${b.start}–${b.end}s inside the film`,
765
+ });
766
+ const layout = unmarked(
767
+ groupLayout(c.layout ?? []),
768
+ (g) => [g.from, g.to],
769
+ (g) => g.message,
770
+ );
771
+ for (const g of layout) issues.push({ severity: "warn", message: g.message });
772
+ const unread = c.unreadText ?? [];
773
+ if (unread.length)
774
+ issues.push({
775
+ severity: "info",
776
+ message: `text drawn turned, skewed, mirrored or in a frame tilted in perspective is not read for collisions or size — look at it yourself: ${unread.slice(0, 6).join(", ")}${unread.length > 6 ? ` and ${unread.length - 6} more` : ""}`,
777
+ });
778
+ if (!c.audio) {
779
+ issues.push({ severity: "warn", message: "no audio stream — the film is silent" });
780
+ } else {
781
+ const a = c.audio;
782
+ if (a.truePeak != null && a.truePeak > -1)
783
+ issues.push({
784
+ severity: "warn",
785
+ message: `true peak ${a.truePeak} dBFS — above -1 dBFS it can clip after lossy encoding`,
786
+ });
787
+ if (a.lufs != null && (a.lufs < -20 || a.lufs > -12))
788
+ issues.push({
789
+ severity: "info",
790
+ message: `integrated loudness ${a.lufs} LUFS — online video usually sits around -14 to -16`,
791
+ });
792
+ const silences = unmarked(
793
+ c.silences.filter((s) => s.start > edge && s.end < c.durationS - edge),
794
+ (s) => [s.start, s.end],
795
+ (s) => `silence ${s.start.toFixed(2)}–${s.end.toFixed(2)}s`,
796
+ );
797
+ for (const s of silences)
798
+ issues.push({
799
+ severity: "info",
800
+ message: `silence ${s.start.toFixed(2)}–${s.end.toFixed(2)}s`,
801
+ });
802
+ const clicks = unmarked(
803
+ c.clicks,
804
+ (t) => [t, t],
805
+ (t) => `a possible click at ${t}s`,
806
+ );
807
+ if (clicks.length)
808
+ issues.push({
809
+ severity: "warn",
810
+ message: `possible clicks (a sudden jump in the waveform) at ${list(clicks)}s`,
811
+ });
812
+ }
813
+ return issues;
814
+ }
815
+
816
+ /** One finding per piece of text, kind and stretch of time, naming what it
817
+ * runs into. */
818
+ function groupLayout(
819
+ spans: readonly LayoutSpan[],
820
+ ): { from: number; to: number; message: string }[] {
821
+ const groups: {
822
+ kind: LayoutSpan["kind"];
823
+ a: string;
824
+ from: number;
825
+ to: number;
826
+ hits: Set<string>;
827
+ }[] = [];
828
+ for (const s of [...spans].sort((x, y) => x.from - y.from)) {
829
+ const g = groups.find(
830
+ (x) => x.kind === s.kind && x.a === s.a && s.from <= x.to + 0.3 && s.to >= x.from - 0.3,
831
+ );
832
+ if (g) {
833
+ g.from = Math.min(g.from, s.from);
834
+ g.to = Math.max(g.to, s.to);
835
+ if (s.b) g.hits.add(s.b);
836
+ } else
837
+ groups.push({
838
+ kind: s.kind,
839
+ a: s.a,
840
+ from: s.from,
841
+ to: s.to,
842
+ hits: new Set(s.b ? [s.b] : []),
843
+ });
844
+ }
845
+ return groups.map((g) => {
846
+ const hits = [...g.hits];
847
+ const into = hits.length
848
+ ? ` × ${hits.slice(0, 4).join("; ")}${hits.length > 4 ? `; and ${hits.length - 4} more` : ""}`
849
+ : "";
850
+ return {
851
+ from: g.from,
852
+ to: g.to,
853
+ message: `${LAYOUT_SAYS[g.kind]} ${g.from}–${g.to}s: ${g.a}${into}`,
854
+ };
855
+ });
856
+ }
857
+
858
+ // --- the page's material ------------------------------------------------------------
859
+
860
+ export type PageMaterial = {
861
+ /** the folder served to the page, where the search started */
862
+ root: string;
863
+ /** `open-take shoot` logs (shots.json) under it: path from root, PNG
864
+ * stills, and how many of those name a saved screen */
865
+ logs: { file: string; stills: number; withState: number }[];
866
+ /** saved screens under it (a `state.html` each) */
867
+ states: number;
868
+ };
869
+
870
+ /** folders the material search does not enter */
871
+ const MATERIAL_SKIP = new Set(["node_modules", "kit"]);
872
+ const MATERIAL_DEPTH = 5;
873
+ const MATERIAL_ENTRIES = 20_000;
874
+
875
+ /** the shoot logs and saved screens in the folder served to the page (as
876
+ * `film render` serves it): read off the files, the page not run. */
877
+ export async function readPageMaterial(page: string, root?: string): Promise<PageMaterial> {
878
+ const base = resolveFilmPage(page, root).root;
879
+ const out: PageMaterial = { root: base, logs: [], states: 0 };
880
+ let seen = 0;
881
+ const walk = async (dir: string, depth: number): Promise<void> => {
882
+ if (depth > MATERIAL_DEPTH || seen > MATERIAL_ENTRIES) return;
883
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
884
+ for (const e of entries) {
885
+ if (++seen > MATERIAL_ENTRIES) return;
886
+ const at = join(dir, e.name);
887
+ if (e.isDirectory()) {
888
+ if (!e.name.startsWith(".") && !MATERIAL_SKIP.has(e.name)) await walk(at, depth + 1);
889
+ } else if (e.name === "state.html") out.states++;
890
+ else if (e.name === "shots.json") {
891
+ try {
892
+ const log = JSON.parse(await readFile(at, "utf8")) as { stills?: unknown };
893
+ if (!Array.isArray(log.stills)) continue;
894
+ const stills = log.stills.filter(
895
+ (x): x is { file: string; state?: unknown } =>
896
+ !!x &&
897
+ typeof x === "object" &&
898
+ /\.png$/i.test(String((x as { file?: unknown }).file)),
899
+ );
900
+ if (stills.length)
901
+ out.logs.push({
902
+ file: relative(base, at),
903
+ stills: stills.length,
904
+ withState: stills.filter((x) => x.state != null && x.state !== false).length,
905
+ });
906
+ } catch {
907
+ // not a shoot log
908
+ }
909
+ }
910
+ }
911
+ };
912
+ await walk(base, 0);
913
+ out.logs.sort((a, b) => a.file.localeCompare(b.file));
914
+ return out;
915
+ }
916
+
917
+ /** one line when the page's folder holds PNG stills from a shoot and no
918
+ * saved screen: what else a still can keep. null otherwise. Information. */
919
+ export function pageMaterialNote(m: PageMaterial): string | null {
920
+ if (!m.logs.length || m.states > 0 || m.logs.some((l) => l.withState > 0)) return null;
921
+ const stills = m.logs.reduce((a, l) => a + l.stills, 0);
922
+ const where =
923
+ m.logs.length === 1
924
+ ? m.logs[0]!.file
925
+ : `${m.logs.length} shoot logs (${m.logs
926
+ .slice(0, 3)
927
+ .map((l) => l.file)
928
+ .join(", ")}${m.logs.length > 3 ? ", …" : ""})`;
929
+ return `${stills} PNG still${stills === 1 ? "" : "s"} from ${where}, and no saved screen in the folder served to the page. A still can also keep the interface itself (\`s.still(name, { state: true })\` in a shoot script, or \`open-take shoot … --states\`): live page parts that \`lift\` / \`isolate\` (kit/media.js) act on and stay sharp at any zoom — \`skill film material\`. Information, not a step.`;
930
+ }
931
+
932
+ const list = (xs: readonly number[]) =>
933
+ xs.length > 8 ? `${xs.slice(0, 8).join(", ")} … (${xs.length})` : xs.join(", ");
934
+
935
+ export function formatFilmCheck(c: FilmCheck): string {
936
+ const lines: string[] = [];
937
+ const v = c.video;
938
+ lines.push(
939
+ v
940
+ ? `picture: ${v.width}×${v.height} ${v.fps} fps ${v.codec}${v.profile ? ` ${v.profile}` : ""} ${v.pixFmt}, ${c.durationS.toFixed(2)}s`
941
+ : "picture: none",
942
+ );
943
+ const a = c.audio;
944
+ lines.push(
945
+ a
946
+ ? `sound: ${a.codec} ${a.sampleRate / 1000} kHz ${a.channels === 2 ? "stereo" : `${a.channels} ch`}, ${a.lufs ?? "?"} LUFS, range ${a.lra ?? "?"} LU, true peak ${a.truePeak ?? "?"} dBFS`
947
+ : "sound: none",
948
+ );
949
+ lines.push(`cuts: ${c.cuts.length ? `${list(c.cuts)}s` : "none"}`);
950
+ if (c.marks.length)
951
+ lines.push(
952
+ `marked as intended: ${c.marks.map((m) => `${m.at === m.until ? m.at : `${m.at}–${m.until}`}s${m.what ? ` "${m.what}"` : ""}`).join(", ")}`,
953
+ );
954
+ if (c.page) {
955
+ lines.push(
956
+ `page: ${c.page.file}, laid out at ${c.page.width}×${c.page.height}, read every ${c.page.every}s`,
957
+ );
958
+ const s = c.smallestText;
959
+ lines.push(
960
+ s
961
+ ? `text: the smallest on screen is ${s.px}px (its font size as drawn on the ${c.page.width}×${c.page.height} frame) at ${s.at}s — ${s.text}`
962
+ : "text: none on screen",
963
+ );
964
+ }
965
+ const note = c.material ? pageMaterialNote(c.material) : null;
966
+ if (note) lines.push(`material: ${note}`);
967
+ const scope = c.scope ?? filmCheckScope(c);
968
+ lines.push(`measured: ${scope.measured}`);
969
+ lines.push(`not measured: ${scope.notMeasured}`);
970
+ if (!c.issues.length) lines.push("found: nothing in what was measured");
971
+ for (const i of c.issues)
972
+ lines.push(`${i.severity === "info" ? "note" : i.severity}: ${i.message}`);
973
+ return lines.join("\n");
974
+ }
975
+
976
+ function pcm(ffmpeg: string, file: string): Promise<Float32Array> {
977
+ return new Promise((ok, fail) => {
978
+ const p = spawn(
979
+ ffmpeg,
980
+ ["-v", "error", "-i", file, "-vn", "-ac", "1", "-ar", "48000", "-f", "f32le", "-"],
981
+ {
982
+ stdio: ["ignore", "pipe", "pipe"],
983
+ },
984
+ );
985
+ const chunks: Buffer[] = [];
986
+ p.stdout.on("data", (d: Buffer) => chunks.push(d));
987
+ p.on("error", fail);
988
+ p.on("close", (code) => {
989
+ if (code !== 0) return fail(new Error(`ffmpeg exited ${code} decoding the sound`));
990
+ const all = Buffer.concat(chunks);
991
+ const f = new Float32Array(all.length >> 2);
992
+ for (let i = 0; i < f.length; i++) f[i] = all.readFloatLE(i * 4);
993
+ ok(f);
994
+ });
995
+ });
996
+ }