Spaces:
Running
Running
Lucas Jackson commited on
Update from github.com/lucasjacks0n/LeanScene@f3f307c
Browse filesFiles changed (9)
- .gitattributes+1
- README.md+15-4
- demo.cssAdded+200
- engine.jsAdded+671
- index.html+96-17
- logo-dark.svgAdded
- logo.svgAdded
- model.jsAdded
- sample.mp4Added+3
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textsample.mp4 filter=lfs diff=lfs merge=lfs -text
12345678910---title: LeanSceneemoji: 📊colorFrom: redcolorTo: redsdk: staticpinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021---title: LeanSceneemoji: 🎬colorFrom: greencolorTo: graysdk: staticpinned: falselicense: mitshort_description: Find every cut in a video, right in your browser tab---The LeanScene browser demo: drop a video, and every shot transition (cut, dissolve, fade) isfound and shown on a timeline, with a card for each one. Everything runs in the tab and thevideo is never uploaded.- Model: [LeanScene](https://huggingface.co/lucaspy/LeanScene), a 0.39M-parameter shot transition detector.- Code: <https://github.com/lucasjacks0n/LeanScene>.- The full demo, which also lets you search the shots by describing them: <https://lucasjackson.dev/leanscene/>.The example clip is 50 seconds of *Big Buck Bunny*, © Blender Foundation, bigbuckbunny.org,CC BY 3.0. It is not covered by the MIT license.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 :root { --bg:#f6f5f1; --panel:#fff; --ink:#1c1b19; --mute:#6b675f; --line:#dcd8cf; --cut:#2f9e44; --fade:#1971c2; --accent:#1c1b19; } @media (prefers-color-scheme: dark) { :root { --bg:#151514; --panel:#1f1f1d; --ink:#ecebe6; --mute:#9a968c; --line:#34332f; --cut:#2f9e44; --fade:#4dabf7; --accent:#ecebe6; } } * { box-sizing: border-box; } body { margin:0; background:var(--bg); color:var(--ink); font:15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; } main { max-width:1100px; margin:0 auto; padding:28px 16px 60px; } h1 { font-size:22px; margin:0 0 4px; letter-spacing:-0.01em; } h1.logo { display:flex; align-items:baseline; gap:14px; flex-wrap:wrap; margin:0 0 10px; } h1.logo svg { height:52px; width:auto; display:block; margin-left:-6px; } /* the text sits on the image's bottom edge; the lettering's baseline is 21/92 of the image's height above that, so the text is lifted by the same amount to share the lettering's baseline */ h1.logo span { font-size:15px; font-weight:500; color:var(--mute); letter-spacing:0; position:relative; top:-11.9px; } h1.logo .d { display:none; } @media (prefers-color-scheme: dark) { h1.logo .l { display:none; } h1.logo .d { display:block; } } h2 { font-size:15px; margin:26px 0 10px; } p { margin:0; } .mute { color:var(--mute); } #status { font-size:13px; } #status.err, #error { color:var(--cut); } #drop { display:block; margin:18px 0 0; padding:34px 16px; text-align:center; border:2px dashed var(--line); border-radius:12px; background:var(--panel); cursor:pointer; transition:border-color .15s; } #drop.over { border-color:var(--accent); } #drop.busy { opacity:.5; pointer-events:none; } #drop strong { display:block; font-size:17px; margin-bottom:4px; } #progress { margin-top:16px; display:flex; gap:14px; align-items:center; background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:12px; } #progress canvas { width:72px; height:72px; border-radius:6px; background:#000; flex:none; } #progress > div { flex:1; min-width:0; } progress { width:100%; height:10px; accent-color:var(--accent); } #summary { display:flex; flex-wrap:wrap; gap:8px 26px; margin:18px 0 14px; } #summary div { font-size:13px; color:var(--mute); } #summary b { display:block; font-size:20px; color:var(--ink); font-variant-numeric:tabular-nums; } video { width:100%; max-height:460px; background:#000; border-radius:10px; display:block; } #strip { display:flex; margin-top:14px; border-radius:6px 6px 0 0; overflow:hidden; background:#000; } #strip img { flex:1; min-width:0; width:0; aspect-ratio:16/9; object-fit:cover; display:block; font-size:0; } #ovwrap { position:relative; background:var(--panel); border:1px solid var(--line); border-top:0; cursor:pointer; touch-action:none; } #overview { display:block; width:100%; height:26px; } #ovbox { position:absolute; top:0; bottom:0; min-width:6px; box-sizing:border-box; border:2px solid var(--accent); border-radius:3px; pointer-events:none; } #ovhead { position:absolute; top:0; bottom:0; width:1px; background:var(--accent); opacity:.6; pointer-events:none; } #tlwrap { position:relative; background:var(--panel); border:1px solid var(--line); border-top:0; border-radius:0 0 6px 6px; cursor:crosshair; overflow:hidden; touch-action:pan-y; user-select:none; -webkit-user-select:none; } #tlwrap.drag { cursor:grabbing; } #timeline { display:block; width:100%; height:146px; } #playhead { position:absolute; top:0; bottom:0; width:2px; background:var(--accent); pointer-events:none; left:0; } #tip { position:absolute; top:4px; padding:2px 6px; font-size:12px; background:var(--accent); color:var(--bg); border-radius:4px; pointer-events:none; white-space:nowrap; transform:translateX(-50%); } .legend { display:flex; flex-wrap:wrap; gap:6px 18px; font-size:12px; color:var(--mute); margin-top:6px; } .zoom { margin-left:auto; display:flex; gap:6px; align-items:center; font-variant-numeric:tabular-nums; } .zoom button { padding:1px 9px; } #zoominfo { margin-left:8px; } .zoom button:disabled { opacity:.4; cursor:default; } .legend i { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:5px; vertical-align:-1px; } #cards { display:grid; grid-template-columns:repeat(auto-fill, minmax(250px, 1fr)); gap:12px; } .card { background:var(--panel); border:1px solid var(--line); border-radius:10px; overflow:hidden; cursor:pointer; padding:0; text-align:left; color:inherit; font:inherit; } .pager { display:flex; align-items:center; justify-content:center; gap:12px; margin:14px 0 4px; font-size:13px; color:var(--mute); font-variant-numeric:tabular-nums; } .pager.top { justify-content:flex-end; margin:-2px 0 10px; } .pager[hidden] { display:none; } .pager button:disabled { opacity:.4; cursor:default; } .card:hover, .card:focus-visible, .card.on { border-color:var(--accent); outline:none; } .card.on { box-shadow:0 0 0 1px var(--accent); } .pair { display:flex; gap:2px; background:#000; } .pair img { width:50%; aspect-ratio:16/9; object-fit:cover; display:block; background:#111; font-size:0; } .cap { padding:7px 10px 9px; font-size:13px; display:flex; justify-content:space-between; gap:8px; font-variant-numeric:tabular-nums; } .tag { font-weight:600; } .tag.cut { color:var(--cut); } .tag.gradual { color:var(--fade); } button.plain { font:inherit; font-size:13px; padding:5px 12px; border-radius:7px; border:1px solid var(--line); background:var(--panel); color:var(--ink); cursor:pointer; } .row { display:flex; justify-content:space-between; align-items:baseline; gap:12px; flex-wrap:wrap; } .pair img.loading, #strip img.loading { background:linear-gradient(100deg, var(--line) 30%, var(--panel) 50%, var(--line) 70%) 0 0 / 200% 100%; animation:shimmer 1.2s linear infinite; } @keyframes shimmer { to { background-position:-200% 0; } } @media (prefers-reduced-motion: reduce) { .pair img.loading, #strip img.loading { animation:none; } } #about { margin-top:34px; } .facts { display:grid; grid-template-columns:repeat(auto-fit, minmax(210px, 1fr)); gap:12px; } .facts div { background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:14px 16px; font-size:13px; color:var(--mute); } .facts b { display:block; font-size:24px; color:var(--ink); letter-spacing:-0.01em; margin-bottom:2px; } .cols { display:grid; grid-template-columns:repeat(auto-fit, minmax(270px, 1fr)); gap:8px 36px; margin-top:8px; } .cols p, .cols ol { margin:0 0 10px; font-size:14px; } .cols ol { padding-left:20px; } .cols li { margin-bottom:4px; } .cols a { color:var(--ink); } .cols pre { margin:0 0 10px; padding:10px 12px; background:var(--panel); border:1px solid var(--line); border-radius:8px; font:13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x:auto; } [hidden] { display:none !important; }
:root { --ls:#2f9e44; --tn:#a8a39a; --grid:#ebe8e1; } @media (prefers-color-scheme: dark) { :root { --tn:#6b675f; --grid:#2a2927; } } .cols pre { white-space:pre-wrap; word-break:break-all; } .lbl { font-size:12px !important; color:var(--mute); margin:0 0 4px !important; text-transform:uppercase; letter-spacing:.06em; } .key { display:flex; gap:16px; font-size:12px; color:var(--mute); margin:6px 0 0; } .key i { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:6px; vertical-align:-1px; } .intro { font-size:16px; max-width:720px; margin:2px 0 8px; } .intro b { font-weight:600; } .headline { font-size:20px; line-height:1.3; letter-spacing:-0.01em; margin:0 0 18px; max-width:760px; } .headline em { font-style:normal; color:var(--ls); } .chartbox { background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:16px 18px; } .chartbox h3 { font-size:13px; margin:0 0 2px; } .chartbox .sub { font-size:12px; color:var(--mute); margin:0 0 12px; } [data-tip] { cursor:default; }
.db-row { display:grid; grid-template-columns:120px 1fr; align-items:center; gap:12px; height:34px; } .db-name { font-size:13px; } .db-track { position:relative; height:100%; margin-right:78px; background:linear-gradient(var(--grid),var(--grid)) 0 50%/100% 1px no-repeat; } .db-line { position:absolute; top:50%; height:2px; margin-top:-1px; background:var(--ls); opacity:.5; } .db-dot { position:absolute; top:50%; width:11px; height:11px; margin:-5.5px 0 0 -5.5px; border-radius:50%; box-shadow:0 0 0 2px var(--panel); } .db-dot.ls { background:var(--ls); } .db-dot.tn { background:var(--tn); } .db-val { position:absolute; top:50%; transform:translate(10px,-50%); font-size:12px; white-space:nowrap; font-variant-numeric:tabular-nums; } .db-val b { color:var(--ls); font-weight:600; } .db-axis { position:relative; height:16px; margin-right:78px; font-size:11px; color:var(--mute); } .db-axis span { position:absolute; transform:translateX(-50%); font-variant-numeric:tabular-nums; }
.br-row { display:grid; grid-template-columns:96px 1fr; align-items:center; gap:12px; height:28px; } .br-name { font-size:13px; } .br-track { display:flex; min-width:0; align-items:center; gap:8px; } .br-bar { height:12px; border-radius:0 4px 4px 0; flex:none; } .br-bar.ls { background:var(--ls); } .br-bar.tn { background:var(--tn); } .br-val { font-size:12px; color:var(--mute); white-space:nowrap; font-variant-numeric:tabular-nums; } .br-group + .br-group { margin-top:12px; }
.charts { display:grid; grid-template-columns:3fr 2fr; gap:12px; margin-bottom:8px; } @media (max-width:760px) { .charts { grid-template-columns:1fr; } } @media (max-width:480px) { .db-row { grid-template-columns:78px 1fr; } .db-name { font-size:12px; } .chartbox { padding:14px 12px; } }
:root { --sx:#1971c2; } @media (prefers-color-scheme: dark) { :root { --sx:#4dabf7; } } .badge { font-style:normal; background:var(--sx); color:#fff; padding:3px 9px; border-radius:6px; font-size:13px; font-weight:600; margin-right:4px; } .intro { margin-bottom:4px; } [data-stage], .de { transition:border-color .2s, background .2s, box-shadow .2s; }
.why { margin-top:18px; padding-top:14px; border-top:1px solid var(--dline); font-size:14px; color:var(--dmute); line-height:1.5; } .why b { color:var(--dink); } .why em { font-style:normal; color:var(--sx); font-weight:600; } .pipe { border-radius:16px; padding:24px 26px 26px; margin:18px 0; } .pipe.dark { background:#151514; color:#ecebe6; } .pipe.light { background:var(--panel); border:1px solid var(--line); box-shadow:0 1px 0 var(--line); } .pk { margin:0; font-size:11px; letter-spacing:.09em; text-transform:uppercase; color:var(--sx); font-weight:700; } .ph { margin:6px 0 2px; font-size:24px; letter-spacing:-.015em; color:var(--dink); } .ps { margin:0 0 20px; font-size:14px; color:var(--dmute); }
#faq { margin-top:38px; max-width:760px; } #faq h2 { margin:0 0 6px; } #faq details { border-bottom:1px solid var(--line); } #faq summary { cursor:pointer; padding:13px 28px 13px 0; font-size:15px; font-weight:600; list-style:none; position:relative; } #faq summary::-webkit-details-marker { display:none; } #faq summary::after { content:"+"; position:absolute; right:4px; top:50%; transform:translateY(-50%); font-size:20px; font-weight:400; color:var(--mute); } #faq details[open] summary::after { content:"−"; } #faq details p { margin:0 0 14px; font-size:14px; color:var(--mute); max-width:660px; } #faq a { color:var(--ink); } #faq code { font:12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background:var(--panel); border:1px solid var(--line); border-radius:5px; padding:1px 5px; } .try { font-size:22px; letter-spacing:-.015em; margin:30px 0 4px; } .try + #status { margin-bottom:10px; }
@property --ang { syntax:'<angle>'; initial-value:0deg; inherits:false; } .pipe { position:relative; overflow:hidden; } .pipe > * { position:relative; } [data-stage="video"] { --c:#f59f00; } [data-stage="leanscene"] { --c:#2f9e44; } [data-stage="clip"] { --c:#9c5cff; } [data-stage="search"] { --c:#339af0; } .e1 { --c1:#f59f00; --c2:#2f9e44; } .e2 { --c1:#2f9e44; --c2:#9c5cff; } .e3 { --c1:#9c5cff; --c2:#339af0; } .vg { display:grid; grid-template-columns:1fr var(--cw, 100px) 1fr var(--cw, 100px) 1fr var(--cw, 100px) 1fr; align-items:center; } .dn b { display:block; font-size:15px; color:var(--dink); } .dn span { display:block; font-size:12px; color:var(--dmute); line-height:1.35; } .di { flex:none; display:grid; place-items:center; } .di svg { width:24px; height:24px; } .tint .di svg [stroke="#2f9e44"] { stroke:#fff; } .tint .di svg [fill="#2f9e44"] { fill:#fff; } .de { position:relative; height:48px; } .dl { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); white-space:nowrap; font-size:11px; padding:2px 8px; border-radius:999px; font-variant-numeric:tabular-nums; z-index:2; color:var(--dmute); background:var(--dbg); border:1px solid var(--dline); transition:border-color .2s; } .dl b { color:var(--dink); font-weight:600; } .de.live .dl { border-color:var(--c2); } .stack .de { height:auto; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:7px; padding:0 8px; } .stack .dl { position:static; transform:none; } @keyframes flow { to { -webkit-mask-position:16px 0; mask-position:16px 0; } } @keyframes pulse { 50% { box-shadow:0 0 0 7px color-mix(in srgb, var(--c) 28%, transparent); } } .v1, .v4 { --cw:104px; } .v1 .dn, .v4 .dn { padding:14px 12px; gap:10px; } .v1 .dl, .v4 .dl { top:-2px; transform:translateX(-50%); } .v3 .dl { top:4px; transform:translateX(-50%); } @media (max-width:820px) { .vg { grid-template-columns:1fr; } .de { height:38px; } .de > .trk, .de > i { display:none; } .dl::before { content:"↓ "; } .v1 .dl, .v3 .dl, .v4 .dl { top:50%; transform:translate(-50%,-50%); } .stack .de { padding:8px 0; } } @media (prefers-reduced-motion: reduce) { .pipe, .pipe *, .pipe::before, .pipe::after, .pipe *::before, .pipe *::after { animation:none !important; } }
.v2 { background:radial-gradient(120% 140% at 0% 0%, #1b1530 0%, #0e0e14 55%), #0e0e14; --cw:92px; } .v2 .dn { border-radius:16px; background:rgba(255,255,255,.05); border:1.5px solid rgba(255,255,255,.1); padding:12px; transition:border-color .2s; } .v2 .vg { grid-template-columns:minmax(0,1fr) var(--cw) minmax(0,1.12fr) var(--cw) minmax(0,1fr) var(--cw) minmax(0,1fr); } .v2 .dn { min-width:0; } .find .box { min-width:0; } .find .typed { min-width:0; overflow:hidden; white-space:nowrap; } .v2 .di { display:none; } .v2 .dt { margin-top:10px; } .v2 .dt b::before { content:""; display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--c); margin-right:7px; vertical-align:1px; box-shadow:0 0 10px var(--c); } .v2 .dn.on { border-color:var(--c); animation:pulse 1.1s ease-in-out infinite; } .v2 .dn.done { border-color:var(--c); } .sc { height:66px; border-radius:10px; background:#08080c; overflow:hidden; position:relative; } .film .reel { position:absolute; top:6px; bottom:6px; left:-20px; right:-20px; background:linear-gradient(90deg, #c9b79c, #5d7280, #d8c3a5, #3e4a3d, #a26b4d, #e3d5c3, #2f3640, #b9a48b, #6f8a72, #d4a373, #c9b79c) 0 0 / 420px 100% repeat-x; filter:blur(5px) saturate(1.15); animation:reel 8s linear infinite; } .film::before, .film::after { content:""; position:absolute; left:0; right:0; height:5px; background:repeating-linear-gradient(90deg, #2a2a33 0 6px, transparent 6px 12px); z-index:1; } .film::before { top:2px; } .film::after { bottom:2px; } @keyframes reel { from { background-position:0 0; } to { background-position:420px 0; } } .film::before, .film::after { background-color:#08080c; } .v2 .dn[data-stage="leanscene"] { border:2px solid #2f9e44; background:linear-gradient(160deg, rgba(47,158,68,.26), rgba(47,158,68,.07)); box-shadow:0 0 0 5px rgba(47,158,68,.14), 0 14px 44px -10px rgba(47,158,68,.75); transform:scale(1.07); z-index:1; } .v2 .dn[data-stage="leanscene"]::after { content:"This project"; position:absolute; top:-11px; left:50%; transform:translateX(-50%); background:#2f9e44; color:#fff; font-size:10.5px; font-weight:700; letter-spacing:.07em; text-transform:uppercase; padding:3px 10px; border-radius:999px; white-space:nowrap; box-shadow:0 4px 14px -2px rgba(47,158,68,.8); } .v2 .dn[data-stage="leanscene"] .dt b { font-size:17px; } .v2 .dn[data-stage="leanscene"] .dt span { color:#cfe9d5; } .v2 .vg { padding-top:8px; } .v2 .dn { position:relative; } @media (max-width:820px) { .v2 .dn[data-stage="leanscene"] { transform:none; } } .cuts { display:flex; align-items:center; padding:12px 8px; } .cuts .blk { height:100%; border-radius:4px; } .cuts .mk { flex:none; width:3px; margin:0 3px; height:130%; background:#2f9e44; border-radius:2px; transform-origin:top; animation:chop 3.2s ease-in-out infinite; box-shadow:0 0 10px #2f9e44; } @keyframes chop { 0%, 8% { transform:scaleY(0); opacity:0; } 22%, 86% { transform:scaleY(1); opacity:1; } 100% { transform:scaleY(1); opacity:0; } } .eq { display:flex; align-items:flex-end; gap:3px; padding:10px 10px 8px; } .eq i { flex:1; height:100%; border-radius:2px; background:linear-gradient(#c9a7ff, #7c3aed); transform-origin:bottom; animation:eq 1.3s ease-in-out infinite alternate; } @keyframes eq { from { transform:scaleY(.18); } to { transform:scaleY(1); } } .find { padding:8px; } .find .box { height:26px; border:1.5px solid #339af0; border-radius:7px; display:flex; align-items:center; padding:0 8px; font-size:12px; color:#f4f3ef; white-space:nowrap; overflow:hidden; } .find u { width:1.5px; height:13px; background:#f4f3ef; margin-left:1px; animation:blink 1s steps(1) infinite; } @keyframes blink { 50% { opacity:0; } } .find .hits { display:flex; gap:4px; margin-top:6px; height:18px; } .find .hits i { flex:1; border-radius:4px; background:#1d2733; animation:hit 2.4s ease-in-out infinite; } .find .hits i:nth-child(2) { animation-delay:.25s; } .find .hits i:nth-child(3) { animation-delay:.5s; } @keyframes hit { 0%, 55%, 100% { background:#1d2733; } 20%, 35% { background:#339af0; } } .chev { display:flex; gap:2px; } .chev i { width:9px; height:9px; border-top:2.5px solid var(--c2); border-right:2.5px solid var(--c2); transform:rotate(45deg); animation:chev 1.2s ease-in-out infinite; opacity:.2; } .chev i:nth-child(2) { animation-delay:.18s; } .chev i:nth-child(3) { animation-delay:.36s; } @keyframes chev { 40% { opacity:1; } 80%, 100% { opacity:.2; } } @media (max-width:820px) { .v2 .chev { transform:rotate(90deg); } .v2 .de { padding:14px 0; } .v2 .vg { grid-template-columns:minmax(0,1fr); } }
#status:not(.err) { display:none; } .rdy { display:flex; flex-wrap:wrap; gap:8px; margin:6px 0 2px; } .chip { position:relative; overflow:hidden; display:inline-flex; align-items:center; gap:7px; padding:5px 12px 6px 10px; border:1px solid var(--line); border-radius:999px; background:var(--panel); font-size:13px; color:var(--mute); font-variant-numeric:tabular-nums; } .chip b { color:var(--ink); font-weight:600; } .chip i { width:8px; height:8px; border-radius:50%; background:var(--line); flex:none; } .chip.busy i { background:#f59f00; animation:chipblink 1s ease-in-out infinite; } .chip.ok i { background:#2f9e44; } .chip.bad i { background:#e03131; } .chip u { position:absolute; left:0; bottom:0; height:3px; width:0; background:var(--sx); transition:width .2s; text-decoration:none; } @keyframes chipblink { 50% { opacity:.3; } } .sample { display:flex; flex-wrap:wrap; align-items:center; gap:8px 12px; margin:10px 0 0; font-size:13px; } .sample a { color:inherit; } body.has-result .sample { display:none; } /* once a video has been processed, the sample offer has done its job */ .lead { font-size:38px; line-height:1.1; letter-spacing:-.03em; margin:16px 0 8px; } .leadtag { font-size:21px; font-weight:700; letter-spacing:-.01em; color:var(--sx); margin:0 0 10px; } .leadsub { font-size:17px; color:var(--mute); max-width:700px; margin:0; line-height:1.5; } .leadsub a { color:inherit; } @media (max-width:600px) { .lead { font-size:28px; } } .top { display:flex; align-items:center; justify-content:space-between; gap:12px; margin:0 0 10px; } .top h1.logo { margin:0; } .gh { display:inline-flex; align-items:center; gap:7px; flex:none; padding:6px 12px; border:1px solid var(--line); border-radius:8px; background:var(--panel); color:var(--ink); text-decoration:none; font-size:13px; font-weight:600; } .gh:hover { border-color:var(--accent); } .ghstars { padding-left:8px; border-left:1px solid var(--line); font-weight:400; color:var(--mute); font-variant-numeric:tabular-nums; } .ghstars b { color:var(--ink); font-weight:600; } .ghstars[hidden] { display:none; } @media (max-width:520px) { .gh > span:first-of-type { display:none; } } #sample { font-weight:600; border-color:var(--sx); color:var(--sx); } #sample:disabled { opacity:.5; cursor:default; } #tryq { display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin:8px 0 0; font-size:13px; color:var(--mute); } #tryq button { font:inherit; font-size:13px; padding:3px 11px; border-radius:999px; border:1px solid var(--line); background:var(--panel); color:var(--ink); cursor:pointer; } #tryq button:hover { border-color:var(--sx); } #tryq button:disabled { opacity:.5; cursor:default; } @media (prefers-reduced-motion: reduce) { .chip.busy i { animation:none; } } #benchmarks { margin-top:34px; } #benchmarks .try { margin:0 0 6px; } #benchmarks .headline { margin-top:0; }123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671"use strict";// LeanScene in the browser. Mirrors leanscene.frame_probs and leanscene.label_frames:// every frame is decoded (WebCodecs), resized to 100x100, and run through the CNN in batches;// the temporal head then labels each frame same / cut / fade, and the frozen rule// (cut >= 0.7, fade >= 0.8, fade runs closed over gaps of <= 8 frames) turns that into transitions.const $ = id => document.getElementById(id);const SIZE = 100, HW = SIZE * SIZE, BATCH = 64, TILES = 8; // TILES: frames are resized into an atlas of 8x8 tilesconst HEAD_CHUNK = 512, HEAD_MARGIN = 64; // the head sees 32 frames each way; 64 keeps chunked output identicalconst STRIP = 20, THUMB_W = 320;const HIST = 64; // colour histogram binslet featS, headS, META, EP, busy = false, result = null;
// yield to the event loop without setTimeout's 4 ms minimumconst tick = () => (self.scheduler && scheduler.yield) ? scheduler.yield() : new Promise(r => { const c = new MessageChannel(); c.port1.onmessage = () => r(); c.port2.postMessage(0); });const b64 = s => Uint8Array.from(atob(s), c => c.charCodeAt(0));const fmtTime = t => { const m = Math.floor(t / 60), s = t - m * 60; return m + ":" + (s < 10 ? "0" : "") + s.toFixed(2); };const css = name => getComputedStyle(document.documentElement).getPropertyValue(name).trim();
async function loadModel() { const st = $("status"); try { if (!window.LEANSCENE) throw new Error("model.js is missing. Create it with: python demo/export_onnx.py"); if (!window.ort || !window.MP4Box) throw new Error("Could not load onnxruntime-web / mp4box from cdn.jsdelivr.net (needs an internet connection)."); if (!window.VideoDecoder) throw new Error("This browser has no WebCodecs video decoder. Use a current Chrome, Edge or Safari."); META = LEANSCENE.meta; ort.env.wasm.numThreads = self.crossOriginIsolated ? Math.min(4, navigator.hardwareConcurrency || 1) : 1; const t = performance.now(); const want = new URLSearchParams(location.search).get("ep") || (navigator.gpu ? "webgpu" : "wasm"); try { featS = await ort.InferenceSession.create(b64(LEANSCENE.features), { executionProviders: [want] }); EP = want; } catch (e) { console.warn("falling back to WebAssembly:", e); featS = await ort.InferenceSession.create(b64(LEANSCENE.features), { executionProviders: ["wasm"] }); EP = "wasm"; } headS = await ort.InferenceSession.create(b64(LEANSCENE.head), { executionProviders: [EP] }); await featS.run({ x: new ort.Tensor("float32", new Float32Array(3 * HW), [1, 3, SIZE, SIZE]) }); // warm-up st.textContent = `Model ready: ${META.checkpoint}, ${((LEANSCENE.features.length + LEANSCENE.head.length) * 0.75 / 1e6).toFixed(1)} MB, loaded in ${Math.round(performance.now() - t)} ms. ` + (EP === "webgpu" ? "Runs on your GPU (WebGPU)." : `Runs on your CPU (WebAssembly, ${ort.env.wasm.numThreads} thread${ort.env.wasm.numThreads > 1 ? "s" : ""}).`); $("drop").classList.remove("busy"); const src = new URLSearchParams(location.search).get("src"); // ?src=clip.mp4 processes a file served next to the page if (src) { const r = await fetch(src); if (!r.ok) throw new Error("Could not fetch " + src); run(new File([await r.blob()], src.split("/").pop())); } } catch (e) { st.textContent = e.message || String(e); st.className = "err"; }}
// --- decoding: every frame of the first video track, in presentation order ---------------function codecDescription(mp4, track) { for (const entry of mp4.getTrackById(track.id).mdia.minf.stbl.stsd.entries) { const box = entry.avcC || entry.hvcC || entry.vpcC || entry.av1C; if (box) { const ds = new DataStream(undefined, 0, DataStream.BIG_ENDIAN); box.write(ds); return new Uint8Array(ds.buffer, 8); } }}
function decodeVideo(file, { onTrack, onFrame, shouldPause, index }) { // index: filled as it goes with where each frame's bytes are, for thumbnails return new Promise((resolve, reject) => { const mp4 = MP4Box.createFile(); let decoder = null, n = 0, failed = false, lastKey = 0; const waiting = []; // [time, sample] of the samples handed to the decoder whose frame has not come out yet const place = () => { // frames come out in presentation order, so this one is the waiting sample with the smallest time let m = 0; for (let i = 1; i < waiting.length; i++) if (waiting[i][0] < waiting[m][0]) m = i; if (!waiting.length) return; const s = waiting[m][1]; waiting[m] = waiting[waiting.length - 1]; waiting.pop(); index.sampleOf.push(s); index.frameOf[s] = n; }; const fail = e => { if (failed) return; failed = true; try { if (decoder && decoder.state !== "closed") decoder.close(); } catch (_) {} reject(e instanceof Error ? e : new Error(String(e))); }; mp4.onError = e => fail(new Error("Could not read this file as MP4/MOV (" + e + ").")); mp4.onReady = info => { const t = info.videoTracks[0]; if (!t) return fail(new Error("No video track found in this file.")); decoder = new VideoDecoder({ output: f => { try { if (!failed) { if (index) place(); onFrame(f, n++); } } catch (e) { fail(e); } finally { f.close(); } }, error: e => fail(new Error(`This browser could not decode the video (codec ${t.codec}): ${e.message}`)), }); const config = { codec: t.codec, codedWidth: t.video.width, codedHeight: t.video.height, description: codecDescription(mp4, t) }; if (index) index.config = config; try { decoder.configure(config); } catch (e) { return fail(new Error(`Unsupported video codec ${t.codec}: ${e.message}`)); } if (onTrack) onTrack(t); mp4.setExtractionOptions(t.id, null, { nbSamples: 100 }); mp4.start(); }; mp4.onSamples = (id, _user, samples) => { if (failed) return; if (index) for (const s of samples) { const i = index.off.length; if (s.is_sync) lastKey = i; index.off.push(s.offset); index.size.push(s.size); index.keyBefore.push(lastKey); waiting.push([s.cts, i]); } for (const s of samples) decoder.decode(new EncodedVideoChunk({ type: s.is_sync ? "key" : "delta", timestamp: 1e6 * s.cts / s.timescale, duration: 1e6 * s.duration / s.timescale, data: s.data })); mp4.releaseUsedSamples(id, samples[samples.length - 1].number); }; (async () => { try { const CHUNK = 1 << 20; for (let off = 0; off < file.size && !failed; off += CHUNK) { const buf = await file.slice(off, off + CHUNK).arrayBuffer(); buf.fileStart = off; mp4.appendBuffer(buf); while (!failed && ((decoder && decoder.decodeQueueSize > 40) || shouldPause())) await new Promise(r => setTimeout(r, 4)); } if (failed) return; mp4.flush(); if (!decoder) return fail(new Error("This does not look like an MP4/MOV video. WebM, MKV and AVI are not supported by this demo.")); await decoder.flush(); decoder.close(); resolve(n); } catch (e) { fail(e); } })(); });}
// --- model -------------------------------------------------------------------------------// Turning a batch's pixels into the model's input takes the page about as long as resizing the// frames does (measured), so a worker does it while the page goes on with the next frames.// This function is turned into text to start the worker: it can use nothing from outside itself.function pixelWorker(SIZE, HIST, TILES) { const HW = SIZE * SIZE, AW = TILES * SIZE; // BIN maps a byte to its colour histogram bin exactly as float32 (v/255)*(4-0.001) truncates const BIN = Uint8Array.from({ length: 256 }, (_, v) => Math.floor(Math.fround(Math.fround(v / 255) * Math.fround(3.999)))); self.onmessage = ev => { // atlas pixels -> one (n,3,SIZE,SIZE) tensor, planar BGR in [0,1] as the model was trained const { run, n, d } = ev.data, t = performance.now(), x = new Float32Array(n * 3 * HW), hist = new Float32Array(n * HIST); for (let k = 0; k < n; k++) { const ox = (k % TILES) * SIZE, oy = Math.floor(k / TILES) * SIZE, o = k * 3 * HW, ho = k * HIST; for (let y = 0, p = 0; y < SIZE; y++) { let q = ((oy + y) * AW + ox) * 4; for (let c = 0; c < SIZE; c++, p++, q += 4) { const r = d[q], g = d[q + 1], b = d[q + 2]; x[o + p] = b / 255; x[o + HW + p] = g / 255; x[o + 2 * HW + p] = r / 255; hist[ho + (BIN[b] * 4 + BIN[g]) * 4 + BIN[r]] += 1 / HW; // joint 4x4x4 colour histogram (models.color_hist) } } } postMessage({ run, n, x, hist, ms: performance.now() - t }, [x.buffer, hist.buffer]); };}let pixels = null, runs = 0;async function detect(file, progress) { const D = META.dim; const live = $("live").getContext("2d"); // Frames are drawn (resized) into an 8x8 atlas of 100x100 tiles and read back once per batch. // willReadFrequently keeps the atlas in CPU memory: reading pixels back from a GPU canvas was the // slowest step of the page (415 vs 1,300 frames/s for decode + resize + readback of 720p, measured). const atlasC = document.createElement("canvas"); atlasC.width = atlasC.height = TILES * SIZE; const atlas = atlasC.getContext("2d", { willReadFrequently: true }); atlas.imageSmoothingEnabled = true; atlas.imageSmoothingQuality = "low"; // bilinear, closest to cv2.resize let feats = new Float32Array(D * 4096), nFeat = 0, total = 0, track = null, fill = 0; const times = [], prof = { model: 0, resize: 0, pixels: 0, head: 0 }; // milliseconds in the CNN, in resize + pixel readback, in the worker that builds the input, in the temporal head const queue = []; let pumping = null; const pump = () => pumping || (pumping = (async () => { while (queue.length) { const { x, n, hist } = queue.shift(); const tm = performance.now(); const out = await featS.run({ x: new ort.Tensor("float32", x, [n, 3, SIZE, SIZE]) }); prof.model += performance.now() - tm; if ((nFeat + n) * D > feats.length) { const g = new Float32Array(feats.length * 2); g.set(feats); feats = g; } if (out.y.dims[1] !== D - HIST) throw new Error("model.js does not match this page. Re-run demo/export_onnx.py and reload without cache."); const y = out.y.data, E = D - HIST; // model output: 128 CNN features, then the layout descriptor for (let k = 0; k < n; k++) { // feature row = CNN features, colour histogram, layout descriptor const o = (nFeat + k) * D; feats.set(y.subarray(k * E, k * E + 128), o); feats.set(hist.subarray(k * HIST, (k + 1) * HIST), o + 128); feats.set(y.subarray(k * E + 128, (k + 1) * E), o + 128 + HIST); } nFeat += n; await head(false); progress(nFeat, total); await tick(); // let decoded frames and the page breathe } pumping = null; })()); if (!pixels) pixels = new Worker(URL.createObjectURL(new Blob([`(${pixelWorker})(${SIZE},${HIST},${TILES})`], { type: "text/javascript" }))); const run = ++runs; let away = 0, workerError = null; // away: batches the worker has not sent back yet pixels.onmessage = ev => { const m = ev.data; if (m.run !== run) return; away--; prof.pixels += m.ms; queue.push(m); pump(); }; pixels.onerror = ev => { workerError = new Error("The page's pixel worker stopped: " + (ev.message || "unknown error")); }; const push = () => { // the atlas's pixels go to the worker, which sends back the model's input if (!fill) return; const tr = performance.now(), n = fill, d = atlas.getImageData(0, 0, TILES * SIZE, Math.ceil(n / TILES) * SIZE).data; away++; pixels.postMessage({ run, n, d }, [d.buffer]); prof.resize += performance.now() - tr; fill = 0; };
const index = { config: null, off: [], size: [], keyBefore: [], sampleOf: [], frameOf: [] };
// Shots are handed on while the video is still being read: `stream.shots` grows as the head // confirms each shot's end, a "leanscene:shots" event says when it grew, and `done` when the // last one is in. clip.js uses this to pick up each shot's picture without a second decode. const stream = window.LEANSCENE_STREAM = { shots: [], done: false, failed: false, thumbs: null }; const shotsGrew = () => document.dispatchEvent(new CustomEvent("leanscene:shots")); // About once per second of video, a small copy of the frame is drawn into a ring of tiles on // one canvas. It stays on the graphics card: nothing is read back here. When a shot ends, the // tile nearest its middle, if it is still in the ring, is handed on with the shot as a bitmap. // Measured on 20 minutes of 1080p (28,906 frames): this adds about 0.3 s to 17.5 s of // detection. Holding every 8th frame added 1.5 s, and holding ImageBitmaps of the frames 2.5 s. const RING_COLS = 8, slotOf = new Map(), frameIn = []; // frame -> its tile, and tile -> its frame let every = 0, ringX = null, ringW = 0, ringH = 0, ringSize = 0, ringN = 0, holdOK = true; const hold = (f, i) => { try { if (!ringX) { ringW = THUMB_W; ringH = Math.round(THUMB_W * f.displayHeight / f.displayWidth); const rows = Math.max(1, Math.min(16, Math.floor(4096 / ringH))), c = document.createElement("canvas"); c.width = RING_COLS * ringW; c.height = rows * ringH; ringSize = RING_COLS * rows; ringX = c.getContext("2d", { alpha: false }); } const slot = ringN++ % ringSize; if (frameIn[slot] !== undefined) slotOf.delete(frameIn[slot]); ringX.drawImage(f, (slot % RING_COLS) * ringW, Math.floor(slot / RING_COLS) * ringH, ringW, ringH); frameIn[slot] = i; slotOf.set(i, slot); } catch (_) { holdOK = false; } }; const heldNear = (start, end, mid) => { // the held frame inside the shot that is nearest its middle, or -1 if (!ringX) return -1; const near = Math.round(mid / every) * every; for (const f of [near, near < mid ? near + every : near - every]) if (f >= start && f <= end && slotOf.has(f)) return f; return -1; }; let shotStart = 0, scan = 0; // first frame of the shot still open; first frame the rule has not settled const addShot = (start, end) => { const mid = (start + end) >> 1, f = heldNear(start, end, mid), s = { start, end, mid, rep: mid, held: null, heldFrame: f }; if (f >= 0) try { const slot = slotOf.get(f); s.held = createImageBitmap(ringX.canvas, (slot % RING_COLS) * ringW, Math.floor(slot / RING_COLS) * ringH, ringW, ringH); s.held.catch(() => {}); } catch (_) { s.held = null; } stream.shots.push(s); }; const emit = final => { // the rule over the frames not settled yet; a run is settled once no later frame can extend it const base = scan, n = headDone - base, before = stream.shots.length; for (const t of transitions(probs.subarray(base * 3, headDone * 3), n)) { if (!final && t.end + META.close + 2 > n) break; if (base + t.before >= shotStart) addShot(shotStart, base + t.before); shotStart = base + t.after; scan = base + t.end + 1; } if (final) { if (shotStart <= headDone - 1) addShot(shotStart, headDone - 1); stream.done = true; } if (final || stream.shots.length > before) shotsGrew(); }; // The temporal head, a chunk of frames at a time as their features arrive (same output as one pass). let probs = new Float32Array(3 * 4096), headDone = 0; async function head(final) { while (headDone < nFeat && (final || nFeat - headDone >= HEAD_CHUNK + HEAD_MARGIN)) { const th = performance.now(), a = headDone, lo = Math.max(0, a - HEAD_MARGIN), hi = Math.min(nFeat, a + HEAD_CHUNK + HEAD_MARGIN), keep = Math.min(HEAD_CHUNK, nFeat - a); // slice (a copy): the worker takes ownership of the buffer it is sent const out = await headS.run({ x: new ort.Tensor("float32", feats.slice(lo * D, hi * D), [1, hi - lo, D]) }); if ((a + keep) * 3 > probs.length) { const g = new Float32Array(Math.max(probs.length * 2, (a + keep) * 3)); g.set(probs); probs = g; } probs.set(out.y.data.subarray((a - lo) * 3, (a - lo + keep) * 3), a * 3); headDone += keep; prof.head += performance.now() - th; emit(final && headDone >= nFeat); } }
try { await decodeVideo(file, { index, onTrack: t => { track = t; total = t.nb_samples; stream.thumbs = thumbnailer(file, index); every = Math.max(8, Math.round(t.nb_samples / (t.duration / t.timescale)) || 24); // frames in a second of this video }, shouldPause: () => queue.length + away > 2, onFrame: (f, i) => { const tr = performance.now(); times.push(f.timestamp / 1e6); if (holdOK && i % every === 0 && window.clipHoldFrames && clipHoldFrames()) hold(f, i); atlas.drawImage(f, (fill % TILES) * SIZE, Math.floor(fill / TILES) * SIZE, SIZE, SIZE); if (fill === 0) live.drawImage(f, 0, 0, SIZE, SIZE); // small preview of where we are prof.resize += performance.now() - tr; if (++fill === BATCH) push(); }, }); push(); while (away || pumping) { if (workerError) throw workerError; if (pumping) await pumping; else await new Promise(r => setTimeout(r, 1)); } const n = nFeat; if (!n) throw new Error("No frames could be decoded from this video."); await head(true); return { n, times, probs: probs.slice(0, n * 3), track, prof, thumbs: stream.thumbs }; } catch (e) { stream.failed = true; if (stream.thumbs) stream.thumbs.close(); shotsGrew(); throw e; } finally { if (ringX) ringX.canvas.width = ringX.canvas.height = 0; // gives the ring's memory back }}
// the decision rule (leanscene.label_frames): returns runs of transition framesfunction transitions(probs, n) { const lab = new Uint8Array(n); for (let i = 0; i < n; i++) lab[i] = probs[i * 3 + 1] >= META.cut ? 1 : probs[i * 3 + 2] >= META.fade ? 2 : 0; const fades = []; for (let i = 0; i < n; i++) if (lab[i] === 2) fades.push(i); const closed = lab.slice(); for (let k = 1; k < fades.length; k++) { const a = fades[k - 1], b = fades[k]; if (b - a > 1 && b - a <= META.close + 1) closed.fill(2, a, b); } const out = []; for (let i = 0; i < n; i++) { if (!closed[i]) continue; let e = i, gradual = false, peak = 0; while (e + 1 < n && closed[e + 1]) e++; for (let j = i; j <= e; j++) { if (closed[j] === 2) gradual = true; peak = Math.max(peak, probs[j * 3 + 1], probs[j * 3 + 2]); } // a cut is labelled on the first frame of the new shot; a gradual run covers the blended frames out.push({ start: i, end: e, type: gradual ? "gradual" : "cut", peak, before: Math.max(0, i - 1), after: gradual ? Math.min(n - 1, e + 1) : e }); i = e; } return out;}
// second decode pass: exact thumbnails of the frames we want to show// --- thumbnails, decoded on demand ---------------------------------------------------------// Nothing is decoded twice up front. When a picture scrolls into view, the frames from the// keyframe before it up to it are read from the file and decoded, which takes a fraction of a// second. `index` is what the first pass records about every frame's bytes (see decodeVideo);// it is still growing while the video is read, and any frame that has come out can be asked for.const BLANK = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; // transparent pixel: no broken-image icon while a picture loadsfunction thumbnailer(file, index) { const order = index.sampleOf, frameOf = index.frameOf, keyBefore = index.keyBefore; // frame (display order) -> sample (decode order), and back; sample -> its keyframe const cache = new Map(), pending = new Map(); // frame -> promise of an image URL; keyframe sample -> Map(frame -> resolve) const c = document.createElement("canvas"), ctx = c.getContext("2d"); let decoder = null, current = null, working = false, closed = false; const open = () => { decoder = new VideoDecoder({ output: f => { try { const done = current && current.get(f.timestamp); // chunks are stamped with their frame number if (done) { if (!c.width || c.dataset.sized !== "1") { c.width = THUMB_W; c.height = Math.round(THUMB_W * f.displayHeight / f.displayWidth); c.dataset.sized = "1"; } ctx.drawImage(f, 0, 0, c.width, c.height); current.delete(f.timestamp); done(c.toDataURL("image/jpeg", 0.8)); } } finally { f.close(); } }, error: e => { console.warn("thumbnail decoder:", e); decoder = null; }, }); decoder.configure(index.config); }; async function work() { if (working) return; working = true; while (pending.size && !closed) { const k = [...pending.keys()].pop(), group = pending.get(k); // newest request first: what is on screen now pending.delete(k); current = group; try { if (!decoder || decoder.state !== "configured") open(); let last = k, lo = Infinity, hi = 0; for (const f of group.keys()) last = Math.max(last, order[f]); for (let s = k; s <= last; s++) { lo = Math.min(lo, index.off[s]); hi = Math.max(hi, index.off[s] + index.size[s]); } const buf = new Uint8Array(await file.slice(lo, hi).arrayBuffer()); for (let s = k; s <= last && decoder; s++) decoder.decode(new EncodedVideoChunk({ type: s === k ? "key" : "delta", timestamp: frameOf[s] ?? 1e12 + s /* its frame has not come out of the first pass yet: never asked for */, data: buf.subarray(index.off[s] - lo, index.off[s] - lo + index.size[s]) })); if (decoder) await decoder.flush(); } catch (e) { console.warn("thumbnail:", e); decoder = null; } for (const done of group.values()) done(""); // frames the decoder did not produce stay blank current = null; } working = false; } const get = frame => { if (!cache.has(frame)) cache.set(frame, new Promise(done => { const k = keyBefore[order[frame]]; let group = pending.get(k); if (group) pending.delete(k); else group = new Map(); group.set(frame, done); pending.set(k, group); // re-inserted last, so it is served first work(); })); return cache.get(frame); }; const seen = new IntersectionObserver(entries => { for (const e of entries) if (e.isIntersecting) { seen.unobserve(e.target); get(+e.target.dataset.frame).then(url => { if (closed) return; e.target.classList.remove("loading"); if (url) e.target.src = url; }); } }, { rootMargin: "300px" }); return { get, lazy(img, frame) { img.dataset.frame = frame; img.src = BLANK; img.classList.add("loading"); seen.observe(img); return img; }, // load when it nears the screen close() { closed = true; seen.disconnect(); pending.clear(); try { if (decoder && decoder.state !== "closed") decoder.close(); } catch (_) {} }, };}
// --- page --------------------------------------------------------------------------------async function run(file) { if (busy || !featS) return; busy = true; if (result) result.thumbs.close(); result = null; $("error").hidden = true; $("results").hidden = true; $("progress").hidden = false; $("drop").classList.add("busy"); $("pbar").value = 0; $("ptext").textContent = "Reading " + file.name + "…"; try { const t0 = performance.now(); const r = await detect(file, (done, total) => { const dt = (performance.now() - t0) / 1000; $("pbar").value = total ? done / total : 0; $("ptext").textContent = `Detecting: ${done.toLocaleString()} / ${total.toLocaleString()} frames · ${Math.round(done / dt)} frames/s`; }); const seconds = (performance.now() - t0) / 1000; const trans = transitions(r.probs, r.n); const stripIdx = Array.from({ length: Math.min(STRIP, r.n) }, (_, k) => Math.min(r.n - 1, Math.floor((k + 0.5) * r.n / Math.min(STRIP, r.n)))); const thumbs = r.thumbs; // pictures are decoded when they scroll into view const fps = r.n > 1 ? (r.n - 1) / (r.times[r.n - 1] - r.times[0]) : 0; result = { file: file.name, frames: r.n, fps, seconds, model: META.checkpoint, prof: r.prof, rule: { cut: META.cut, fade: META.fade, close: META.close }, transitions: trans.map(t => ({ ...t, time: r.times[t.after] - r.times[0] })), probs: r.probs, times: r.times, thumbs, stripIdx }; window.LEANSCENE_RESULT = result; show(file); } catch (e) { console.error(e); $("error").textContent = e.message || String(e); $("error").hidden = false; } finally { busy = false; $("progress").hidden = true; $("drop").classList.remove("busy"); }}
// Player time of frame i. The player's clock does not always start at the first video frame:// when the file has no edit list and its video starts after its audio (common with B-frames),// the first frame sits a couple of frames in. show() measures that as result.base.const base = () => result.base ?? result.times[0];const timeOf = i => result.times[i] - base();function seek(t, play) { const v = $("player"); v.currentTime = Math.max(0, t); if (play) v.play().catch(() => {}); }
function show(file) { const R = result, v = $("player"); if (v.src) URL.revokeObjectURL(v.src); v.src = URL.createObjectURL(file); if (v.requestVideoFrameCallback) v.requestVideoFrameCallback((now, m) => { // the first frame shown tells us where the player's clock puts frame 0 const b = R.times[0] - m.mediaTime; if (result === R && v.currentTime < 0.01 && Math.abs(b) < 10) R.base = b; }); const cuts = R.transitions.filter(t => t.type === "cut").length, grads = R.transitions.length - cuts; const dur = R.frames / (R.fps || 1); const stat = (b, label) => `<div><b>${b}</b>${label}</div>`; $("summary").innerHTML = stat(R.transitions.length + 1, "shots") + stat(cuts, "cuts") + stat(grads, "fades / gradual") + stat(R.frames.toLocaleString(), `frames at ${R.fps.toFixed(2)} fps`) + stat(Math.round(R.frames / R.seconds).toLocaleString(), "frames/s, decoding included") + stat((dur / R.seconds).toFixed(1) + "×", "faster than real time"); $("strip").replaceChildren(...R.stripIdx.map(i => { const im = new Image(); im.alt = "frame " + i; return R.thumbs.lazy(im, i); })); $("cardsTitle").textContent = R.transitions.length ? `${R.transitions.length} transitions` : "No transitions found"; activeCard = -1; showPage(0); $("results").hidden = false; drawOverview(); setView(0, R.frames); document.dispatchEvent(new CustomEvent("leanscene:result")); // clip.js listens for this}
// --- timeline: an overview of the whole video, and a strip below it that zooms and pans ----let view = { a: 0, b: 1 }; // the frames the strip shows, as fractional frame numbers [a, b)let dragging = false, ovDown = false, lastTouch = 0, drawQueued = false;const TOP = 14, RULER = 16;const span = () => view.b - view.a;const tlW = () => $("timeline").clientWidth || 1;const minSpan = () => Math.min(result.frames, Math.max(10, tlW() / 10)); // closest zoom: 10 px per frameconst timeAt = f => timeOf(Math.max(0, Math.min(result.frames - 1, Math.floor(f))));function frameAtTime(t) { // fractional frame shown at player time t const T = result.times, t0 = base(); let lo = 0, hi = T.length - 1; while (lo < hi) { const m = (lo + hi + 1) >> 1; if (T[m] - t0 <= t) lo = m; else hi = m - 1; } const next = lo + 1 < T.length ? T[lo + 1] - T[lo] : 0; return lo + (next > 0 ? Math.max(0, Math.min(1, (t - (T[lo] - t0)) / next)) : 0);}function setView(a, b) { if (!result) return; const n = result.frames, s = Math.max(minSpan(), Math.min(n, b - a)); a = Math.max(0, Math.min(n - s, a)); view = { a, b: a + s }; const box = $("ovbox"); box.style.left = 100 * a / n + "%"; box.style.width = 100 * s / n + "%"; $("zoominfo").textContent = s >= n ? "" : `${clock(timeAt(a))} – ${clock(timeAt(a + s))}`; $("zfit").disabled = $("zout").disabled = s >= n; $("zin").disabled = s <= minSpan(); if (!drawQueued) { drawQueued = true; requestAnimationFrame(() => { drawQueued = false; drawTimeline(); }); }}function zoomAt(frame, factor) { // keeps `frame` under the same pixel const s = span(), ns = Math.max(minSpan(), Math.min(result.frames, s * factor)), a = frame - (frame - view.a) * ns / s; setView(a, a + ns);}function clock(t, decimals = 0) { const h = Math.floor(t / 3600), m = Math.floor(t % 3600 / 60), s = t - h * 3600 - m * 60; const ss = (s < 10 ? "0" : "") + s.toFixed(decimals); return h ? `${h}:${m < 10 ? "0" : ""}${m}:${ss}` : `${m}:${ss}`;}
function plot(g, W, y0, h, a, b) { // cut and fade probability of frames a..b across W pixels const R = result, px = W / (b - a), i0 = Math.max(0, Math.floor(a)), i1 = Math.min(R.frames, Math.ceil(b)); const layers = [[2, css("--fade"), 0.75], [1, css("--cut"), 1]]; if (px >= 1) { // zoomed in: one bar per frame const gap = px >= 4 ? 1 : 0; for (const [k, color, alpha] of layers) { g.fillStyle = color; g.globalAlpha = alpha; for (let i = i0; i < i1; i++) { const p = R.probs[i * 3 + k]; if (p > 0.02) g.fillRect((i - a) * px, y0 + h * (1 - p), px - gap, h * p); } } } else { // zoomed out: each pixel column shows the highest probability of the frames under it const col = new Float32Array(W * 3); for (let i = i0; i < i1; i++) { const x = Math.max(0, Math.min(W - 1, Math.floor((i - a) * px))) * 3; if (R.probs[i * 3 + 1] > col[x + 1]) col[x + 1] = R.probs[i * 3 + 1]; if (R.probs[i * 3 + 2] > col[x + 2]) col[x + 2] = R.probs[i * 3 + 2]; } for (const [k, color, alpha] of layers) { g.fillStyle = color; g.globalAlpha = alpha; for (let x = 0; x < W; x++) { const p = col[x * 3 + k]; if (p > 0.02) g.fillRect(x, y0 + h * (1 - p), 1, h * p); } } } g.globalAlpha = 1;}
function canvas2d(id) { const c = $(id), dpr = window.devicePixelRatio || 1, W = c.clientWidth, H = c.clientHeight; c.width = W * dpr; c.height = H * dpr; const g = c.getContext("2d"); g.scale(dpr, dpr); g.clearRect(0, 0, W, H); return { g, W, H };}
function drawOverview() { if (!result) return; const { g, W, H } = canvas2d("overview"); plot(g, W, 2, H - 4, 0, result.frames);}
function drawTimeline() { if (!result) return; const R = result, { g, W, H } = canvas2d("timeline"), { a, b } = view, px = W / (b - a); const h = H - TOP - RULER - 2, cutC = css("--cut"), fadeC = css("--fade"); g.strokeStyle = css("--line"); g.setLineDash([3, 4]); g.lineWidth = 1; for (const th of new Set([R.rule.cut, R.rule.fade])) { const y = TOP + h * (1 - th) + 0.5; g.beginPath(); g.moveTo(0, y); g.lineTo(W, y); g.stroke(); } g.setLineDash([]); plot(g, W, TOP, h, a, b); for (const t of R.transitions) { // markers above the plot if (t.end + 1 < a || t.start > b) continue; const x = ((t.start + t.end + 1) / 2 - a) * px; g.fillStyle = t.type === "cut" ? cutC : fadeC; if (t.type !== "cut" && px >= 1) g.fillRect((t.start - a) * px, 4, (t.end + 1 - t.start) * px, 3); // how long a gradual transition lasts g.beginPath(); g.moveTo(x - 4, 2); g.lineTo(x + 4, 2); g.lineTo(x, 10); g.fill(); } // time ruler: the smallest round step that keeps labels about 90 px apart const t0 = timeAt(a), t1 = timeAt(b), secs = Math.max(1e-6, t1 - t0); const step = [0.1, 0.2, 0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, 3600].find(s => s / secs * W >= 90) || 3600; g.fillStyle = css("--mute"); g.font = "10px -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"; for (let k = Math.ceil(t0 / step); k * step <= t1; k++) { const x = (frameAtTime(k * step) - a) * px; g.fillRect(x, H - RULER, 1, 4); g.fillText(clock(k * step, step < 1 ? 1 : 0), x + 3, H - 4); }}
const tl = $("tlwrap"), ov = $("ovwrap");const xFrac = ev => { const r = tl.getBoundingClientRect(); return (ev.clientX - r.left) / r.width; };function frameAtX(ev) { return Math.max(0, Math.min(result.frames - 1, Math.floor(view.a + xFrac(ev) * span()))); }tl.addEventListener("wheel", ev => { // pinch or Ctrl/Cmd + scroll zooms; sideways scroll (or Shift + scroll) pans if (!result) return; const unit = ev.deltaMode === 1 ? 16 : 1; if (ev.ctrlKey || ev.metaKey) zoomAt(view.a + xFrac(ev) * span(), Math.exp(ev.deltaY * unit * 0.01)); else if (Math.abs(ev.deltaX) > Math.abs(ev.deltaY)) { const d = ev.deltaX * unit * span() / tlW(); setView(view.a + d, view.b + d); } else return; // plain vertical scroll still scrolls the page ev.preventDefault(); lastTouch = performance.now();}, { passive: false });let pinch = null; // Safari reports trackpad pinches as gesture eventstl.addEventListener("gesturestart", ev => { if (!result) return; ev.preventDefault(); pinch = { s: span(), f: view.a + xFrac(ev) * span() }; });tl.addEventListener("gesturechange", ev => { if (!pinch) return; ev.preventDefault(); zoomAt(pinch.f, pinch.s / ev.scale / span()); lastTouch = performance.now(); });tl.addEventListener("gestureend", () => { pinch = null; });let down = null; // a press that has not moved is a click (jump there); one that moves drags the viewtl.addEventListener("pointerdown", ev => { if (result && !ev.button) down = { x: ev.clientX, a: view.a, id: ev.pointerId }; });tl.addEventListener("pointermove", ev => { if (!result) return; if (down) { const dx = ev.clientX - down.x; if (!dragging && Math.abs(dx) > 4 && span() < result.frames) { dragging = true; try { tl.setPointerCapture(down.id); } catch (_) {} tl.classList.add("drag"); $("tip").hidden = true; } if (dragging) { const a = down.a - dx * span() / tlW(); setView(a, a + span()); lastTouch = performance.now(); return; } } const i = frameAtX(ev), tip = $("tip"), r = tl.getBoundingClientRect(); tip.hidden = false; tip.style.left = Math.max(60, Math.min(r.width - 60, ev.clientX - r.left)) + "px"; tip.textContent = `${fmtTime(timeOf(i))} · frame ${i}`;});const release = ev => { if (!down) return; if (!dragging && ev.type === "pointerup") seek(timeOf(frameAtX(ev)), false); down = null; dragging = false; tl.classList.remove("drag");};tl.addEventListener("pointerup", release);tl.addEventListener("pointercancel", release);tl.addEventListener("pointerleave", () => { $("tip").hidden = true; });// overview: press or drag to move the zoomed view thereconst ovGo = ev => { const r = ov.getBoundingClientRect(), f = (ev.clientX - r.left) / r.width * result.frames, s = span(); setView(f - s / 2, f + s / 2); lastTouch = performance.now(); };ov.addEventListener("pointerdown", ev => { if (!result || ev.button) return; ovDown = true; ovGo(ev); try { ov.setPointerCapture(ev.pointerId); } catch (_) {} });ov.addEventListener("pointermove", ev => { if (ovDown) ovGo(ev); });ov.addEventListener("pointerup", () => { ovDown = false; });ov.addEventListener("pointercancel", () => { ovDown = false; });const zoomButton = factor => () => { if (!result) return; const f = frameAtTime($("player").currentTime); zoomAt(f >= view.a && f <= view.b ? f : (view.a + view.b) / 2, factor); // around the playhead when it is in view};$("zin").onclick = zoomButton(0.5);$("zout").onclick = zoomButton(2);$("zfit").onclick = () => { if (result) setView(0, result.frames); };// previous / next transition: the buttons, and the left and right arrow keys// The cards are paged: a film has many hundreds of transitions.const PER_PAGE = 48; // a multiple of 12, so rows are full at 4, 3, 2 and 1 columnslet activeCard = -1, cardPage = 0;function card(t, k) { const R = result, b = document.createElement("button"); b.className = "card"; const where = t.type === "cut" ? `frame ${t.after}` : `frames ${t.start}–${t.end}`; b.innerHTML = `<div class="pair"><img alt="frame ${t.before}"><img alt="frame ${t.after}"></div>` + `<div class="cap"><span><span class="tag ${t.type}">${t.type}</span> · ${fmtTime(t.time)}</span><span class="mute">${where} · p ${t.peak.toFixed(2)}</span></div>`; const [before, after] = b.querySelectorAll("img"); R.thumbs.lazy(before, t.before); R.thumbs.lazy(after, t.after); b.onclick = () => { markCard(k); seek(timeOf(t.start) + 0.001, true); /* +1 ms: an exact frame time can round to the frame before */ $("player").scrollIntoView({ behavior: "smooth", block: "nearest" }); }; return b;}function showPage(p, scroll) { const T = result.transitions, n = T.length, pages = Math.max(1, Math.ceil(n / PER_PAGE)); cardPage = Math.max(0, Math.min(pages - 1, p)); const a = cardPage * PER_PAGE, b = Math.min(n, a + PER_PAGE); $("cards").replaceChildren(...T.slice(a, b).map((t, i) => card(t, a + i))); if (activeCard >= a && activeCard < b) $("cards").children[activeCard - a].classList.add("on"); for (const el of document.querySelectorAll(".pager")) { el.hidden = pages < 2; el.querySelector(".pinfo").textContent = `${(a + 1).toLocaleString()}–${b.toLocaleString()} of ${n.toLocaleString()}`; el.querySelector(".pprev").disabled = cardPage === 0; el.querySelector(".pnext").disabled = cardPage === pages - 1; } if (scroll) $("cardsTitle").scrollIntoView({ behavior: "smooth", block: "start" });}function markCard(k) { // highlights transition k, turning to its page when it is on another one const page = Math.floor(k / PER_PAGE); if (k >= 0 && page !== cardPage) { activeCard = k; showPage(page); return; } const cards = $("cards").children, a = cardPage * PER_PAGE; if (cards[activeCard - a]) cards[activeCard - a].classList.remove("on"); activeCard = k; if (cards[k - a]) cards[k - a].classList.add("on");}document.addEventListener("click", ev => { const btn = ev.target.closest && ev.target.closest(".pager button"); if (btn && result) showPage(cardPage + (btn.classList.contains("pnext") ? 1 : -1), !!btn.closest(".bottom"));});function step(dir) { if (!result) return; const T = result.transitions, v = $("player"), f = Math.floor(frameAtTime(v.currentTime) + 1e-3); const back = v.paused ? 0 : (result.fps || 30) * 0.5; // while playing, "previous" within half a second of a transition goes one further back let k = -1; if (dir > 0) k = T.findIndex(t => t.start > f); else for (let i = T.length - 1; i >= 0; i--) if (T[i].start < f - back) { k = i; break; } if (k < 0) { // nothing earlier: "previous" goes to the first frame of the video if (dir < 0 && f > 0) { seek(timeOf(0), false); markCard(-1); } return; } seek(timeOf(T[k].start) + 0.001, false); // keeps playing if it was playing markCard(k);}$("tprev").onclick = () => step(-1);$("tnext").onclick = () => step(1);// Capture phase, and stopped there: a focused player handles the arrow keys itself (it seeks by// a few seconds) before a bubbling listener runs, which made one press skip several transitions.window.addEventListener("keydown", ev => { if (!result || ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey || (ev.key !== "ArrowLeft" && ev.key !== "ArrowRight")) return; if (ev.target.closest && ev.target.closest("input, textarea, select")) return; ev.preventDefault(); ev.stopImmediatePropagation(); step(ev.key === "ArrowRight" ? 1 : -1);}, true);(function playhead() { if (result) { const v = $("player"), n = result.frames, f = frameAtTime(v.currentTime), s = span(); // while playing, turn the page when the playhead leaves the view (unless the view was just moved by hand) if (!v.paused && s < n && !dragging && !ovDown && performance.now() - lastTouch > 1500 && (f < view.a || f > view.a + s * 0.95)) setView(f - s * 0.05, f + s * 0.95); const p = (f - view.a) / span(), ph = $("playhead"); ph.hidden = p < 0 || p > 1; ph.style.left = 100 * p + "%"; $("ovhead").style.left = 100 * f / n + "%"; } requestAnimationFrame(playhead);})();$("player").addEventListener("seeked", () => { // a jump from a card or the player's own bar: bring it into view if (!result) return; const f = frameAtTime($("player").currentTime), s = span(); if (f < view.a || f > view.b) setView(f - s / 2, f + s / 2);});window.addEventListener("resize", () => { drawOverview(); setView(view.a, view.b); });matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => { drawOverview(); drawTimeline(); });
$("download").onclick = () => { const R = result, body = { file: R.file, model: R.model, rule: R.rule, frames: R.frames, fps: R.fps, transitions: R.transitions.map(t => ({ type: t.type, start_frame: t.start, end_frame: t.end, time_s: +t.time.toFixed(3), peak_probability: +t.peak.toFixed(4) })) }; const a = document.createElement("a"); a.href = URL.createObjectURL(new Blob([JSON.stringify(body, null, 1)], { type: "application/json" })); a.download = R.file.replace(/\.[^.]+$/, "") + ".transitions.json"; a.click(); URL.revokeObjectURL(a.href);};
const drop = $("drop");$("file").addEventListener("change", ev => { if (ev.target.files[0]) run(ev.target.files[0]); ev.target.value = ""; });window.addEventListener("dragover", ev => { ev.preventDefault(); drop.classList.add("over"); });window.addEventListener("dragleave", ev => { if (!ev.relatedTarget) drop.classList.remove("over"); });window.addEventListener("drop", ev => { ev.preventDefault(); drop.classList.remove("over"); const f = ev.dataTransfer.files[0]; if (f) run(f); });
12345678910111213141516171819<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><link rel="stylesheet" href="style.css" /></head><body><div class="card"><h1>Welcome to your static Space!</h1><p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p><p>Also don't forget to check the<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.</p></div></body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798<!doctype html><!-- The LeanScene Space on Hugging Face: shot detection only, under its own header. This file isthe page around the detection view; publish.sh fills in the rest from demo/index.html, sothat what shows the detections is the same in both places and is kept in one place:demo.css its stylesheetRESULTS its results section (player, timeline, transition cards), put in belowengine.js its script, up to where shot search is loadedand adds the wordmark from logo/ as logo.svg and logo-dark.svg.See ../publish.sh. --><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>LeanScene: shot detection</title><link rel="stylesheet" href="demo.css"><style>main { padding-top:22px; }h1.logo img { display:block; height:36px; width:auto; margin-left:-4px; } /* two thirds of the demo's size; demo.css picks the light or dark one */h1.logo span { top:-8px; }header p { margin:4px 0 0; max-width:72ch; }.links { display:flex; flex-wrap:wrap; gap:6px 18px; margin:10px 0 0; font-size:13px; }.links a { color:inherit; }#drop { margin-top:16px; }.examples { display:flex; flex-wrap:wrap; align-items:center; gap:6px 10px; margin:10px 0 0; font-size:13px; }.examples small { font-size:12px; } .examples a { color:inherit; }#status:not(.err) { display:block; margin:10px 0 0; } /* the demo shows this in a pill; here it is a line of text */</style></head><body><main><header><h1 class="logo"><img class="l" src="logo.svg" alt="LeanScene"><img class="d" src="logo-dark.svg" alt="LeanScene"><span><em class="badge">Shot detection</em></span></h1><p class="mute">Finds every cut, dissolve and fade in a video. The model is 1.6 MB and runs in this browser tab: your video is not uploaded.</p><p class="links mute"><a href="https://huggingface.co/lucaspy/LeanScene" target="_blank" rel="noopener">Model card and benchmarks</a><a href="https://github.com/lucasjacks0n/LeanScene" target="_blank" rel="noopener">Code on GitHub</a><a href="https://lucasjackson.dev/leanscene/" target="_blank" rel="noopener">Full demo, with search by description</a></p></header><label id="drop" class="busy"><input type="file" id="file" accept="video/mp4,video/quicktime,.mp4,.mov,.m4v" hidden><strong>Drop a video here</strong><span class="mute">or click to choose one (MP4 or MOV). It is processed in this tab and never uploaded.</span></label><p class="examples mute">Example<button class="plain" id="sample" disabled>Big Buck Bunny, 50 s</button><small>© Blender Foundation, <a href="https://www.bigbuckbunny.org/" target="_blank" rel="noopener">bigbuckbunny.org</a>, <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank" rel="noopener">CC BY 3.0</a></small></p><p id="status" class="mute">Loading model…</p><p id="error" style="margin-top:10px" hidden></p><section id="progress" hidden><canvas id="live" width="100" height="100"></canvas><div><p id="ptext">Starting…</p><progress id="pbar" max="1" value="0"></progress></div></section><section id="results" hidden><div id="summary"></div><video id="player" controls muted playsinline></video><div id="strip"></div><div id="ovwrap"><canvas id="overview"></canvas><div id="ovbox"></div><div id="ovhead"></div></div><div id="tlwrap"><canvas id="timeline"></canvas><div id="playhead"></div><div id="tip" hidden></div></div><div class="legend"><span><i style="background:var(--cut)"></i>cut probability</span><span><i style="background:var(--fade)"></i>fade / gradual probability</span><span>▼ detected transition</span><span>Click to jump; ← → step between transitions. Pinch or Ctrl/⌘ + scroll to zoom; drag or scroll sideways to move.</span><span class="zoom"><button class="plain" id="tprev" aria-label="Previous transition" title="Previous transition (←)">◀</button><button class="plain" id="tnext" aria-label="Next transition" title="Next transition (→)">▶</button><span id="zoominfo"></span><button class="plain" id="zout" aria-label="Zoom out">−</button><button class="plain" id="zin" aria-label="Zoom in">+</button><button class="plain" id="zfit">Fit</button></span></div><div class="row"><h2 id="cardsTitle">Transitions</h2><button class="plain" id="download">Download JSON</button></div><p class="mute" style="font-size:13px;margin:-4px 0 10px">Each card shows the last frame before the transition and the first frame after it. Click a card to play from the transition.</p><div class="pager top" hidden><button class="plain pprev">← Previous</button><span class="pinfo"></span><button class="plain pnext">Next →</button></div><div id="cards"></div><div class="pager bottom" hidden><button class="plain pprev">← Previous</button><span class="pinfo"></span><button class="plain pnext">Next →</button></div></section></main><script src="https://cdn.jsdelivr.net/npm/mp4box@0.5.2/dist/mp4box.all.min.js"></script><script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort.webgpu.min.js"></script><script src="model.js"></script><script src="engine.js"></script><script>// engine.js is the demo's own script: it reads the video, finds the transitions and draws the// results. All this page adds is the example button, then it starts loading the model."use strict";$("sample").onclick = async () => {try { const r = await fetch("sample.mp4"); if (!r.ok) throw new Error("HTTP " + r.status); run(new File([await r.blob()], "big-buck-bunny.mp4", { type: "video/mp4" })); }catch (e) { $("error").textContent = "Could not load the example: " + (e.message || e); $("error").hidden = false; }};setInterval(() => { $("sample").disabled = !featS || busy; }, 200);loadModel();</script></body></html>
123version https://git-lfs.github.com/spec/v1oid sha256:f8a10e0c99e24b46f4a75cddfb818733994e57d95745ff3bcb4e84e065682f85size 2774857.gitattributes+1
README.md+15-4
demo.cssAdded+200
engine.jsAdded+671
index.html+96-17
logo-dark.svgAdded
logo.svgAdded
model.jsAdded
sample.mp4Added+3