@bydiorama/motion 0.0.0-stage → 0.4.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.
- package/CREDITS.md +62 -0
- package/LICENSE +21 -0
- package/README.md +142 -2
- package/catalog.json +4697 -0
- package/dist/npm/brief/brief.d.ts +28 -0
- package/dist/npm/brief/brief.js +159 -0
- package/dist/npm/brief/types.d.ts +75 -0
- package/dist/npm/brief/types.js +2 -0
- package/dist/npm/browser/motion.js +1039 -0
- package/dist/npm/browser/page.js +4821 -0
- package/dist/npm/browser/wizard.js +1511 -0
- package/dist/npm/build/design.d.ts +54 -0
- package/dist/npm/build/design.js +91 -0
- package/dist/npm/build/index.d.ts +39 -0
- package/dist/npm/build/index.js +66 -0
- package/dist/npm/build/iso.d.ts +41 -0
- package/dist/npm/build/iso.js +71 -0
- package/dist/npm/catalog.d.ts +24 -0
- package/dist/npm/catalog.js +23 -0
- package/dist/npm/cli/browser.d.ts +26 -0
- package/dist/npm/cli/browser.js +66 -0
- package/dist/npm/cli/capture.d.ts +26 -0
- package/dist/npm/cli/capture.js +94 -0
- package/dist/npm/cli/files.d.ts +14 -0
- package/dist/npm/cli/files.js +87 -0
- package/dist/npm/cli/frames.d.ts +27 -0
- package/dist/npm/cli/frames.js +125 -0
- package/dist/npm/cli/guard.d.ts +23 -0
- package/dist/npm/cli/guard.js +158 -0
- package/dist/npm/cli/library.d.ts +2 -0
- package/dist/npm/cli/library.js +55 -0
- package/dist/npm/cli/main.d.ts +17 -0
- package/dist/npm/cli/main.js +964 -0
- package/dist/npm/cli/motion.d.ts +2 -0
- package/dist/npm/cli/motion.js +6 -0
- package/dist/npm/cli/record.d.ts +36 -0
- package/dist/npm/cli/record.js +142 -0
- package/dist/npm/cli/review.d.ts +45 -0
- package/dist/npm/cli/review.js +139 -0
- package/dist/npm/cli/schema.d.ts +852 -0
- package/dist/npm/cli/schema.js +120 -0
- package/dist/npm/cli/server.d.ts +17 -0
- package/dist/npm/cli/server.js +135 -0
- package/dist/npm/core/ease.d.ts +39 -0
- package/dist/npm/core/ease.js +176 -0
- package/dist/npm/core/frame.d.ts +52 -0
- package/dist/npm/core/frame.js +60 -0
- package/dist/npm/core/shapes.d.ts +8 -0
- package/dist/npm/core/shapes.js +88 -0
- package/dist/npm/core/stagger.d.ts +19 -0
- package/dist/npm/core/stagger.js +77 -0
- package/dist/npm/core/tap.d.ts +19 -0
- package/dist/npm/core/tap.js +42 -0
- package/dist/npm/core/track.d.ts +4 -0
- package/dist/npm/core/track.js +23 -0
- package/dist/npm/dom/mount.d.ts +127 -0
- package/dist/npm/dom/mount.js +950 -0
- package/dist/npm/dom/page.d.ts +37 -0
- package/dist/npm/dom/page.js +77 -0
- package/dist/npm/dom/soundtrack.d.ts +13 -0
- package/dist/npm/dom/soundtrack.js +37 -0
- package/dist/npm/dom/stage.css.d.ts +1 -0
- package/dist/npm/dom/stage.css.js +44 -0
- package/dist/npm/dom/tokens.d.ts +10 -0
- package/dist/npm/dom/tokens.js +38 -0
- package/dist/npm/dom/ui-themes.css.d.ts +8 -0
- package/dist/npm/dom/ui-themes.css.js +9 -0
- package/dist/npm/film/beats.d.ts +64 -0
- package/dist/npm/film/beats.js +282 -0
- package/dist/npm/film/pace.d.ts +94 -0
- package/dist/npm/film/pace.js +396 -0
- package/dist/npm/film/resolve.d.ts +16 -0
- package/dist/npm/film/resolve.js +997 -0
- package/dist/npm/film/tempo.d.ts +19 -0
- package/dist/npm/film/tempo.js +34 -0
- package/dist/npm/film/tune.d.ts +17 -0
- package/dist/npm/film/tune.js +68 -0
- package/dist/npm/film/types.d.ts +416 -0
- package/dist/npm/film/types.js +16 -0
- package/dist/npm/index.d.ts +18 -0
- package/dist/npm/index.js +11 -0
- package/dist/npm/primitives/blur.d.ts +14 -0
- package/dist/npm/primitives/blur.js +59 -0
- package/dist/npm/primitives/canvas.d.ts +5 -0
- package/dist/npm/primitives/canvas.js +13 -0
- package/dist/npm/primitives/el/box.d.ts +2 -0
- package/dist/npm/primitives/el/box.js +24 -0
- package/dist/npm/primitives/el/frames.d.ts +15 -0
- package/dist/npm/primitives/el/frames.js +71 -0
- package/dist/npm/primitives/el/html.d.ts +2 -0
- package/dist/npm/primitives/el/html.js +14 -0
- package/dist/npm/primitives/el/image.d.ts +2 -0
- package/dist/npm/primitives/el/image.js +43 -0
- package/dist/npm/primitives/el/slot.d.ts +2 -0
- package/dist/npm/primitives/el/slot.js +25 -0
- package/dist/npm/primitives/el/text.d.ts +2 -0
- package/dist/npm/primitives/el/text.js +13 -0
- package/dist/npm/primitives/el/video.d.ts +6 -0
- package/dist/npm/primitives/el/video.js +179 -0
- package/dist/npm/primitives/fx/counter-roll.d.ts +2 -0
- package/dist/npm/primitives/fx/counter-roll.js +32 -0
- package/dist/npm/primitives/fx/depth-drift.d.ts +2 -0
- package/dist/npm/primitives/fx/depth-drift.js +44 -0
- package/dist/npm/primitives/fx/grid-ripple.d.ts +2 -0
- package/dist/npm/primitives/fx/grid-ripple.js +59 -0
- package/dist/npm/primitives/fx/odometer.d.ts +2 -0
- package/dist/npm/primitives/fx/odometer.js +80 -0
- package/dist/npm/primitives/fx/pan-across.d.ts +17 -0
- package/dist/npm/primitives/fx/pan-across.js +76 -0
- package/dist/npm/primitives/fx/path-draw.d.ts +2 -0
- package/dist/npm/primitives/fx/path-draw.js +105 -0
- package/dist/npm/primitives/fx/pin-drop.d.ts +2 -0
- package/dist/npm/primitives/fx/pin-drop.js +92 -0
- package/dist/npm/primitives/fx/shape-morph.d.ts +2 -0
- package/dist/npm/primitives/fx/shape-morph.js +65 -0
- package/dist/npm/primitives/fx/slow-push.d.ts +13 -0
- package/dist/npm/primitives/fx/slow-push.js +56 -0
- package/dist/npm/primitives/fx/stagger-fill.d.ts +2 -0
- package/dist/npm/primitives/fx/stagger-fill.js +33 -0
- package/dist/npm/primitives/index.d.ts +4 -0
- package/dist/npm/primitives/index.js +78 -0
- package/dist/npm/primitives/rig/browser-window.d.ts +2 -0
- package/dist/npm/primitives/rig/browser-window.js +142 -0
- package/dist/npm/primitives/rig/camera.d.ts +36 -0
- package/dist/npm/primitives/rig/camera.js +81 -0
- package/dist/npm/primitives/rig/footage-plane.d.ts +27 -0
- package/dist/npm/primitives/rig/footage-plane.js +257 -0
- package/dist/npm/primitives/rig/layer-stack.d.ts +39 -0
- package/dist/npm/primitives/rig/layer-stack.js +276 -0
- package/dist/npm/primitives/rig/orbit-ring.d.ts +2 -0
- package/dist/npm/primitives/rig/orbit-ring.js +59 -0
- package/dist/npm/primitives/rig/tab-stack.d.ts +9 -0
- package/dist/npm/primitives/rig/tab-stack.js +143 -0
- package/dist/npm/primitives/scene/bar-chart.d.ts +2 -0
- package/dist/npm/primitives/scene/bar-chart.js +83 -0
- package/dist/npm/primitives/scene/bento-grid.d.ts +49 -0
- package/dist/npm/primitives/scene/bento-grid.js +293 -0
- package/dist/npm/primitives/scene/grid-wall.d.ts +18 -0
- package/dist/npm/primitives/scene/grid-wall.js +110 -0
- package/dist/npm/primitives/scene/line-chart.d.ts +2 -0
- package/dist/npm/primitives/scene/line-chart.js +121 -0
- package/dist/npm/primitives/scene/logo-reveal.d.ts +2 -0
- package/dist/npm/primitives/scene/logo-reveal.js +117 -0
- package/dist/npm/primitives/scene/marquee-wall.d.ts +2 -0
- package/dist/npm/primitives/scene/marquee-wall.js +82 -0
- package/dist/npm/primitives/scene/post-carousel.d.ts +16 -0
- package/dist/npm/primitives/scene/post-carousel.js +195 -0
- package/dist/npm/primitives/scene/strip-cycle.d.ts +49 -0
- package/dist/npm/primitives/scene/strip-cycle.js +237 -0
- package/dist/npm/primitives/split.d.ts +34 -0
- package/dist/npm/primitives/split.js +105 -0
- package/dist/npm/primitives/texture/beat-field.d.ts +13 -0
- package/dist/npm/primitives/texture/beat-field.js +113 -0
- package/dist/npm/primitives/texture/gradient-drift.d.ts +2 -0
- package/dist/npm/primitives/texture/gradient-drift.js +56 -0
- package/dist/npm/primitives/texture/grain.d.ts +2 -0
- package/dist/npm/primitives/texture/grain.js +54 -0
- package/dist/npm/primitives/texture/halftone-field.d.ts +2 -0
- package/dist/npm/primitives/texture/halftone-field.js +36 -0
- package/dist/npm/primitives/texture/signal-field.d.ts +4 -0
- package/dist/npm/primitives/texture/signal-field.js +107 -0
- package/dist/npm/primitives/texture/vignette.d.ts +2 -0
- package/dist/npm/primitives/texture/vignette.js +23 -0
- package/dist/npm/primitives/transition/band-sweep.d.ts +22 -0
- package/dist/npm/primitives/transition/band-sweep.js +111 -0
- package/dist/npm/primitives/transition/beat-cut.d.ts +2 -0
- package/dist/npm/primitives/transition/beat-cut.js +10 -0
- package/dist/npm/primitives/transition/blur-dissolve.d.ts +2 -0
- package/dist/npm/primitives/transition/blur-dissolve.js +28 -0
- package/dist/npm/primitives/transition/camera-travel.d.ts +2 -0
- package/dist/npm/primitives/transition/camera-travel.js +69 -0
- package/dist/npm/primitives/transition/cover-reveal.d.ts +2 -0
- package/dist/npm/primitives/transition/cover-reveal.js +52 -0
- package/dist/npm/primitives/transition/curtain.d.ts +2 -0
- package/dist/npm/primitives/transition/curtain.js +40 -0
- package/dist/npm/primitives/transition/dive-in.d.ts +2 -0
- package/dist/npm/primitives/transition/dive-in.js +52 -0
- package/dist/npm/primitives/transition/fly-past.d.ts +2 -0
- package/dist/npm/primitives/transition/fly-past.js +87 -0
- package/dist/npm/primitives/transition/iris.d.ts +2 -0
- package/dist/npm/primitives/transition/iris.js +38 -0
- package/dist/npm/primitives/transition/overlay.d.ts +4 -0
- package/dist/npm/primitives/transition/overlay.js +24 -0
- package/dist/npm/primitives/transition/push.d.ts +2 -0
- package/dist/npm/primitives/transition/push.js +35 -0
- package/dist/npm/primitives/transition/signal-wipe.d.ts +2 -0
- package/dist/npm/primitives/transition/signal-wipe.js +67 -0
- package/dist/npm/primitives/transition/slant-wipe.d.ts +2 -0
- package/dist/npm/primitives/transition/slant-wipe.js +30 -0
- package/dist/npm/primitives/transition/stack-over.d.ts +2 -0
- package/dist/npm/primitives/transition/stack-over.js +38 -0
- package/dist/npm/primitives/transition/step-wipe.d.ts +2 -0
- package/dist/npm/primitives/transition/step-wipe.js +29 -0
- package/dist/npm/primitives/transition/strip-wipe.d.ts +40 -0
- package/dist/npm/primitives/transition/strip-wipe.js +121 -0
- package/dist/npm/primitives/transition/whip-pan.d.ts +2 -0
- package/dist/npm/primitives/transition/whip-pan.js +45 -0
- package/dist/npm/primitives/type/block-reveal.d.ts +2 -0
- package/dist/npm/primitives/type/block-reveal.js +61 -0
- package/dist/npm/primitives/type/char-cascade.d.ts +2 -0
- package/dist/npm/primitives/type/char-cascade.js +45 -0
- package/dist/npm/primitives/type/echo.d.ts +2 -0
- package/dist/npm/primitives/type/echo.js +57 -0
- package/dist/npm/primitives/type/fill-text.d.ts +14 -0
- package/dist/npm/primitives/type/fill-text.js +82 -0
- package/dist/npm/primitives/type/mask-reveal.d.ts +2 -0
- package/dist/npm/primitives/type/mask-reveal.js +58 -0
- package/dist/npm/primitives/type/scramble.d.ts +2 -0
- package/dist/npm/primitives/type/scramble.js +34 -0
- package/dist/npm/primitives/type/scribble-highlight.d.ts +2 -0
- package/dist/npm/primitives/type/scribble-highlight.js +84 -0
- package/dist/npm/primitives/type/shimmer.d.ts +2 -0
- package/dist/npm/primitives/type/shimmer.js +35 -0
- package/dist/npm/primitives/type/tracking-in.d.ts +2 -0
- package/dist/npm/primitives/type/tracking-in.js +37 -0
- package/dist/npm/primitives/type/typed-title.d.ts +2 -0
- package/dist/npm/primitives/type/typed-title.js +33 -0
- package/dist/npm/primitives/type/word-build.d.ts +2 -0
- package/dist/npm/primitives/type/word-build.js +44 -0
- package/dist/npm/primitives/type/word-roller.d.ts +2 -0
- package/dist/npm/primitives/type/word-roller.js +80 -0
- package/dist/npm/primitives/types.d.ts +183 -0
- package/dist/npm/primitives/types.js +5 -0
- package/dist/npm/primitives/ui/cursor-click.d.ts +4 -0
- package/dist/npm/primitives/ui/cursor-click.js +68 -0
- package/dist/npm/primitives/ui/page-scroll.d.ts +17 -0
- package/dist/npm/primitives/ui/page-scroll.js +98 -0
- package/dist/npm/review/fft.d.ts +4 -0
- package/dist/npm/review/fft.js +71 -0
- package/dist/npm/review/measure.d.ts +170 -0
- package/dist/npm/review/measure.js +577 -0
- package/dist/npm/tokens.d.ts +50 -0
- package/dist/npm/tokens.js +49 -0
- package/dist/npm/version.d.ts +1 -0
- package/dist/npm/version.js +1 -0
- package/examples/builder.film.mjs +18 -0
- package/films/feature-announcement.film.json +70 -0
- package/library/narratives/app-demo.md +64 -0
- package/library/narratives/brand-identity.md +78 -0
- package/library/narratives/capability-through-type.md +53 -0
- package/library/narratives/data-story.md +59 -0
- package/library/narratives/explainer.md +64 -0
- package/library/narratives/feature-announcement.md +68 -0
- package/library/narratives/infinite-loop.md +28 -0
- package/library/narratives/platform-launch.md +81 -0
- package/library/narratives/social-teaser.md +45 -0
- package/library/narratives/title-sequence.md +55 -0
- package/library/narratives/website-launch.md +65 -0
- package/library/primitives/fx/card-arrangements.md +26 -0
- package/library/primitives/fx/counter-roll.md +27 -0
- package/library/primitives/fx/depth-drift.md +32 -0
- package/library/primitives/fx/grid-ripple.md +58 -0
- package/library/primitives/fx/letter-interleave.md +26 -0
- package/library/primitives/fx/marquee-highlight.md +27 -0
- package/library/primitives/fx/mosaic-fill.md +23 -0
- package/library/primitives/fx/odometer.md +44 -0
- package/library/primitives/fx/pan-across.md +63 -0
- package/library/primitives/fx/path-draw.md +54 -0
- package/library/primitives/fx/pin-drop.md +51 -0
- package/library/primitives/fx/radial-burst.md +33 -0
- package/library/primitives/fx/shape-morph.md +45 -0
- package/library/primitives/fx/slow-push.md +63 -0
- package/library/primitives/fx/stagger-fill.md +28 -0
- package/library/primitives/rig/browser-window.md +113 -0
- package/library/primitives/rig/flip-ticker.md +26 -0
- package/library/primitives/rig/footage-plane.md +90 -0
- package/library/primitives/rig/layer-stack.md +168 -0
- package/library/primitives/rig/orbit-ring.md +43 -0
- package/library/primitives/rig/rolodex.md +31 -0
- package/library/primitives/rig/tab-stack.md +116 -0
- package/library/primitives/rig/tumbling-object.md +27 -0
- package/library/primitives/scene/bar-chart.md +49 -0
- package/library/primitives/scene/bento-grid.md +74 -0
- package/library/primitives/scene/end-card.md +28 -0
- package/library/primitives/scene/grid-wall.md +61 -0
- package/library/primitives/scene/hero-object.md +33 -0
- package/library/primitives/scene/kinetic-headline.md +34 -0
- package/library/primitives/scene/line-chart.md +47 -0
- package/library/primitives/scene/logo-reveal.md +53 -0
- package/library/primitives/scene/marquee-wall.md +33 -0
- package/library/primitives/scene/mosaic.md +28 -0
- package/library/primitives/scene/post-carousel.md +68 -0
- package/library/primitives/scene/specimen-grid.md +28 -0
- package/library/primitives/scene/stat-with-evidence.md +34 -0
- package/library/primitives/scene/strip-cycle.md +122 -0
- package/library/primitives/scene/zoomed-ui.md +29 -0
- package/library/primitives/texture/ascii.md +22 -0
- package/library/primitives/texture/beat-field.md +85 -0
- package/library/primitives/texture/depth-fade.md +23 -0
- package/library/primitives/texture/dither.md +27 -0
- package/library/primitives/texture/gradient-drift.md +50 -0
- package/library/primitives/texture/grain.md +39 -0
- package/library/primitives/texture/halftone-field.md +26 -0
- package/library/primitives/texture/signal-field.md +61 -0
- package/library/primitives/texture/vignette.md +53 -0
- package/library/primitives/transition/band-sweep.md +63 -0
- package/library/primitives/transition/beat-cut.md +27 -0
- package/library/primitives/transition/blur-dissolve.md +36 -0
- package/library/primitives/transition/camera-travel.md +57 -0
- package/library/primitives/transition/collapse-to-anchor.md +27 -0
- package/library/primitives/transition/cover-reveal.md +47 -0
- package/library/primitives/transition/curtain.md +42 -0
- package/library/primitives/transition/dive-in.md +51 -0
- package/library/primitives/transition/fly-past.md +51 -0
- package/library/primitives/transition/iris.md +49 -0
- package/library/primitives/transition/layout-locked-swap.md +28 -0
- package/library/primitives/transition/light-dark-flip.md +27 -0
- package/library/primitives/transition/push.md +47 -0
- package/library/primitives/transition/signal-wipe.md +52 -0
- package/library/primitives/transition/slant-wipe.md +44 -0
- package/library/primitives/transition/stack-over.md +51 -0
- package/library/primitives/transition/step-wipe.md +32 -0
- package/library/primitives/transition/strip-wipe.md +80 -0
- package/library/primitives/transition/torn-edge.md +26 -0
- package/library/primitives/transition/whip-pan.md +47 -0
- package/library/primitives/transition/zoom-through-letter.md +27 -0
- package/library/primitives/type/accent-number.md +22 -0
- package/library/primitives/type/block-reveal.md +41 -0
- package/library/primitives/type/char-cascade.md +65 -0
- package/library/primitives/type/echo.md +44 -0
- package/library/primitives/type/fill-text.md +63 -0
- package/library/primitives/type/focus-blur.md +22 -0
- package/library/primitives/type/inline-chips.md +27 -0
- package/library/primitives/type/mask-reveal.md +65 -0
- package/library/primitives/type/parting.md +23 -0
- package/library/primitives/type/per-word-restyle.md +28 -0
- package/library/primitives/type/scramble.md +26 -0
- package/library/primitives/type/scribble-highlight.md +47 -0
- package/library/primitives/type/shimmer.md +39 -0
- package/library/primitives/type/split-flap.md +26 -0
- package/library/primitives/type/style-multiply.md +23 -0
- package/library/primitives/type/tracking-in.md +40 -0
- package/library/primitives/type/typed-title.md +27 -0
- package/library/primitives/type/word-build.md +37 -0
- package/library/primitives/type/word-roller.md +52 -0
- package/library/primitives/type/writing-ticker.md +27 -0
- package/library/primitives/ui/collab-cursors.md +27 -0
- package/library/primitives/ui/cursor-click.md +61 -0
- package/library/primitives/ui/page-scroll.md +58 -0
- package/library/primitives/ui/prompt-typing.md +29 -0
- package/library/primitives/ui/streamed-result.md +23 -0
- package/library/primitives/ui/tour-hold.md +27 -0
- package/library/styles/brand-system.md +49 -0
- package/library/styles/clean-explainer.md +42 -0
- package/library/styles/dark-showcase.md +48 -0
- package/library/styles/editorial-type.md +37 -0
- package/library/styles/kinetic-poster.md +54 -0
- package/library/styles/product-ui.md +44 -0
- package/library/styles/studio-loop.md +41 -0
- package/library.json +1467 -0
- package/package.json +64 -4
- package/schema/film.schema.json +1316 -0
- package/showcase/vendor/DIALKIT-LICENSE +21 -0
- package/src/studio/theme/fonts/OFL.txt +94 -0
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
// What `motion review` measures, as pure functions over grey frames.
|
|
2
|
+
//
|
|
3
|
+
// A film is coherent when everything that moves together moves as one, and
|
|
4
|
+
// nothing changes from one frame to the next that did not mean to. Stills
|
|
5
|
+
// cannot show either: a line that wraps one way, then the other, looks fine in
|
|
6
|
+
// every single frame. So every pair of neighbouring frames is compared:
|
|
7
|
+
//
|
|
8
|
+
// - The picture is cut into tiles, and each tile's shift from the frame before
|
|
9
|
+
// is found by phase correlation, to a tenth of a pixel.
|
|
10
|
+
// - The shifts are fitted to one camera move: a plane seen by a moving camera
|
|
11
|
+
// (pan, zoom, turn and a little perspective). What the fit leaves over in a
|
|
12
|
+
// tile is that tile moving on its own.
|
|
13
|
+
// - The camera's own motion must not turn back and forth (wiggle), jump for a
|
|
14
|
+
// frame and stop (jump), or stall for a frame mid-move (stall). Tiles must not
|
|
15
|
+
// shake against the camera (floating).
|
|
16
|
+
// - Light must not blink: a frame unlike both neighbours while they agree
|
|
17
|
+
// (blip), brightness that flips up and down every frame (flicker), and fine
|
|
18
|
+
// detail that crawls while the picture holds still (shimmer).
|
|
19
|
+
//
|
|
20
|
+
// All sizes in findings are in pixels of the source frame, scaled to a frame
|
|
21
|
+
// 1080 px on its shorter side, so thresholds mean the same at any resolution.
|
|
22
|
+
import { fft2 } from "./fft.js";
|
|
23
|
+
/** Pixels per analysis pixel are rescaled to this short side for every threshold. */
|
|
24
|
+
export const REFERENCE_SHORT = 1080;
|
|
25
|
+
export const THRESHOLDS = {
|
|
26
|
+
/** A camera reversal counts when both steps are at least this (px at 1080). */
|
|
27
|
+
wiggle: 1.5,
|
|
28
|
+
/** A step at least this big (px at 1080) and 3× its neighbours is a candidate jump. */
|
|
29
|
+
jump: 3,
|
|
30
|
+
/** A tile shaking against the camera by at least this much (px at 1080), turning back and forth … */
|
|
31
|
+
floating: 2,
|
|
32
|
+
/** … but no more than this: a bigger local motion is something animating, not the layout giving way. */
|
|
33
|
+
floatingMax: 12,
|
|
34
|
+
/** Only tiles that match this well, and this unambiguously, count for floating: the same content, moved, not changed. */
|
|
35
|
+
floatingPeak: 0.3, floatingClarity: 2,
|
|
36
|
+
/** Reversals of one tile within half a second that make it floating. */
|
|
37
|
+
floatingReversals: 4,
|
|
38
|
+
/** A frame differing from both neighbours by this many levels, while they are this share as far apart. */
|
|
39
|
+
blip: 2, blipShare: 0.35,
|
|
40
|
+
/** Brightness flipping up and down by this many levels, frame after frame, in a tile. */
|
|
41
|
+
flicker: 1.5, flickerFlips: 3,
|
|
42
|
+
/** Frame-to-frame change of fine detail in still tiles, in levels, held for a quarter second. */
|
|
43
|
+
shimmer: 1.2,
|
|
44
|
+
/** A tile holding for a frame inside a steady move of at least judderMin px a frame (at 1080), judderBeats
|
|
45
|
+
* times within half a second apart, judders; a fault when its steps are at least `judder` px. */
|
|
46
|
+
judder: 1.5, judderMin: 0.6, judderBeats: 3,
|
|
47
|
+
/** A pan faster than this share of the short side a frame strobes (CRAFT §7: a fortieth). */
|
|
48
|
+
strobe: 1 / 40,
|
|
49
|
+
};
|
|
50
|
+
const TILE = 64;
|
|
51
|
+
/** Mean step between neighbouring pixels, in levels, below which a tile has nothing to match. */
|
|
52
|
+
const MIN_EDGE = 1;
|
|
53
|
+
function hann(n) {
|
|
54
|
+
const w = new Float64Array(n * n);
|
|
55
|
+
for (let y = 0; y < n; y++)
|
|
56
|
+
for (let x = 0; x < n; x++) {
|
|
57
|
+
w[y * n + x] = (0.5 - 0.5 * Math.cos((2 * Math.PI * (x + 0.5)) / n)) * (0.5 - 0.5 * Math.cos((2 * Math.PI * (y + 0.5)) / n));
|
|
58
|
+
}
|
|
59
|
+
return w;
|
|
60
|
+
}
|
|
61
|
+
/** Tile spectra of one frame, windowed with the mean removed; null for a flat tile. */
|
|
62
|
+
function spectra(f, w, tiles, win) {
|
|
63
|
+
return tiles.map((t) => {
|
|
64
|
+
const re = new Float64Array(TILE * TILE), im = new Float64Array(TILE * TILE);
|
|
65
|
+
// Texture is edges, not spread: a smooth gradient (a vignette, a glow) has spread but nothing
|
|
66
|
+
// to lock onto, and a tile of it matches "no motion" whatever the picture does.
|
|
67
|
+
let sum = 0, edge = 0;
|
|
68
|
+
for (let y = 0; y < TILE; y++)
|
|
69
|
+
for (let x = 0; x < TILE; x++) {
|
|
70
|
+
const o = (t.y + y) * w + t.x + x, v = f[o];
|
|
71
|
+
sum += v;
|
|
72
|
+
if (x + 1 < TILE)
|
|
73
|
+
edge += Math.abs(f[o + 1] - v);
|
|
74
|
+
if (y + 1 < TILE)
|
|
75
|
+
edge += Math.abs(f[o + w] - v);
|
|
76
|
+
}
|
|
77
|
+
const n = TILE * TILE, mean = sum / n;
|
|
78
|
+
if (edge / (2 * (TILE - 1) * TILE) < MIN_EDGE)
|
|
79
|
+
return null;
|
|
80
|
+
for (let y = 0; y < TILE; y++)
|
|
81
|
+
for (let x = 0; x < TILE; x++)
|
|
82
|
+
re[y * TILE + x] = (f[(t.y + y) * w + t.x + x] - mean) * win[y * TILE + x];
|
|
83
|
+
fft2(re, im, TILE);
|
|
84
|
+
return { re, im };
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** One tile's spectrum, taken at (x, y); null when flat or outside the frame. */
|
|
88
|
+
function tileSpectrum(f, w, h, x0, y0, win) {
|
|
89
|
+
if (x0 < 0 || y0 < 0 || x0 + TILE > w || y0 + TILE > h)
|
|
90
|
+
return null;
|
|
91
|
+
return spectra(f, w, [{ x: x0, y: y0, cx: 0, cy: 0 }], win)[0] ?? null;
|
|
92
|
+
}
|
|
93
|
+
/** How far tile content moved from a to b, by phase correlation, with a sub-pixel peak. */
|
|
94
|
+
export function correlate(a, b) {
|
|
95
|
+
const N = TILE, n = N * N, cr = new Float64Array(n), ci = new Float64Array(n);
|
|
96
|
+
for (let k = 0; k < n; k++) {
|
|
97
|
+
// b × conj(a), normalised: the peak of its inverse sits at the shift from a to b.
|
|
98
|
+
const r = b.re[k] * a.re[k] + b.im[k] * a.im[k], i = b.im[k] * a.re[k] - b.re[k] * a.im[k];
|
|
99
|
+
const m = Math.hypot(r, i) + 1e-12;
|
|
100
|
+
cr[k] = r / m;
|
|
101
|
+
ci[k] = i / m;
|
|
102
|
+
}
|
|
103
|
+
const first = peakOf(cr, ci, 0, 0);
|
|
104
|
+
// Sub-pixel estimates lean toward whole pixels ("pixel locking"), so a steady 0.4 px drift reads
|
|
105
|
+
// as move, hold, move: a judder that is not there. Undo the estimate in the spectrum and measure
|
|
106
|
+
// what is left near zero, where the estimate is unbiased.
|
|
107
|
+
const second = peakOf(cr, ci, first.dx, first.dy);
|
|
108
|
+
return { dx: first.dx + second.dx, dy: first.dy + second.dy, peak: first.peak, clarity: first.clarity };
|
|
109
|
+
}
|
|
110
|
+
/** The peak of the inverse of a normalised cross-power spectrum, after taking out a shift of (sx, sy). */
|
|
111
|
+
function peakOf(cr, ci, sx, sy) {
|
|
112
|
+
const N = TILE, n = N * N, re = new Float64Array(n), im = new Float64Array(n);
|
|
113
|
+
for (let v = 0; v < N; v++)
|
|
114
|
+
for (let u = 0; u < N; u++) {
|
|
115
|
+
const k = v * N + u, fu = u > N / 2 ? u - N : u, fv = v > N / 2 ? v - N : v;
|
|
116
|
+
const ang = (2 * Math.PI * (fu * sx + fv * sy)) / N, c = Math.cos(ang), s = Math.sin(ang);
|
|
117
|
+
re[k] = cr[k] * c - ci[k] * s;
|
|
118
|
+
im[k] = cr[k] * s + ci[k] * c;
|
|
119
|
+
}
|
|
120
|
+
fft2(re, im, N, true);
|
|
121
|
+
let best = -Infinity, at = 0;
|
|
122
|
+
for (let k = 0; k < n; k++)
|
|
123
|
+
if (re[k] > best) {
|
|
124
|
+
best = re[k];
|
|
125
|
+
at = k;
|
|
126
|
+
}
|
|
127
|
+
const px = at % N, py = Math.floor(at / N);
|
|
128
|
+
// The runner-up, away from the peak (wrapping): how sure the match is.
|
|
129
|
+
let second = 1e-9;
|
|
130
|
+
for (let k = 0; k < n; k++) {
|
|
131
|
+
const ddx = Math.abs((k % N) - px), ddy = Math.abs(Math.floor(k / N) - py);
|
|
132
|
+
if (Math.min(ddx, N - ddx) <= 2 && Math.min(ddy, N - ddy) <= 2)
|
|
133
|
+
continue;
|
|
134
|
+
if (re[k] > second)
|
|
135
|
+
second = re[k];
|
|
136
|
+
}
|
|
137
|
+
const at2 = (x, y) => re[((y + N) % N) * N + ((x + N) % N)];
|
|
138
|
+
// Foroosh et al. 2002: for a phase-correlation peak, the shift is the larger neighbour's share.
|
|
139
|
+
const sub = (l, c, r) => (Math.max(l, r) <= 0 ? 0 : r > l ? r / (r + c) : -l / (l + c));
|
|
140
|
+
const fx = px + sub(at2(px - 1, py), best, at2(px + 1, py)), fy = py + sub(at2(px, py - 1), best, at2(px, py + 1));
|
|
141
|
+
return { dx: fx > N / 2 ? fx - N : fx, dy: fy > N / 2 ? fy - N : fy, peak: best, clarity: best / second };
|
|
142
|
+
}
|
|
143
|
+
/** Solve A x = b for a small dense system (Gaussian elimination with pivoting); null when singular. */
|
|
144
|
+
function solve(A, b) {
|
|
145
|
+
const n = b.length, M = A.map((r, i) => [...r, b[i]]);
|
|
146
|
+
for (let c = 0; c < n; c++) {
|
|
147
|
+
let p = c;
|
|
148
|
+
for (let r = c + 1; r < n; r++)
|
|
149
|
+
if (Math.abs(M[r][c]) > Math.abs(M[p][c]))
|
|
150
|
+
p = r;
|
|
151
|
+
if (Math.abs(M[p][c]) < 1e-12)
|
|
152
|
+
return null;
|
|
153
|
+
[M[c], M[p]] = [M[p], M[c]];
|
|
154
|
+
for (let r = 0; r < n; r++) {
|
|
155
|
+
if (r === c)
|
|
156
|
+
continue;
|
|
157
|
+
const f = M[r][c] / M[c][c];
|
|
158
|
+
for (let k = c; k <= n; k++)
|
|
159
|
+
M[r][k] -= f * M[c][k];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return M.map((r, i) => r[n] / r[i]);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The camera move that best explains the tile shifts: a plane under a moving
|
|
166
|
+
* camera, to first order (pan, zoom, turn, shear and perspective: the eight
|
|
167
|
+
* terms of a linearised homography). `R` normalises positions. Weighted by each
|
|
168
|
+
* tile's match strength; returns the camera, a predictor and each tile's leftover.
|
|
169
|
+
*/
|
|
170
|
+
export function fitCamera(t, R) {
|
|
171
|
+
const full = t.length >= 7;
|
|
172
|
+
// Unknowns: full model [a0 a1 a2 b0 b1 b2 c1 c2]; similarity [tx ty s r].
|
|
173
|
+
const terms = (cx, cy) => {
|
|
174
|
+
const x = cx / R, y = cy / R;
|
|
175
|
+
return full ? [[1, x, y, 0, 0, 0, x * x, x * y], [0, 0, 0, 1, x, y, x * y, y * y]] : [[1, 0, x, -y], [0, 1, y, x]];
|
|
176
|
+
};
|
|
177
|
+
const n = full ? 8 : 4;
|
|
178
|
+
const A = Array.from({ length: n }, () => new Array(n).fill(0)), b = new Array(n).fill(0);
|
|
179
|
+
for (const s of t) {
|
|
180
|
+
const [ex, ey] = terms(s.cx, s.cy);
|
|
181
|
+
for (const [row, v] of [[ex, s.dx], [ey, s.dy]]) {
|
|
182
|
+
for (let i = 0; i < n; i++) {
|
|
183
|
+
b[i] += s.weight * row[i] * v;
|
|
184
|
+
for (let j = 0; j < n; j++)
|
|
185
|
+
A[i][j] += s.weight * row[i] * row[j];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const p = solve(A, b);
|
|
190
|
+
if (!p)
|
|
191
|
+
return null;
|
|
192
|
+
const dot = (row) => row.reduce((s, x, i) => s + x * p[i], 0);
|
|
193
|
+
const predict = (cx, cy) => { const [ex, ey] = terms(cx, cy); return [dot(ex), dot(ey)]; };
|
|
194
|
+
const cam = full
|
|
195
|
+
? { tx: p[0], ty: p[3], zoom: (p[1] + p[5]) / 2 / R, rot: (p[4] - p[2]) / 2 / R }
|
|
196
|
+
: { tx: p[0], ty: p[1], zoom: p[2] / R, rot: p[3] / R };
|
|
197
|
+
return { cam, predict, residual: t.map((s) => { const [vx, vy] = predict(s.cx, s.cy); return [s.dx - vx, s.dy - vy]; }) };
|
|
198
|
+
}
|
|
199
|
+
/** Fits, then refits without tiles that clearly move on their own (an element entering, text streaming). */
|
|
200
|
+
function robustFit(tiles, R, last) {
|
|
201
|
+
const ok = tiles.map((t) => ({ ...t, weight: t.peak })).filter((t) => t.ok);
|
|
202
|
+
// Seed with the largest group that moves alike: a picture can hold two planes (the world under
|
|
203
|
+
// the camera, and a frame or vignette fixed to the screen), and a fit across both is neither.
|
|
204
|
+
// When two groups are near the same size (a panel gliding while the page holds), keep the one that
|
|
205
|
+
// carries on the last frame's motion, so the fit does not swap between them frame by frame.
|
|
206
|
+
const groups = ok.map((c) => ok.filter((t) => Math.hypot(t.dx - c.dx, t.dy - c.dy) <= Math.max(1.5, 0.15 * Math.hypot(c.dx, c.dy))));
|
|
207
|
+
const size = Math.max(0, ...groups.map((g) => g.length));
|
|
208
|
+
const off = (g) => (last ? g.reduce((s, t) => { const [vx, vy] = last.predict(t.cx, t.cy); return s + Math.hypot(t.dx - vx, t.dy - vy); }, 0) / g.length : 0);
|
|
209
|
+
let best = [];
|
|
210
|
+
for (const g of groups)
|
|
211
|
+
if (g.length >= 0.75 * size && (!best.length || off(g) < off(best) - 0.5 || (Math.abs(off(g) - off(best)) <= 0.5 && g.length > best.length)))
|
|
212
|
+
best = g;
|
|
213
|
+
// No camera when no group holds half the tiles: the picture is changing, not moving, and a fit would invent a move.
|
|
214
|
+
if (best.length < Math.max(4, ok.length / 2))
|
|
215
|
+
return undefined;
|
|
216
|
+
let use = best;
|
|
217
|
+
let fit = fitCamera(use, R);
|
|
218
|
+
// Grow the seed to every tile the seed's model explains, so zoom and perspective are fitted across the frame.
|
|
219
|
+
if (fit) {
|
|
220
|
+
const f0 = fit;
|
|
221
|
+
const grown = ok.filter((t) => { const [vx, vy] = f0.predict(t.cx, t.cy); return Math.hypot(t.dx - vx, t.dy - vy) <= Math.max(1, 0.1 * Math.hypot(vx, vy)); });
|
|
222
|
+
if (grown.length >= use.length) {
|
|
223
|
+
use = grown;
|
|
224
|
+
fit = fitCamera(use, R) ?? fit;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (let pass = 0; pass < 2 && fit; pass++) {
|
|
228
|
+
const mags = fit.residual.map(([x, y]) => Math.hypot(x, y)), sorted = [...mags].sort((a, b) => a - b);
|
|
229
|
+
const cut = Math.max(0.6, 3 * sorted[Math.floor(sorted.length / 2)]);
|
|
230
|
+
const keep = use.filter((_, i) => mags[i] <= cut);
|
|
231
|
+
if (keep.length === use.length || keep.length < 4)
|
|
232
|
+
break;
|
|
233
|
+
use = keep;
|
|
234
|
+
fit = fitCamera(use, R) ?? fit;
|
|
235
|
+
}
|
|
236
|
+
if (!fit)
|
|
237
|
+
return undefined;
|
|
238
|
+
// Leftovers for every measured tile against the final fit, kept or not.
|
|
239
|
+
const f = fit;
|
|
240
|
+
return { cam: f.cam, predict: (cx, cy) => f.predict(cx, cy), residual: tiles.map((t) => { if (!t.ok)
|
|
241
|
+
return undefined; const [vx, vy] = f.predict(t.cx, t.cy); return [t.dx - vx, t.dy - vy]; }) };
|
|
242
|
+
}
|
|
243
|
+
function smallFrame(f, w, h, k = 4) {
|
|
244
|
+
const sw = Math.floor(w / k), sh = Math.floor(h / k), out = new Float32Array(sw * sh);
|
|
245
|
+
for (let y = 0; y < sh; y++)
|
|
246
|
+
for (let x = 0; x < sw; x++) {
|
|
247
|
+
let s = 0;
|
|
248
|
+
for (let j = 0; j < k; j++)
|
|
249
|
+
for (let i = 0; i < k; i++)
|
|
250
|
+
s += f[(y * k + j) * w + x * k + i];
|
|
251
|
+
out[y * sw + x] = s / (k * k);
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
const meanAbs = (a, b) => { let s = 0; for (let i = 0; i < a.length; i++)
|
|
256
|
+
s += Math.abs(a[i] - b[i]); return s / a.length; };
|
|
257
|
+
/** Fine detail of a tile: the tile minus its 3 × 3 average. */
|
|
258
|
+
function detail(f, w, t) {
|
|
259
|
+
const out = new Float32Array((TILE - 2) * (TILE - 2));
|
|
260
|
+
for (let y = 1; y < TILE - 1; y++)
|
|
261
|
+
for (let x = 1; x < TILE - 1; x++) {
|
|
262
|
+
let s = 0;
|
|
263
|
+
for (let j = -1; j <= 1; j++)
|
|
264
|
+
for (let i = -1; i <= 1; i++)
|
|
265
|
+
s += f[(t.y + y + j) * w + t.x + x + i];
|
|
266
|
+
out[(y - 1) * (TILE - 2) + x - 1] = f[(t.y + y) * w + t.x + x] - s / 9;
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Takes frames one at a time (grey, w × h, levels 0–255) and keeps only what
|
|
272
|
+
* the findings need, so a long film never sits in memory whole.
|
|
273
|
+
*/
|
|
274
|
+
export class Analyser {
|
|
275
|
+
tiles;
|
|
276
|
+
win = hann(TILE);
|
|
277
|
+
prev;
|
|
278
|
+
before;
|
|
279
|
+
lastFit;
|
|
280
|
+
steps = [];
|
|
281
|
+
luma = [];
|
|
282
|
+
skip = [0];
|
|
283
|
+
n = 0;
|
|
284
|
+
R;
|
|
285
|
+
w;
|
|
286
|
+
h;
|
|
287
|
+
scale;
|
|
288
|
+
constructor(w, h, scale) {
|
|
289
|
+
this.w = w;
|
|
290
|
+
this.h = h;
|
|
291
|
+
this.scale = scale;
|
|
292
|
+
const cols = Math.max(1, Math.floor(w / (TILE * 1.25))), rows = Math.max(1, Math.floor(h / (TILE * 1.25)));
|
|
293
|
+
this.tiles = [];
|
|
294
|
+
for (let r = 0; r < rows; r++)
|
|
295
|
+
for (let c = 0; c < cols; c++) {
|
|
296
|
+
const x = Math.round(((c + 0.5) * w) / cols - TILE / 2), y = Math.round(((r + 0.5) * h) / rows - TILE / 2);
|
|
297
|
+
this.tiles.push({ x, y, cx: x + TILE / 2 - w / 2, cy: y + TILE / 2 - h / 2 });
|
|
298
|
+
}
|
|
299
|
+
this.R = Math.max(w, h) / 2;
|
|
300
|
+
}
|
|
301
|
+
push(f) {
|
|
302
|
+
const spec = spectra(f, this.w, this.tiles, this.win), small = smallFrame(f, this.w, this.h);
|
|
303
|
+
const luma = new Float32Array(this.tiles.length);
|
|
304
|
+
this.tiles.forEach((t, k) => { let s = 0; for (let y = 0; y < TILE; y++)
|
|
305
|
+
for (let x = 0; x < TILE; x++)
|
|
306
|
+
s += f[(t.y + y) * this.w + t.x + x]; luma[k] = s / (TILE * TILE); });
|
|
307
|
+
this.luma.push(luma);
|
|
308
|
+
const det = this.tiles.map((t) => detail(f, this.w, t));
|
|
309
|
+
if (this.prev) {
|
|
310
|
+
const p = this.prev;
|
|
311
|
+
// A fast move carries content past what one tile can see; look where the last step says it went.
|
|
312
|
+
const last = this.lastFit;
|
|
313
|
+
const tiles = this.tiles.map((t, k) => {
|
|
314
|
+
const a = p.spec[k];
|
|
315
|
+
const [px, py] = last ? last.predict(t.cx, t.cy).map(Math.round) : [0, 0];
|
|
316
|
+
const far = Math.hypot(px, py) >= 6;
|
|
317
|
+
const b = far ? tileSpectrum(f, this.w, this.h, t.x + px, t.y + py, this.win) : spec[k];
|
|
318
|
+
if (!a || !b)
|
|
319
|
+
return { cx: t.cx, cy: t.cy, dx: 0, dy: 0, peak: 0, clarity: 0, ok: false };
|
|
320
|
+
const c = correlate(a, b);
|
|
321
|
+
return { cx: t.cx, cy: t.cy, ...c, dx: c.dx + (far ? px : 0), dy: c.dy + (far ? py : 0), ok: c.peak >= 0.12 };
|
|
322
|
+
});
|
|
323
|
+
const fit = robustFit(tiles, this.R, this.lastFit);
|
|
324
|
+
this.lastFit = fit ? { predict: fit.predict } : undefined;
|
|
325
|
+
const still = tiles.map((t, k) => (t.ok && Math.hypot(t.dx, t.dy) < 0.2 ? meanAbs(det[k], p.detail[k]) : -1)).filter((x) => x >= 0).sort((a, b) => a - b);
|
|
326
|
+
this.steps.push({
|
|
327
|
+
i: this.n, tiles, ...(fit ? { cam: fit.cam } : {}), residual: fit ? fit.residual : tiles.map(() => undefined),
|
|
328
|
+
diff: meanAbs(small, p.small), matched: tiles.filter((t) => t.ok).length / Math.max(1, tiles.filter((t, k) => p.spec[k] && spec[k] && t).length),
|
|
329
|
+
...(still.length ? { shimmer: still[Math.floor(still.length / 2)] } : {}),
|
|
330
|
+
});
|
|
331
|
+
if (this.before)
|
|
332
|
+
this.skip.push(meanAbs(small, this.before));
|
|
333
|
+
}
|
|
334
|
+
this.before = this.prev?.small;
|
|
335
|
+
this.prev = { spec, small, detail: det };
|
|
336
|
+
this.n++;
|
|
337
|
+
}
|
|
338
|
+
result() {
|
|
339
|
+
return { w: this.w, h: this.h, scale: this.scale, tiles: this.tiles, steps: this.steps, luma: this.luma, skip: [...this.skip, 0], frames: this.n };
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** The camera's motion at a frame as one vector in output px: pan plus the zoom and turn seen at the frame's edge. */
|
|
343
|
+
function camVec(c, a) {
|
|
344
|
+
const edge = (Math.min(a.w, a.h) / 2) * a.scale;
|
|
345
|
+
return [c.tx * a.scale, c.ty * a.scale, c.zoom * edge, c.rot * edge];
|
|
346
|
+
}
|
|
347
|
+
/** Cuts the video shows on its own: most tiles lose their match and the picture changes a lot. */
|
|
348
|
+
export function detectCuts(a) {
|
|
349
|
+
return a.steps.filter((s) => s.matched < 0.3 && s.diff >= 8).map((s) => s.i);
|
|
350
|
+
}
|
|
351
|
+
export function findings(a, o) {
|
|
352
|
+
const out = [];
|
|
353
|
+
const fps = o.fps, T = THRESHOLDS;
|
|
354
|
+
const cuts = new Set([...(o.cuts ?? []), ...detectCuts(a)]);
|
|
355
|
+
const exempt = (i) => [...cuts].some((c) => i >= c - 1 && i <= c + 1) || (o.spans ?? []).some(([s, e]) => i >= s && i <= e);
|
|
356
|
+
const time = (i) => Number((i / fps).toFixed(3));
|
|
357
|
+
const v = a.steps.map((s) => (s.cam ? camVec(s.cam, a) : undefined));
|
|
358
|
+
const mag = (x) => (x ? Math.hypot(...x) : 0);
|
|
359
|
+
// Judder: content that holds for a frame in the middle of a steady move, again and again. Holds
|
|
360
|
+
// every other frame are an animation updating at half the frame rate; holds every few frames
|
|
361
|
+
// are motion snapping to whole pixels inside a scaled layer. Judged per tile, before the camera,
|
|
362
|
+
// because a fit across a picture half of which judders swings between the halves.
|
|
363
|
+
const judder = [];
|
|
364
|
+
const shift = (k, t) => { const m = a.steps[k]?.tiles[t]; return m && m.ok && m.clarity >= T.floatingClarity ? Math.hypot(m.dx, m.dy) : undefined; };
|
|
365
|
+
a.tiles.forEach((tile, t) => {
|
|
366
|
+
const holds = [];
|
|
367
|
+
let moved = 0;
|
|
368
|
+
for (let k = 1; k + 1 < a.steps.length; k++) {
|
|
369
|
+
const c = shift(k, t), p = shift(k - 1, t), n = shift(k + 1, t), i = a.steps[k].i;
|
|
370
|
+
if (c === undefined || p === undefined || n === undefined || exempt(i) || exempt(i - 1) || exempt(i + 1))
|
|
371
|
+
continue;
|
|
372
|
+
const near = [];
|
|
373
|
+
for (let j = k - 4; j <= k + 4; j++) {
|
|
374
|
+
const x = shift(j, t);
|
|
375
|
+
if (x !== undefined)
|
|
376
|
+
near.push(x);
|
|
377
|
+
}
|
|
378
|
+
if (near.length < 7)
|
|
379
|
+
continue;
|
|
380
|
+
const mean = near.reduce((x, y) => x + y, 0) / near.length;
|
|
381
|
+
if (mean * a.scale < T.judderMin || c >= 0.3 * mean || p < 0.6 * mean || n < 0.6 * mean)
|
|
382
|
+
continue;
|
|
383
|
+
holds.push(k);
|
|
384
|
+
moved = Math.max(moved, mean);
|
|
385
|
+
}
|
|
386
|
+
for (const run of runs(holds, Math.round(fps * 0.5))) {
|
|
387
|
+
if (run.length < T.judderBeats)
|
|
388
|
+
continue;
|
|
389
|
+
const i0 = a.steps[run[0]].i - 1, i1 = a.steps[run[run.length - 1]].i + 1;
|
|
390
|
+
const steps = run.map((k) => Math.max(shift(k - 1, t), shift(k + 1, t))).sort((x, y) => x - y);
|
|
391
|
+
const size = steps[Math.floor(steps.length / 2)] * a.scale;
|
|
392
|
+
const gaps = run.slice(1).map((k, j) => k - run[j]), half = gaps.filter((g) => g === 2).length >= 0.6 * gaps.length;
|
|
393
|
+
const same = judder.find(([s0, e0]) => i0 <= e0 + 2 && i1 >= s0 - 2);
|
|
394
|
+
if (same) {
|
|
395
|
+
same[0] = Math.min(same[0], i0);
|
|
396
|
+
same[1] = Math.max(same[1], i1);
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
judder.push([i0, i1]);
|
|
400
|
+
out.push({ kind: 'judder', frame: i0, t: time(i0), to: i1, size: r1(size), at: pct(a, tile), level: size >= T.judder ? 'fault' : 'note',
|
|
401
|
+
message: half
|
|
402
|
+
? `Part of the picture moves on one frame and holds on the next (steps of ${r1(size)} px): it updates at half the frame rate. Drive it from the frame clock.`
|
|
403
|
+
: `Part of the picture moves in uneven steps, holding a frame ${run.length} times (steps of ${r1(size)} px): motion snapping to whole pixels, usually inside a scaled-up layer. Give the moving element its own layer (will-change: transform), or lay the page out at the final size instead of scaling it up.` });
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
// The camera fit swings between a juddering part and a steady one, so camera wiggles and stalls
|
|
407
|
+
// near a judder are its echo, not a second fault.
|
|
408
|
+
const near = Math.round(fps * 0.15);
|
|
409
|
+
const juddering = (i) => judder.some(([s, e]) => i >= s - near && i <= e + near);
|
|
410
|
+
// Wiggle: a component of the camera's motion turns back while both steps are big.
|
|
411
|
+
// A move that reverses on purpose eases through zero, so its steps beside the turn are small.
|
|
412
|
+
const rev = [];
|
|
413
|
+
for (let k = 1; k < v.length; k++) {
|
|
414
|
+
const p = v[k - 1], c = v[k];
|
|
415
|
+
if (!p || !c || exempt(a.steps[k].i) || exempt(a.steps[k - 1].i) || juddering(a.steps[k].i))
|
|
416
|
+
continue;
|
|
417
|
+
for (let d = 0; d < 4; d++)
|
|
418
|
+
if (p[d] * c[d] < 0 && Math.abs(p[d]) >= T.wiggle && Math.abs(c[d]) >= T.wiggle) {
|
|
419
|
+
rev.push(k);
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
for (const run of runs(rev, Math.round(fps * 0.3))) {
|
|
424
|
+
const size = Math.max(...run.map((k) => Math.max(...v[k].map(Math.abs))));
|
|
425
|
+
out.push({ kind: 'wiggle', frame: a.steps[run[0]].i, t: time(a.steps[run[0]].i), to: a.steps[run[run.length - 1]].i, size: r1(size), level: 'fault',
|
|
426
|
+
message: `The camera turns back and forth ${run.length} time(s) (steps up to ${r1(size)} px).` });
|
|
427
|
+
}
|
|
428
|
+
// Jumps, impacts and stalls.
|
|
429
|
+
for (let k = 0; k < v.length; k++) {
|
|
430
|
+
const c = v[k], i = a.steps[k].i;
|
|
431
|
+
if (!c || exempt(i))
|
|
432
|
+
continue;
|
|
433
|
+
const m = mag(c);
|
|
434
|
+
// Judge a step only against measured neighbours: three before, three after.
|
|
435
|
+
const before = v.slice(Math.max(0, k - 4), k).filter(Boolean), after = v.slice(k + 1, k + 5).filter(Boolean);
|
|
436
|
+
if (before.length < 3 || after.length < 3 || !v[k + 1] || !v[k + 2] || !v[k + 3])
|
|
437
|
+
continue;
|
|
438
|
+
const nb = [...before, ...after].map(mag).sort((x, y) => x - y);
|
|
439
|
+
const med = nb.length ? nb[Math.floor(nb.length / 2)] : 0;
|
|
440
|
+
const prevMag = Math.max(mag(v[k - 1]), mag(v[k - 2]));
|
|
441
|
+
if (m >= T.jump && m >= 3 * Math.max(med, 0.5) && m >= 2 * prevMag) {
|
|
442
|
+
// Carried on: the next frames keep moving the same way, as a punch eases out. A jump moves once and stops.
|
|
443
|
+
const unit = c.map((x) => x / m);
|
|
444
|
+
const carried = v.slice(k + 1, k + 4).reduce((s, n) => s + (n ? Math.max(0, n.reduce((d, x, j) => d + x * unit[j], 0)) : 0), 0);
|
|
445
|
+
if (carried >= m)
|
|
446
|
+
out.push({ kind: 'impact', frame: i, t: time(i), to: i, size: r1(m), level: 'note', message: `A move starts at full speed (${r1(m)} px in one frame): a punch, if meant.` });
|
|
447
|
+
else
|
|
448
|
+
out.push({ kind: 'jump', frame: i, t: time(i), to: i, size: r1(m), level: 'fault', message: `The picture jumps ${r1(m)} px in one frame and stops.` });
|
|
449
|
+
}
|
|
450
|
+
// Hitch: a steady move that skips ahead one frame (a dropped frame, or a clock that ticked twice).
|
|
451
|
+
else if (!juddering(i)) {
|
|
452
|
+
const near = [v[k - 2], v[k - 1], v[k + 1], v[k + 2]];
|
|
453
|
+
if (near.every(Boolean) && ![i - 2, i - 1, i + 1, i + 2].some(exempt)) {
|
|
454
|
+
const ms = near.map(mag), lo = Math.min(...ms), hi = Math.max(...ms), mean = ms.reduce((x, y) => x + y, 0) / 4;
|
|
455
|
+
const along = near.reduce((d, x) => d + x.reduce((e, y, j) => e + y * c[j], 0), 0) / 4 / Math.max(m, 1e-9);
|
|
456
|
+
if (mean >= 0.5 && hi <= 1.5 * lo && m >= 1.7 * mean && m - mean >= 0.8 && along >= 0.8 * mean)
|
|
457
|
+
out.push({ kind: 'hitch', frame: i, t: time(i), to: i, size: r1(m - mean), level: 'fault',
|
|
458
|
+
message: `A steady move of ${r1(mean)} px a frame skips ahead ${r1(m - mean)} px in one frame: a dropped frame, or a clock that ticked twice.` });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const p = v[k - 1], n = v[k + 1];
|
|
462
|
+
if (p && n && !exempt(i - 1) && !exempt(i + 1) && !juddering(i)) {
|
|
463
|
+
const lo = Math.min(mag(p), mag(n));
|
|
464
|
+
if (lo >= 2 && m < 0.25 * lo)
|
|
465
|
+
out.push({ kind: 'stall', frame: i, t: time(i), to: i, size: r1(lo), level: 'fault', message: `The camera stops for one frame in the middle of a move (${r1(lo)} px steps either side): a repeated frame.` });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// Strobe: a pan too fast to read as motion, or too fast to measure at all.
|
|
469
|
+
const limit = T.strobe * REFERENCE_SHORT;
|
|
470
|
+
const fast = a.steps.map((s, k) => {
|
|
471
|
+
if (exempt(s.i))
|
|
472
|
+
return -1;
|
|
473
|
+
if (v[k])
|
|
474
|
+
return Math.hypot(v[k][0], v[k][1]) > limit ? k : -1;
|
|
475
|
+
// Unmeasured between two fast frames: faster than the tiles can follow.
|
|
476
|
+
const p = v[k - 1], n = v[k + 1];
|
|
477
|
+
return p && n && Math.hypot(p[0], p[1]) > limit && Math.hypot(n[0], n[1]) > limit ? k : -1;
|
|
478
|
+
}).filter((k) => k >= 0);
|
|
479
|
+
for (const run of runs(fast, 2)) {
|
|
480
|
+
const sp = Math.max(...run.map((k) => (v[k] ? Math.hypot(v[k][0], v[k][1]) : 0)));
|
|
481
|
+
const i0 = a.steps[run[0]].i, i1 = a.steps[run[run.length - 1]].i;
|
|
482
|
+
out.push({ kind: 'strobe', frame: i0, t: time(i0), to: i1, size: r1(sp), level: 'note',
|
|
483
|
+
message: `The picture pans ${sp ? `${r1(sp)} px` : 'too fast to measure'} a frame, over the ${Math.round(limit)} px that reads as motion: it strobes. Slow it, or blur it along the move.` });
|
|
484
|
+
}
|
|
485
|
+
// Floating: one tile shaking against the camera fit.
|
|
486
|
+
const thr = T.floating / a.scale, max = T.floatingMax / a.scale, win = Math.round(fps * 0.5);
|
|
487
|
+
const firm = (k, t) => { const s = a.steps[k], r = s.residual[t]; const m = s.tiles[t]; return r && m.peak >= T.floatingPeak && m.clarity >= T.floatingClarity && Math.hypot(...r) <= max ? r : undefined; };
|
|
488
|
+
a.tiles.forEach((tile, t) => {
|
|
489
|
+
const flips = [];
|
|
490
|
+
for (let k = 1; k < a.steps.length; k++) {
|
|
491
|
+
const p = firm(k - 1, t), c = firm(k, t), i = a.steps[k].i;
|
|
492
|
+
if (!p || !c || exempt(i) || exempt(i - 1))
|
|
493
|
+
continue;
|
|
494
|
+
for (let d = 0; d < 2; d++)
|
|
495
|
+
if (p[d] * c[d] < 0 && Math.abs(p[d]) >= thr && Math.abs(c[d]) >= thr) {
|
|
496
|
+
flips.push(k);
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
for (const run of runs(flips, win)) {
|
|
501
|
+
if (run.length < T.floatingReversals)
|
|
502
|
+
continue;
|
|
503
|
+
const size = Math.max(...run.map((k) => Math.max(...a.steps[k].residual[t].map(Math.abs)))) * a.scale;
|
|
504
|
+
const i0 = a.steps[run[0]].i, i1 = a.steps[run[run.length - 1]].i;
|
|
505
|
+
out.push({ kind: 'floating', frame: i0, t: time(i0), to: i1, size: r1(size), at: pct(a, tile), level: 'fault',
|
|
506
|
+
message: `Part of the picture shakes against the rest: ${run.length} reversals of up to ${r1(size)} px.` });
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
// Blips: a frame unlike both neighbours, while they are like each other. Several close together
|
|
510
|
+
// are one finding: the picture flipping between two states.
|
|
511
|
+
const blips = [];
|
|
512
|
+
for (let k = 0; k + 1 < a.steps.length; k++) {
|
|
513
|
+
const i = a.steps[k].i, dPrev = a.steps[k].diff, dNext = a.steps[k + 1].diff, across = a.skip[i] ?? 0;
|
|
514
|
+
const lo = Math.min(dPrev, dNext);
|
|
515
|
+
// A camera that goes there and back explains such a frame: that is a wiggle, reported above.
|
|
516
|
+
const moved = v[k] && v[k + 1] && mag(v[k]) >= T.wiggle && mag(v[k + 1]) >= T.wiggle;
|
|
517
|
+
if (lo >= T.blip && across < T.blipShare * lo && !moved)
|
|
518
|
+
blips.push({ i, lo });
|
|
519
|
+
}
|
|
520
|
+
for (const run of runs(blips.map((b) => b.i), Math.round(fps * 0.3))) {
|
|
521
|
+
const lo = Math.max(...blips.filter((b) => run.includes(b.i)).map((b) => b.lo)), i0 = run[0], i1 = run[run.length - 1];
|
|
522
|
+
out.push({ kind: 'blip', frame: i0, t: time(i0), to: i1, size: r1(lo), level: 'fault',
|
|
523
|
+
message: run.length === 1
|
|
524
|
+
? `One frame differs from both its neighbours by ${r1(lo)} levels while they agree: a blank, late or stray frame.`
|
|
525
|
+
: `${run.length} frames each differ from both neighbours (up to ${r1(lo)} levels) while the neighbours agree: the picture flips between two states.` });
|
|
526
|
+
}
|
|
527
|
+
// Flicker: a tile's brightness flipping up and down, frame after frame.
|
|
528
|
+
a.tiles.forEach((tile, t) => {
|
|
529
|
+
let flips = 0, start = -1;
|
|
530
|
+
for (let i = 2; i < a.luma.length; i++) {
|
|
531
|
+
const d1 = a.luma[i - 1][t] - a.luma[i - 2][t], d2 = a.luma[i][t] - a.luma[i - 1][t];
|
|
532
|
+
const flip = d1 * d2 < 0 && Math.abs(d1) >= T.flicker && Math.abs(d2) >= T.flicker && !exempt(i) && !exempt(i - 1);
|
|
533
|
+
if (flip) {
|
|
534
|
+
if (!flips)
|
|
535
|
+
start = i - 2;
|
|
536
|
+
flips++;
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
if (flips >= T.flickerFlips)
|
|
540
|
+
out.push({ kind: 'flicker', frame: start, t: time(start), to: i - 1, size: T.flicker, at: pct(a, tile), level: 'note', message: `Brightness flips up and down ${flips} frames running.` });
|
|
541
|
+
flips = 0;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
// Shimmer: fine detail crawling where the picture holds still, for at least a quarter second.
|
|
546
|
+
const sh = a.steps.map((s) => (s.shimmer !== undefined && !exempt(s.i) ? s.shimmer : 0));
|
|
547
|
+
const hot = sh.map((x, k) => (x >= T.shimmer ? k : -1)).filter((k) => k >= 0);
|
|
548
|
+
for (const run of runs(hot, 2)) {
|
|
549
|
+
if (run.length < fps / 4)
|
|
550
|
+
continue;
|
|
551
|
+
const size = Math.max(...run.map((k) => sh[k]));
|
|
552
|
+
out.push({ kind: 'shimmer', frame: a.steps[run[0]].i, t: time(a.steps[run[0]].i), to: a.steps[run[run.length - 1]].i, size: r1(size), level: 'note', message: `Fine detail changes by ${r1(size)} levels a frame while the picture holds still: compression noise or aliasing.` });
|
|
553
|
+
}
|
|
554
|
+
return out.sort((x, y) => x.frame - y.frame);
|
|
555
|
+
}
|
|
556
|
+
/** Summary numbers for the report: how still the still parts are. */
|
|
557
|
+
export function shimmerLevel(a) {
|
|
558
|
+
const s = a.steps.map((x) => x.shimmer).filter((x) => x !== undefined).sort((x, y) => x - y);
|
|
559
|
+
if (!s.length)
|
|
560
|
+
return { median: 0, p95: 0 };
|
|
561
|
+
return { median: r2(s[Math.floor(s.length / 2)]), p95: r2(s[Math.floor(s.length * 0.95)]) };
|
|
562
|
+
}
|
|
563
|
+
/** Groups sorted indices into runs where neighbours are at most `gap` apart. */
|
|
564
|
+
export function runs(xs, gap) {
|
|
565
|
+
const out = [];
|
|
566
|
+
for (const x of xs) {
|
|
567
|
+
const last = out[out.length - 1];
|
|
568
|
+
if (last && x - last[last.length - 1] <= gap)
|
|
569
|
+
last.push(x);
|
|
570
|
+
else
|
|
571
|
+
out.push([x]);
|
|
572
|
+
}
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
const r1 = (x) => Math.round(x * 10) / 10;
|
|
576
|
+
const r2 = (x) => Math.round(x * 100) / 100;
|
|
577
|
+
const pct = (a, t) => [Math.round(((t.x + TILE / 2) / a.w) * 100), Math.round(((t.y + TILE / 2) / a.h) * 100)];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { EaseSpec } from './core/ease.ts';
|
|
2
|
+
export interface Tokens {
|
|
3
|
+
fps: number;
|
|
4
|
+
beat: number;
|
|
5
|
+
hold: number;
|
|
6
|
+
hold_end: number;
|
|
7
|
+
duration: {
|
|
8
|
+
instant: number;
|
|
9
|
+
fast: number;
|
|
10
|
+
base: number;
|
|
11
|
+
slow: number;
|
|
12
|
+
};
|
|
13
|
+
stagger: {
|
|
14
|
+
tight: number;
|
|
15
|
+
base: number;
|
|
16
|
+
loose: number;
|
|
17
|
+
};
|
|
18
|
+
ease_enter: EaseSpec;
|
|
19
|
+
ease_exit: EaseSpec;
|
|
20
|
+
ease_move: EaseSpec;
|
|
21
|
+
ease_loop: EaseSpec;
|
|
22
|
+
/**
|
|
23
|
+
* How far transitions travel, lean and blur. `calm` swaps every transition's
|
|
24
|
+
* defaults for its quiet preset (a camera that barely pulls back, no tumble);
|
|
25
|
+
* values a film sets itself still win.
|
|
26
|
+
*/
|
|
27
|
+
transitions: 'standard' | 'calm';
|
|
28
|
+
/** bydiorama/ui interface timings in seconds. Replaced by the theme on a page that loads one. */
|
|
29
|
+
ui: {
|
|
30
|
+
duration: {
|
|
31
|
+
fast: number;
|
|
32
|
+
base: number;
|
|
33
|
+
slow: number;
|
|
34
|
+
enter: number;
|
|
35
|
+
};
|
|
36
|
+
stagger: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type TokenOverrides = {
|
|
40
|
+
[K in keyof Tokens]?: Tokens[K] extends object ? Partial<Tokens[K]> : Tokens[K];
|
|
41
|
+
};
|
|
42
|
+
export declare const DEFAULT_TOKENS: Tokens;
|
|
43
|
+
/** Deep merge of plain objects. Arrays and scalars are replaced. */
|
|
44
|
+
export declare function merge<T>(base: T, over: unknown): T;
|
|
45
|
+
export declare const mergeTokens: (...layers: (TokenOverrides | undefined)[]) => Tokens;
|
|
46
|
+
/** Every token path a film may reference as `$path`, e.g. `$duration.base`. */
|
|
47
|
+
export declare function tokenPaths(tokens: Tokens): string[];
|
|
48
|
+
/** Reads `$duration.base` style references. Returns undefined when the path is unknown. */
|
|
49
|
+
export declare function readToken(tokens: Tokens, ref: string): unknown;
|
|
50
|
+
export declare const isTokenRef: (v: unknown) => v is string;
|