@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,791 @@
1
+ // Read picture changes and motion on a small grey copy at native cadence.
2
+ // The probe's wide change windows give places to look. The pair at each
3
+ // proposed boundary supplies the evidence for a cut, with nearby frames
4
+ // showing how motion approached and left. Verdict thresholds were set on
5
+ // two launch reels with UI footage at 24 and 30 fps. The fit leaves some
6
+ // 3D camera moves, blur hand-offs, dissolves and morphs unresolved or misses
7
+ // them entirely.
8
+
9
+ import {
10
+ type CameraPath,
11
+ type CarryKind,
12
+ findChanges,
13
+ findCuts,
14
+ findSmallSwaps,
15
+ follow,
16
+ frameEnergy,
17
+ frameTime,
18
+ type GreyFrames,
19
+ globalMotion,
20
+ pictureMotion,
21
+ } from "./probe";
22
+ import { median } from "./beats";
23
+
24
+ export type StudyFrames = GreyFrames & { times?: readonly number[] };
25
+ type Move = { s: number; x: number; y: number };
26
+ type Fit = Move & { error: number; ratio: number; support: number };
27
+ type CutKind = "hard_cut" | "scale_jump" | "match_cut";
28
+ export type Verdict =
29
+ | CutKind
30
+ | "fast_move"
31
+ | "in_picture_change"
32
+ | "flash_or_fade"
33
+ | "unresolved";
34
+ type Source = "cuts" | "small_swaps" | "changes" | "energy_peak";
35
+ type MotionState = "travel" | "drift" | "hold";
36
+ type Nomination = { source: Source; frame: number; from: number; to: number };
37
+ export type Step = { motion: Move | null; localPx: number | null; energy: number };
38
+
39
+ export const studyTime = (g: StudyFrames, i: number) => g.times?.[i] ?? frameTime(g, i);
40
+ const frame = (g: GreyFrames, i: number) =>
41
+ g.data.subarray(i * g.w * g.h, (i + 1) * g.w * g.h);
42
+
43
+ const STILL = 0.0015; // film probe's grey-change floor, above small encode noise
44
+ // A fast step, for the verdicts at a boundary and the camera's runs: 2 px a
45
+ // frame on the 640 px ruler, 0.004 of |ln s|, 3 px of local motion. The
46
+ // verdicts were tuned with these on the two launch reels (24 and 30 fps),
47
+ // where they stay per frame; a step shorter than a thirtieth of a second is
48
+ // held to its share of them, so a 60 fps master reads as its 30 fps copy.
49
+ const FAST_PX = 2;
50
+ const FAST_SCALE = 0.004;
51
+ const FAST_LOCAL = 3;
52
+ const FAST_SECONDS = 1 / 30;
53
+ // Travel, drift and hold are per second, so one film read at 24, 30 or 60
54
+ // fps gives one set of shares. The 24 fps travel24.py table flags 2 native
55
+ // px of a 1276 px-wide picture, |ln s| 0.004, or 3 native px of median flow
56
+ // per frame. Scale the pixel thresholds to the 640 px ruler.
57
+ const TRAVEL_RATE = 2 * 640 / 1276 * 24;
58
+ const TRAVEL_SCALE_RATE = 0.004 * 24;
59
+ const TRAVEL_LOCAL_RATE = 3 * 640 / 1276 * 24;
60
+ // The probe's grey-change floor and the quarter pixel a frame of a slow
61
+ // drift, timed at the 24 fps table's cadence.
62
+ const DRIFT_ENERGY_RATE = STILL * 24;
63
+ const DRIFT_RATE = 0.25 * 24;
64
+ // The travel24.py table closes with k = 1 at 24 fps.
65
+ const CLOSE_SECONDS = 1 / 24;
66
+ const SCALE_JUMP = 1.3; // fast pushes reach 1.28×; jumps inside ramps start around 1.45×
67
+ const CAMERA_SIDE = 3; // read the approach and departure over a few native frames
68
+
69
+ const translation = (m: Move, w: number) => Math.hypot(m.x, m.y) * 640 / w;
70
+ const speed = (m: Move, w: number) => Math.hypot(m.x, m.y, Math.log(m.s) * w / 4) * 640 / w;
71
+
72
+ /** a step that took `seconds` fast enough to be the camera travelling:
73
+ * judged per frame at 30 fps and slower, per second above */
74
+ function fast(step: Step, w: number, seconds: number): boolean {
75
+ const m = step.motion;
76
+ const k = seconds > 0 ? Math.min(1, seconds / FAST_SECONDS) : 1;
77
+ return !!(m && (translation(m, w) >= k * FAST_PX || Math.abs(Math.log(m.s)) >= k * FAST_SCALE)) ||
78
+ (step.localPx ?? 0) >= k * FAST_LOCAL;
79
+ }
80
+
81
+ /** what a step that took `seconds` does: the camera travels, the picture
82
+ * drifts, or it holds */
83
+ function state(step: Step, w: number, seconds: number): MotionState {
84
+ const m = step.motion;
85
+ const dt = seconds > 0 ? seconds : 1 / 30;
86
+ if (
87
+ (m && (translation(m, w) / dt >= TRAVEL_RATE || Math.abs(Math.log(m.s)) / dt >= TRAVEL_SCALE_RATE)) ||
88
+ (step.localPx ?? 0) / dt >= TRAVEL_LOCAL_RATE
89
+ )
90
+ return "travel";
91
+ return step.energy / dt >= DRIFT_ENERGY_RATE || (m && speed(m, w) / dt >= DRIFT_RATE) ? "drift" : "hold";
92
+ }
93
+
94
+ // With unmarked padding, closing fills holes of up to two radii between
95
+ // marked steps. A held frame on a variable-rate film can span a whole hole.
96
+ function close(mask: boolean[], seconds: readonly number[]): boolean[] {
97
+ let prev = -1;
98
+ let gap = 0;
99
+ for (let i = 0; i < mask.length; i++) {
100
+ if (mask[i]) {
101
+ // Seconds from the frame clock may be rounded by floating point.
102
+ if (prev >= 0 && gap <= 2 * CLOSE_SECONDS + 1e-9) mask.fill(true, prev + 1, i);
103
+ prev = i;
104
+ gap = 0;
105
+ } else gap += seconds[i]!;
106
+ }
107
+ return mask;
108
+ }
109
+
110
+ /** Each step of a shot as travel, drift or hold. `seconds[i]` is the time
111
+ * step i took (the interval between the two frames it compares); without
112
+ * it, 30 fps. */
113
+ export function motionStates(
114
+ steps: readonly Step[], w: number, seconds: readonly number[] = [], spans = seconds,
115
+ ): MotionState[] {
116
+ const dts = steps.map((_, i) => seconds[i] ?? 1 / 30);
117
+ const raw = steps.map((s, i) => state(s, w, spans[i] ?? dts[i]!));
118
+ const moving = close(raw.map((s) => s !== "hold"), dts);
119
+ const travelling = close(raw.map((s) => s === "travel"), dts);
120
+ return raw.map((_, i) => (travelling[i] ? "travel" : moving[i] ? "drift" : "hold"));
121
+ }
122
+
123
+ /** How the picture moved from frame a to frame b. */
124
+ function stepBetween(g: StudyFrames, a: number, b: number, e: number): Step {
125
+ let motion: Move | null = null;
126
+ if (e > 0) {
127
+ const m = pictureMotion(g, a, b);
128
+ if (m && (speed(m, g.w) < 0.25 || trusted(fitEvidence(g, frame(g, a), frame(g, b), m)))) motion = m;
129
+ }
130
+ const step: Step = { motion, localPx: null, energy: e };
131
+ if (e >= STILL && !fast(step, g.w, studyTime(g, b) - studyTime(g, a))) step.localPx = localMotion(g, frame(g, a), frame(g, b));
132
+ return step;
133
+ }
134
+
135
+ // On the 96 px grey copy a step of a 60 fps film moves too little to
136
+ // measure (half a pixel on the 640 ruler is 0.08 px there), so a step for
137
+ // travel, drift and hold spans at least a thirtieth of a second, as the
138
+ // launch reels' tables were read: every frame of a faster film is compared
139
+ // with the one that far back in its shot.
140
+ const STATE_SPAN = 1 / 30;
141
+
142
+ /** The steps of shot [from, to) for motionStates, frames from + 1 to
143
+ * to − 1, and the seconds each spans. On a film at 30 fps or slower they
144
+ * are the adjacent steps. */
145
+ export function stateSteps(
146
+ g: StudyFrames, steps: readonly Step[], from: number, to: number, frameSeconds: number,
147
+ ): { steps: Step[]; seconds: number[] } {
148
+ const k = Math.max(1, Math.round(STATE_SPAN / frameSeconds - 0.25));
149
+ const out: Step[] = [];
150
+ const seconds: number[] = [];
151
+ for (let i = from + 1; i < to; i++) {
152
+ let a = i - 1;
153
+ while (a > Math.max(from, i - k) && studyTime(g, i) - studyTime(g, a - 1) <=
154
+ STATE_SPAN + frameSeconds / 2) a--;
155
+ seconds.push(studyTime(g, i) - studyTime(g, a));
156
+ if (a === i - 1) {
157
+ out.push(steps[i]!);
158
+ continue;
159
+ }
160
+ const fa = frame(g, a);
161
+ const fb = frame(g, i);
162
+ let sum = 0;
163
+ for (let j = 0; j < fa.length; j++) sum += Math.abs(fa[j]! - fb[j]!);
164
+ out.push(stepBetween(g, a, i, sum / fa.length / 255));
165
+ }
166
+ return { steps: out, seconds };
167
+ }
168
+
169
+ export function motionShares(states: readonly MotionState[], seconds: readonly number[]) {
170
+ const sum = { travel: 0, drift: 0, hold: 0 };
171
+ states.forEach((s, i) => { sum[s] += seconds[i]!; });
172
+ const total = sum.travel + sum.drift + sum.hold;
173
+ return total
174
+ ? { travel: sum.travel / total, drift: sum.drift / total, hold: sum.hold / total, seconds: total }
175
+ : null;
176
+ }
177
+
178
+ function sample(a: Uint8Array, w: number, x: number, y: number): number {
179
+ const i = Math.floor(x);
180
+ const j = Math.floor(y);
181
+ const u = x - i;
182
+ const v = y - j;
183
+ const k = j * w + i;
184
+ return (1 - v) * ((1 - u) * a[k]! + u * a[k + 1]!) +
185
+ v * ((1 - u) * a[k + w]! + u * a[k + w + 1]!);
186
+ }
187
+
188
+ // Check the fit on the overlapping picture, including the texture that
189
+ // the robust solver may have left out. Flat margins give no support.
190
+ function fitEvidence(g: GreyFrames, a: Uint8Array, b: Uint8Array, m: Move): Fit {
191
+ let error = 0;
192
+ let raw = 0;
193
+ let supported = 0;
194
+ let n = 0;
195
+ for (let y = 2; y < g.h - 2; y += 2) {
196
+ for (let x = 2; x < g.w - 2; x += 2) {
197
+ const k = y * g.w + x;
198
+ const detail = Math.abs(a[k + 1]! - a[k - 1]!) + Math.abs(a[k + g.w]! - a[k - g.w]!);
199
+ if (detail < 10) continue; // probe's texture gate, on the small grey copy
200
+ const qx = g.w / 2 + m.s * (x - g.w / 2) + m.x;
201
+ const qy = g.h / 2 + m.s * (y - g.h / 2) + m.y;
202
+ if (qx < 0 || qx >= g.w - 1 || qy < 0 || qy >= g.h - 1) continue;
203
+ const d = Math.abs(a[k]! - sample(b, g.w, qx, qy));
204
+ error += d;
205
+ raw += Math.abs(a[k]! - b[k]!);
206
+ if (d <= 8 + detail * 0.2) supported++; // edges of downscaled, compressed pictures
207
+ n++;
208
+ }
209
+ }
210
+ const enough = n >= Math.max(10, g.w * g.h * 0.008);
211
+ return {
212
+ ...m,
213
+ error: enough ? error / n : Infinity,
214
+ ratio: enough ? error / Math.max(1, raw) : Infinity,
215
+ support: enough ? supported / n : 0,
216
+ };
217
+ }
218
+
219
+ const trusted = (f: Fit) => f.support >= 0.55 && f.ratio <= 0.76;
220
+ const identity: Move = { s: 1, x: 0, y: 0 };
221
+
222
+ function textureCentre(g: GreyFrames, f: Uint8Array) {
223
+ let total = 0;
224
+ let sx = 0;
225
+ let sy = 0;
226
+ for (let y = 2; y < g.h - 2; y += 2) {
227
+ for (let x = 2; x < g.w - 2; x += 2) {
228
+ const k = y * g.w + x;
229
+ const detail = Math.max(0, Math.abs(f[k + 1]! - f[k - 1]!) +
230
+ Math.abs(f[k + g.w]! - f[k - g.w]!) - 10);
231
+ sx += x * detail;
232
+ sy += y * detail;
233
+ total += detail;
234
+ }
235
+ }
236
+ return total ? { x: sx / total - g.w / 2, y: sy / total - g.h / 2 } : { x: 0, y: 0 };
237
+ }
238
+
239
+ function widenScale(g: GreyFrames, a: Uint8Array, b: Uint8Array): Fit | null {
240
+ // Large one-frame punches in UI footage run from about 1.3× to 4×.
241
+ // Pre-scale the smaller view, then use probe's existing scale/shift
242
+ // search. Compose the transforms and check them on the original pair.
243
+ const scales = [1.23, 1.38, 1.55, 1.8, 2.1, 2.45, 2.85, 3.35, 4];
244
+ const w = Math.max(16, Math.floor(g.w / 8) * 4);
245
+ const h = Math.max(8, Math.floor(g.h / 8) * 4);
246
+ const small = { ...g, w, h };
247
+ const resize = (src: Uint8Array, sc: number, dx = 0, dy = 0) => {
248
+ const clamp = (v: number, size: number) => Math.max(0, Math.min(size - 1.001, v));
249
+ const out = new Uint8Array(w * h);
250
+ for (let y = 0; y < h; y++) {
251
+ for (let x = 0; x < w; x++) {
252
+ const sx = clamp(g.w / 2 + dx + (x - w / 2) * g.w / w / sc, g.w);
253
+ const sy = clamp(g.h / 2 + dy + (y - h / 2) * g.h / h / sc, g.h);
254
+ out[y * w + x] = Math.round(sample(src, g.w, sx, sy));
255
+ }
256
+ }
257
+ return out;
258
+ };
259
+ let best: Fit | null = null;
260
+ let bestScore = Infinity;
261
+ for (const [from, to, reverse] of [[a, b, false], [b, a, true]] as const) {
262
+ const dst = resize(to, 1);
263
+ const ca = textureCentre(g, from);
264
+ const cb = textureCentre(g, to);
265
+ const check = (s: number, x: number, y: number) => {
266
+ const src = resize(from, s, x, y);
267
+ const m = globalMotion(small, src, dst);
268
+ const smallFit = fitEvidence(small, src, dst, m);
269
+ if (smallFit.error > 24) return; // downscaled texture no longer matches
270
+ const data = new Uint8Array(2 * w * h);
271
+ data.set(src);
272
+ data.set(dst, w * h);
273
+ const fine = pictureMotion({ ...small, count: 2, data }, 0, 1) ?? m;
274
+ const scale = s * fine.s;
275
+ if (scale < SCALE_JUMP - 0.01) return;
276
+ const move = { s: scale, x: fine.x * g.w / w - x * scale, y: fine.y * g.h / h - y * scale };
277
+ const f = fitEvidence(g, from, to, move);
278
+ const score = f.error / Math.max(0.1, f.support);
279
+ // Even a close patch can be the wrong part of an interface.
280
+ if (f.support >= 0.65 && f.ratio <= 0.55 && f.error <= 13 && score < bestScore) {
281
+ bestScore = score;
282
+ best = reverse ? { ...f, s: 1 / f.s, x: -f.x / f.s, y: -f.y / f.s } : f;
283
+ }
284
+ };
285
+ for (const s of scales) {
286
+ check(s, 0, 0);
287
+ // A punch can land off-centre, as on a button at the edge of a panel.
288
+ // Seed the same search on the texture rather than on the frame centre.
289
+ const x = ca.x - cb.x / s;
290
+ const y = ca.y - cb.y / s;
291
+ if (s >= 1.55 && bestScore > 4 && Math.hypot(x, y) > g.w / 12) check(s, x, y);
292
+ }
293
+ }
294
+ return best;
295
+ }
296
+
297
+ function picturePair(g: GreyFrames, a: Uint8Array, b: Uint8Array) {
298
+ // Same block size and grey gates as probe's changedShare and compare.
299
+ const block = 8;
300
+ let blocks = 0;
301
+ let changed = 0;
302
+ let stillTexture = 0;
303
+ let flat = 0;
304
+ let edgeBlocks = 0;
305
+ let edgeKept = 0;
306
+ for (let y = 0; y + block <= g.h; y += block) {
307
+ for (let x = 0; x + block <= g.w; x += block) {
308
+ let pa = 0;
309
+ let pb = 0;
310
+ let qa = 0;
311
+ let qb = 0;
312
+ let d = 0;
313
+ for (let r = y; r < y + block; r += 2) {
314
+ for (let c = x; c < x + block; c += 2) {
315
+ const k = r * g.w + c;
316
+ const va = a[k]!;
317
+ const vb = b[k]!;
318
+ pa += va;
319
+ pb += vb;
320
+ qa += va * va;
321
+ qb += vb * vb;
322
+ d += Math.abs(va - vb);
323
+ }
324
+ }
325
+ const n = (block / 2) ** 2;
326
+ const textA = qa / n - (pa / n) ** 2 >= 25;
327
+ const textB = qb / n - (pb / n) ** 2 >= 25;
328
+ if (d / n > 12) changed++;
329
+ if (d / n < 8 && textA && textB) stillTexture++;
330
+ if (Math.abs(pa - pb) / n < 8 && !textA && !textB) flat++;
331
+ if (x === 0 || y === 0 || x + 2 * block > g.w || y + 2 * block > g.h) {
332
+ edgeBlocks++;
333
+ if (d / n < 12) edgeKept++;
334
+ }
335
+ blocks++;
336
+ }
337
+ }
338
+ return {
339
+ changed: changed / blocks, stillTexture: stillTexture / blocks, flat: flat / blocks,
340
+ edgeKept: edgeKept / edgeBlocks,
341
+ };
342
+ }
343
+
344
+ // A scrim or a sudden light change may touch the whole frame with the
345
+ // same picture underneath. Fit its gain and offset and check the residual.
346
+ function sameUnderLight(a: Uint8Array, b: Uint8Array, energy: number) {
347
+ let x = 0;
348
+ let y = 0;
349
+ let xx = 0;
350
+ let xy = 0;
351
+ let n = 0;
352
+ for (let k = 0; k < a.length; k += 3) {
353
+ x += a[k]!;
354
+ y += b[k]!;
355
+ xx += a[k]! ** 2;
356
+ xy += a[k]! * b[k]!;
357
+ n++;
358
+ }
359
+ const spread = xx - x * x / n;
360
+ if (spread / n < 36) return false; // flat pixels cannot confirm the scene
361
+ const gain = (xy - x * y / n) / spread;
362
+ if (gain < 0.48 || gain > 2) return false;
363
+ const offset = (y - gain * x) / n;
364
+ let error = 0;
365
+ for (let k = 0; k < a.length; k += 3)
366
+ error += Math.abs(Math.max(0, Math.min(255, gain * a[k]! + offset)) - b[k]!);
367
+ return error / n <= 0.38 * energy * 255;
368
+ }
369
+
370
+ // The block search in probe's jumpMove, sampled on a grid here. The
371
+ // median includes still patches. Each patch needs texture and a close
372
+ // match before its displacement can stand in for local flow.
373
+ function localMotion(g: GreyFrames, a: Uint8Array, b: Uint8Array): number | null {
374
+ const mags: number[] = [];
375
+ let textured = 0;
376
+ const grid = 8; // probe's patch width on the grey copy
377
+ const radius = 4; // adjacent-frame search in probe's follow
378
+ for (let y = radius; y + grid + radius <= g.h; y += grid) {
379
+ for (let x = radius; x + grid + radius <= g.w; x += grid) {
380
+ const patch: number[] = [];
381
+ for (let r = 0; r < grid; r += 2)
382
+ for (let c = 0; c < grid; c += 2) patch.push(a[(y + r) * g.w + x + c]!);
383
+ const mean = patch.reduce((s, v) => s + v, 0) / patch.length;
384
+ const sd = Math.sqrt(patch.reduce((s, v) => s + (v - mean) ** 2, 0) / patch.length);
385
+ if (sd < 7) continue; // small grey patches with visible edges
386
+ textured++;
387
+ const cost = (dx: number, dy: number) => {
388
+ let d = 0;
389
+ let i = 0;
390
+ for (let r = 0; r < grid; r += 2)
391
+ for (let c = 0; c < grid; c += 2)
392
+ d += Math.abs(patch[i++]! - b[(y + r + dy) * g.w + x + c + dx]!);
393
+ return d / patch.length;
394
+ };
395
+ const still = cost(0, 0);
396
+ let best = still;
397
+ let mx = 0;
398
+ let my = 0;
399
+ if (still > 1.5) { // flat residual at rest from compression
400
+ for (let dy = -radius; dy <= radius; dy++) {
401
+ for (let dx = -radius; dx <= radius; dx++) {
402
+ const d = cost(dx, dy) + 0.1 * Math.hypot(dx, dy);
403
+ if (d < best) {
404
+ best = d;
405
+ mx = dx;
406
+ my = dy;
407
+ }
408
+ }
409
+ }
410
+ }
411
+ // As in jumpMove, the costs around the best integer match can place
412
+ // it between pixels. Check that the fractional step improves the match.
413
+ const vertex = (left: number, centre: number, right: number) => {
414
+ const curve = left - 2 * centre + right;
415
+ return curve > 0 ? Math.max(-0.5, Math.min(0.5, (left - right) / (2 * curve))) : 0;
416
+ };
417
+ const centre = cost(mx, my);
418
+ if (still > 1.5 && centre < sd * 0.5) {
419
+ const dx = Math.abs(mx) < radius ? vertex(cost(mx - 1, my), centre, cost(mx + 1, my)) : 0;
420
+ const dy = Math.abs(my) < radius ? vertex(cost(mx, my - 1), centre, cost(mx, my + 1)) : 0;
421
+ if (dx || dy) {
422
+ let error = 0;
423
+ let i = 0;
424
+ for (let r = 0; r < grid; r += 2)
425
+ for (let c = 0; c < grid; c += 2)
426
+ error += Math.abs(patch[i++]! - sample(b, g.w, x + c + mx + dx, y + r + my + dy));
427
+ if (error / patch.length < best) {
428
+ best = error / patch.length;
429
+ mx += dx;
430
+ my += dy;
431
+ }
432
+ }
433
+ }
434
+ if (best > Math.min(14, sd * 0.35)) continue; // probe's textured-patch match
435
+ mags.push(best < 0.7 * still ? Math.hypot(mx, my) : 0);
436
+ }
437
+ }
438
+ return mags.length >= Math.max(4, textured * 0.45) ? median(mags) * 640 / g.w : null;
439
+ }
440
+
441
+ function looksLikeLight(g: StudyFrames, energy: Float32Array, means: Float32Array, i: number) {
442
+ // Brief flashes on the test reels last one or two frames. Compare both
443
+ // ends to see whether the old picture comes back — from i itself when i
444
+ // is the way out of the light, which the film's last frame can only be.
445
+ for (let a = Math.max(0, i - 3); a < i; a++) {
446
+ for (let b = a + 2 <= i ? i : i + 1; b <= Math.min(i + 3, g.count - 1); b++) {
447
+ if (b - a > 4) continue;
448
+ const middle = means.subarray(a + 1, b);
449
+ const light = Math.max(...middle) - Math.max(means[a]!, means[b]!);
450
+ const dark = Math.min(means[a]!, means[b]!) - Math.min(...middle);
451
+ if (Math.max(light, dark) < 0.06) continue;
452
+ const fa = frame(g, a);
453
+ const fb = frame(g, b);
454
+ let distance = 0;
455
+ for (let j = 0; j < fa.length; j++) distance += Math.abs(fa[j]! - fb[j]!);
456
+ if (distance / (255 * fa.length) <= 0.28 * energy[i]!) return true;
457
+ }
458
+ }
459
+ // A luma ramp moves nearly all the pixels one way over several steps.
460
+ const sign = Math.sign(means[i]! - means[i - 1]!);
461
+ if (!sign) return false;
462
+ const ramp = (k: number) => {
463
+ if (k < 1 || k >= g.count) return false;
464
+ const luma = sign * (means[k]! - means[k - 1]!);
465
+ return luma >= 0.012 && luma >= 0.82 * energy[k]! &&
466
+ Math.min(energy[k]!, energy[i]!) >= 0.25 * Math.max(energy[k]!, energy[i]!);
467
+ };
468
+ return ramp(i) && ((ramp(i - 1) && ramp(i + 1)) ||
469
+ (ramp(i - 2) && ramp(i - 1)) || (ramp(i + 1) && ramp(i + 2)));
470
+ }
471
+
472
+ export type PictureCandidate = {
473
+ frame: number;
474
+ nominations: Nomination[];
475
+ verdict: Verdict;
476
+ verified: boolean;
477
+ across: CarryKind | null;
478
+ energy: number;
479
+ nearbyEnergy: number;
480
+ changed: number;
481
+ fit: Fit | null;
482
+ };
483
+
484
+ export function analyzeStudyPicture(g: StudyFrames) {
485
+ const energy = frameEnergy(g);
486
+ const means = new Float32Array(g.count);
487
+ for (let i = 0; i < g.count; i++) {
488
+ let sum = 0;
489
+ for (const v of frame(g, i)) sum += v;
490
+ means[i] = sum / (255 * g.w * g.h);
491
+ }
492
+ const cuts = findCuts(g, energy);
493
+ const cutSet = new Set(cuts);
494
+ const changes = findChanges(g, energy, cuts);
495
+ const swaps = findSmallSwaps(g, energy, cuts);
496
+ const carries = new Map(changes.filter((c) => cutSet.has(c.frame)).map((c) => [c.frame, c]));
497
+ const seeds = new Map<number, Nomination[]>();
498
+ const nominate = (at: number, source: Source, f = at, from = f - 1, to = f) => {
499
+ const list = seeds.get(at) ?? [];
500
+ list.push({ source, frame: f, from, to });
501
+ seeds.set(at, list);
502
+ };
503
+ for (const i of cuts) nominate(i, "cuts");
504
+ for (const { frame: i } of swaps) nominate(i, "small_swaps");
505
+
506
+ const nearby = (i: number) => {
507
+ const a = Array.from(energy.subarray(Math.max(1, i - 4), i));
508
+ const b = Array.from(energy.subarray(i + 1, i + 5));
509
+ // The second-largest flanking step, as in findCuts, leaves room for
510
+ // a flash's other edge and for footage with duplicate frames.
511
+ return [...a, ...b].sort((x, y) => y - x)[1] ?? 0;
512
+ };
513
+ for (let i = 1; i < g.count; i++) {
514
+ const e = energy[i]!;
515
+ // Include luma-similar swaps and the peaks of fast moves on the grey
516
+ // copy. The nearby floor keeps codec noise on a hold out of the list.
517
+ if (e < 0.009 || (e < 0.045 && e < 1.55 * nearby(i))) continue;
518
+ let peak = true;
519
+ for (let j = Math.max(1, i - 2); j <= Math.min(g.count - 1, i + 2); j++)
520
+ if (energy[j]! > e || (energy[j] === e && j < i)) peak = false;
521
+ if (peak) nominate(i, "energy_peak");
522
+ }
523
+ for (const c of changes) {
524
+ let at = c.before + 1;
525
+ let best = -Infinity;
526
+ for (let i = at; i <= c.after; i++) {
527
+ // A wide-window change may peak early. Use the strongest *adjacent*
528
+ // evidence in its span and keep the source window in the report.
529
+ const score = energy[i]! / Math.sqrt(Math.max(0.008, nearby(i)));
530
+ if (score > best) {
531
+ at = i;
532
+ best = score;
533
+ }
534
+ }
535
+ nominate(at, "changes", c.frame, c.before, c.after);
536
+ }
537
+
538
+ const steps: Step[] = [{ motion: null, localPx: null, energy: 0 }];
539
+ for (let i = 1; i < g.count; i++) steps.push(stepBetween(g, i - 1, i, energy[i]!));
540
+
541
+ const candidates: PictureCandidate[] = [];
542
+ for (const [i, nominations] of [...seeds].sort(([a], [b]) => a - b)) {
543
+ const a = frame(g, i - 1);
544
+ const b = frame(g, i);
545
+ const e = energy[i]!;
546
+ const ref = nearby(i);
547
+ const pair = picturePair(g, a, b);
548
+ const motion = steps[i]!.motion;
549
+ const took = (j: number) => studyTime(g, j) - studyTime(g, j - 1);
550
+ const dt = took(i);
551
+ const fastAt = (j: number) => fast(steps[j]!, g.w, took(j));
552
+ const sides = [];
553
+ for (let j = Math.max(1, i - CAMERA_SIDE); j < Math.min(steps.length, i + CAMERA_SIDE + 1); j++)
554
+ if (j !== i) sides.push(j);
555
+ const adjacent = sides.map((j) => steps[j]!);
556
+ // the local-motion gate, held to the step's share of a thirtieth of a second
557
+ const fastLocal = FAST_LOCAL * (dt > 0 ? Math.min(1, dt / FAST_SECONDS) : 1);
558
+ const flank = adjacent.flatMap((s) => s.motion ? [s.motion] : []);
559
+ const flankScale = Math.max(0, ...flank.map((m) => Math.abs(Math.log(m.s))));
560
+ const flankSpeed = Math.max(0, ...flank.map((m) => speed(m, g.w)));
561
+ // Abrupt over the flanks — or over the two steps right beside it, when a
562
+ // whip slows into the cut: its energy fills the flanks on one side, but
563
+ // the step before the cut has already dropped (3× the larger neighbour;
564
+ // inside a fast move the steps on both sides run close to the peak).
565
+ const beside = Math.max(energy[i - 1] ?? 0, energy[i + 1] ?? 0);
566
+ const abrupt = e >= Math.max(0.012, 1.75 * ref) || e >= Math.max(0.012, 3 * beside);
567
+ let fit = motion && speed(motion, g.w) >= 0.25 ? fitEvidence(g, a, b, motion) : null;
568
+ let verdict: Verdict = "unresolved";
569
+ let across: CarryKind | null = null;
570
+ if (looksLikeLight(g, energy, means, i) ||
571
+ (e >= 0.035 && Math.abs(means[i]! - means[i - 1]!) > 0.4 * e && sameUnderLight(a, b, e))) {
572
+ verdict = "flash_or_fade";
573
+ } else {
574
+ if (!fit && (abrupt || e > 0.065) && (pair.changed >= 0.12 || e >= 0.026)) {
575
+ fit = widenScale(g, a, b);
576
+ }
577
+ if (fit && trusted(fit)) {
578
+ const log = Math.abs(Math.log(fit.s));
579
+ if (log >= Math.log(SCALE_JUMP - 0.01) && log > 1.65 * flankScale) {
580
+ verdict = "scale_jump";
581
+ across = "carried";
582
+ } else if (e >= 2.5 * ref && log < 0.06 &&
583
+ translation(fit, g.w) >= 35 && speed(fit, g.w) > 3 * flankSpeed) {
584
+ // A shift of this size in one frame with still or slow shoulders
585
+ // is a jump to another framing, as in a panel-to-panel edit.
586
+ verdict = "match_cut";
587
+ across = "carried";
588
+ } else if (abrupt && e >= 2.5 * ref && log >= 0.06 && log > 3 * flankScale &&
589
+ speed(fit, g.w) > 3 * flankSpeed) {
590
+ // A step in scale in one frame between still or slow shoulders is
591
+ // a cut to a nearer or farther framing, not part of a move.
592
+ verdict = "match_cut";
593
+ across = "carried";
594
+ } else if (fast({ motion: fit, localPx: null, energy: e }, g.w, dt)) {
595
+ verdict = "fast_move";
596
+ }
597
+ }
598
+ // On a film faster than 30 fps one frame's move can be too small to fit
599
+ // on the grey copy: a change that is not abrupt is read again over a
600
+ // thirtieth of a second, as stateSteps reads travel.
601
+ if (verdict === "unresolved" && !abrupt && dt > 0 && dt < FAST_SECONDS * 0.75) {
602
+ const from = Math.max(0, i - Math.round(FAST_SECONDS / dt));
603
+ const m = pictureMotion(g, from, i);
604
+ const spanFit = m && speed(m, g.w) >= 0.25 ? fitEvidence(g, frame(g, from), b, m) : null;
605
+ if (spanFit && trusted(spanFit) && Math.abs(Math.log(spanFit.s)) < Math.log(SCALE_JUMP - 0.01) &&
606
+ fast({ motion: spanFit, localPx: null, energy: e }, g.w, studyTime(g, i) - studyTime(g, from)))
607
+ verdict = "fast_move";
608
+ }
609
+ if (verdict === "unresolved") {
610
+ const inPlace = pair.stillTexture + pair.flat;
611
+ const outside = fitEvidence(g, a, b, identity);
612
+ const local = steps[i]!.localPx ?? 0;
613
+ if ((pair.changed < 0.42 && (inPlace > 0.64 ||
614
+ (pair.changed < 0.20 && (inPlace > 0.54 || outside.support > 0.55)))) ||
615
+ (pair.changed < 0.70 && pair.edgeKept >= 0.75 && pair.stillTexture >= 0.13)) {
616
+ verdict = "in_picture_change";
617
+ } else if (local >= fastLocal && !abrupt && sides.some(fastAt)) {
618
+ verdict = "fast_move";
619
+ } else if (abrupt && (pair.changed >= 0.32 || (pair.changed >= 0.19 && e >= 0.035)) &&
620
+ !(local >= fastLocal && inPlace > 0.55)) {
621
+ const carry = carries.get(i);
622
+ const shoulders = Math.max(energy[i - 1] ?? 0, energy[i + 1] ?? 0);
623
+ // A layered push may fail the whole-frame fit. If a moving region
624
+ // survives the pair and either neighbouring step also has a strong
625
+ // change, keep the motion together unless the pair proved a jump.
626
+ const followed = shoulders >= 0.46 * e || !carry
627
+ ? follow(g, i - 1, i, 5) : null;
628
+ if (shoulders >= 0.46 * e && followed && followed.share >= 0.28 && followed.shift &&
629
+ Math.hypot(followed.shift.x, followed.shift.y) >= 1.5) {
630
+ verdict = "fast_move";
631
+ } else {
632
+ across = carry?.across ?? (Math.max(pair.stillTexture, followed?.share ?? 0) >= 0.10 ? "carried"
633
+ : pair.flat >= 0.25 ? "background only" : "nothing carried");
634
+ verdict = across === "carried" ? "match_cut" : "hard_cut";
635
+ }
636
+ }
637
+ }
638
+ }
639
+ const verified = verdict === "hard_cut" || verdict === "scale_jump" || verdict === "match_cut";
640
+ candidates.push({ frame: i, nominations, verdict, verified, across, energy: e, nearbyEnergy: ref,
641
+ changed: pair.changed, fit });
642
+ }
643
+ return { steps, candidates, means };
644
+ }
645
+
646
+ /** The camera's path, one reading a frame. `spans` gives, for a frame, the
647
+ * step that ends on it spanning a thirtieth of a second or more and the
648
+ * seconds it took (stateSteps): on a film faster than 30 fps a frame's own
649
+ * step moves too little to read on the grey copy, so the span's move is
650
+ * read and shared out over the frames it covers. */
651
+ export function cameraReadings(
652
+ g: StudyFrames,
653
+ steps: readonly Step[],
654
+ cuts: ReadonlySet<number>,
655
+ spans: ReadonlyMap<number, { step: Step; seconds: number }> = new Map(),
656
+ ) {
657
+ const path: CameraPath = { step: 1, t: [], logScale: [], dx: [], dy: [] };
658
+ for (let i = 1; i < g.count; i++) {
659
+ const own = studyTime(g, i) - studyTime(g, i - 1);
660
+ const span = spans.get(i);
661
+ const m = cuts.has(i) ? null : span ? span.step.motion : steps[i]!.motion;
662
+ const k = span && span.seconds > 0 && own > 0 ? own / span.seconds : 1;
663
+ path.t.push(studyTime(g, i));
664
+ path.logScale.push(m ? Math.log(m.s) * k : null);
665
+ path.dx.push(m ? (m.x / g.w) * k : null);
666
+ path.dy.push(m ? (m.y / g.h) * k : null);
667
+ }
668
+ return path;
669
+ }
670
+
671
+ export function motionSide(
672
+ g: StudyFrames, steps: readonly Step[], from: number, to: number,
673
+ ) {
674
+ const moves = [];
675
+ for (let i = Math.max(1, from); i < to; i++) {
676
+ const m = steps[i]!.motion;
677
+ if (m) moves.push({ m, dt: studyTime(g, i) - studyTime(g, i - 1) });
678
+ }
679
+ if (!moves.length) return null;
680
+ const x = median(moves.map(({ m }) => m.x * 640 / g.w));
681
+ const y = median(moves.map(({ m }) => m.y * 640 / g.w));
682
+ const logScale = median(moves.map(({ m }) => Math.log(m.s)));
683
+ const pxPerFrame = median(moves.map(({ m }) => speed(m, g.w)));
684
+ const pxPerSecond = median(moves.map(({ m, dt }) => speed(m, g.w) / dt));
685
+ const vx = median(moves.map(({ m, dt }) => m.x * 640 / g.w / dt));
686
+ const vy = median(moves.map(({ m, dt }) => m.y * 640 / g.w / dt));
687
+ const zoom = median(moves.map(({ m, dt }) => Math.log(m.s) / dt));
688
+ // The old still gate for a flank was |ln s| of 0.001 per frame at 30 fps.
689
+ const dir = Math.hypot(vx, vy) < DRIFT_RATE && Math.abs(zoom) < 0.001 * 30 ? "still"
690
+ : Math.abs(zoom) * 160 > Math.hypot(vx, vy) ? (zoom > 0 ? "in" : "out")
691
+ : Math.abs(vx) >= Math.abs(vy) ? (vx > 0 ? "right" : "left") : (vy > 0 ? "down" : "up");
692
+ return { dir, x, y, logScale, pxPerFrame, pxPerSecond };
693
+ }
694
+
695
+ export function boundaryMotion(
696
+ g: StudyFrames, steps: readonly Step[], c: PictureCandidate, from: number, to: number,
697
+ ) {
698
+ const i = c.frame;
699
+ const left = Math.max(from + 1, i - CAMERA_SIDE);
700
+ const right = Math.min(to, i + CAMERA_SIDE + 1);
701
+ const before = motionSide(g, steps, left, i);
702
+ const after = motionSide(g, steps, i + 1, right);
703
+ const across = c.fit;
704
+ const around = steps.slice(left, i).concat(steps.slice(i + 1, right));
705
+ const atPeak = across && around.some((s) => s.motion)
706
+ ? around.every((s) => !s.motion || speed(across, g.w) >= speed(s.motion, g.w))
707
+ : null;
708
+ const continues = before && after && before.dir !== "still" && after.dir !== "still"
709
+ ? before.dir === after.dir : null;
710
+ return { before, after, continues, atPeak, scale: across?.s ?? null };
711
+ }
712
+
713
+ /** What the study says crosses a cut: the probe's reading on the grey copy,
714
+ * or a small part seen staying put on a finer one. */
715
+ export type AcrossKind = CarryKind | "small part kept";
716
+
717
+ /** The width of the copy `keptInPlace` reads: the strips' colour frames. A
718
+ * thing 100 px across on a 1920 px film is one block of the 96 px grey copy
719
+ * and two or three across here. */
720
+ export const KEPT_WIDTH = 320;
721
+ const KEPT_BLOCK = 8;
722
+ // A block counts when it has texture before the cut (variance ≥ 100 grey²:
723
+ // lettering, a face, an icon — not a flat ground or a soft gradient) and the
724
+ // same block after it differs by under 6 grey levels a pixel, which JPEG noise
725
+ // stays below and a different picture does not.
726
+ const KEPT_TEXTURE = 100;
727
+ const KEPT_DIFFERENCE = 6;
728
+ // Lone blocks agree by chance across unrelated shots (up to 15 scattered ones
729
+ // at a hard cut of the launch reels this was checked on, never four
730
+ // touching); a thing that stayed covers several that touch.
731
+ const KEPT_TOUCHING = 4;
732
+
733
+ /** The share of the frame, 0..1, in patches of textured picture that are the
734
+ * same, in the same place, in the frame before a cut and the frame after it:
735
+ * a pinned caption, a logo, an avatar that the next scene opens on. Too small
736
+ * for the grey copy's 10 % "carried", and not nothing. It does not follow a
737
+ * thing that moves across the cut or lands on a different ground. `a` and
738
+ * `b` are grey frames of w × h. */
739
+ export function keptInPlace(a: Uint8Array, b: Uint8Array, w: number, h: number): number {
740
+ const B = KEPT_BLOCK;
741
+ const cols = Math.floor(w / B);
742
+ const rows = Math.floor(h / B);
743
+ if (cols < 1 || rows < 1) return 0;
744
+ const kept = new Uint8Array(cols * rows);
745
+ const n = B * B;
746
+ for (let by = 0; by < rows; by++) {
747
+ for (let bx = 0; bx < cols; bx++) {
748
+ let sum = 0;
749
+ let squares = 0;
750
+ let d = 0;
751
+ for (let r = by * B; r < by * B + B; r++) {
752
+ for (let c = bx * B; c < bx * B + B; c++) {
753
+ const va = a[r * w + c]!;
754
+ sum += va;
755
+ squares += va * va;
756
+ d += Math.abs(va - b[r * w + c]!);
757
+ }
758
+ }
759
+ if (squares / n - (sum / n) ** 2 >= KEPT_TEXTURE && d / n < KEPT_DIFFERENCE) kept[by * cols + bx] = 1;
760
+ }
761
+ }
762
+ // patches of blocks that touch, corners included
763
+ let total = 0;
764
+ const stack: number[] = [];
765
+ for (let k = 0; k < kept.length; k++) {
766
+ if (kept[k] !== 1) continue;
767
+ let size = 0;
768
+ kept[k] = 2;
769
+ stack.push(k);
770
+ while (stack.length) {
771
+ const at = stack.pop()!;
772
+ size++;
773
+ const x = at % cols;
774
+ const y = (at - x) / cols;
775
+ for (let dy = -1; dy <= 1; dy++) {
776
+ for (let dx = -1; dx <= 1; dx++) {
777
+ const nx = x + dx;
778
+ const ny = y + dy;
779
+ if (nx < 0 || ny < 0 || nx >= cols || ny >= rows) continue;
780
+ const j = ny * cols + nx;
781
+ if (kept[j] === 1) {
782
+ kept[j] = 2;
783
+ stack.push(j);
784
+ }
785
+ }
786
+ }
787
+ }
788
+ if (size >= KEPT_TOUCHING) total += size;
789
+ }
790
+ return total / kept.length;
791
+ }