A 0.39M-parameter network that finds shot transitions (cuts, dissolves, fades) in video. It scores higher than TransNet V2 on all three of that model's benchmarks, with 115x fewer operations per frame.
Try it in your browser: drop a video and see every transition on a timeline. It runs in the tab; nothing is uploaded.
# Python
pip install leanscene
leanscene video.mp4
# JavaScript: Node.js and the browser
npm install leanscene
npx leanscene video.mp4
The Python package is on PyPI and the JavaScript package, for Node.js and the browser, is on npm.
video.mp4: 14775 frames, 25.000 fps, 51 shots, 50 transitions
shot start end start time end time
1 0 343 00:00:00.000 00:00:13.760
2 344 2403 00:00:13.760 00:01:36.160
...
The weights ship inside the package (1.6 MB, plus a 1.6 MB copy as ONNX graphs for the CPU); nothing is downloaded at run time. The paper is in preparation.
Python
import leanscene
result = leanscene.detect("video.mp4")
result.shots # [(0, 343), (344, 2403), (2414, 3315), ...] inclusive frame ranges, 0-based
result.transitions # [Transition(start=344, end=344, kind='cut'), Transition(start=2404, end=2413, kind='gradual'), ...]
result.probs # (frames, 3) float32: same, cut, fade
result.to_dict() # JSON-ready, with times in seconds
To process many videos, load the model once:
model = leanscene.load_model() # or load_model(device="cuda")
for path in paths:
result = leanscene.detect(path, model=model)
On the CPU, load_model() returns a leanscene.OnnxModel, the network on ONNX Runtime, which
is about twice as fast there. It is not a torch.nn.Module: for the PyTorch model (to train,
export, or call it directly) use load_model(backend="torch"). A checkpoint file, device="cuda"
or "mps", and a Python without an ONNX Runtime wheel give the PyTorch model anyway.
detect also takes an iterable of HxWx3 uint8 frames in BGR order instead of a path, and
cut= / fade= thresholds (defaults 0.7 and 0.8, the rule used for every number below).
frame_probs returns only the probabilities; label_frames, find_transitions and
find_shots are the steps detect applies to them.
A cut is reported on the first frame of the new shot. A gradual transition is the run of frames inside it, and those frames belong to neither neighbouring shot.
Command line
| Option | Effect |
|---|---|
-f table|json|csv |
Output format. table (default) and csv list shots; json has shots and transitions |
-o FILE |
Write to a file instead of standard output |
--model PATH |
A checkpoint file, to use weights other than the bundled ones |
--device DEVICE |
cpu, cuda or mps. Default: cuda when available, else cpu |
--cut X, --fade X |
Thresholds (0.7, 0.8). Higher gives fewer false alarms, lower misses less |
--probs FILE.npy |
Also save the per-frame probabilities |
-q, --quiet |
No progress line |
In a terminal it shows a live progress line (frames done, frames per second, time left). The line goes to
standard error, so piped or redirected output stays clean. From Python, pass progress= a function that
takes the number of frames read so far.
Several videos can be given at once. python -m leanscene is the same command.
JavaScript: the browser and Node.js
js/ is the same model as an npm package, with TypeScript types. One
import works in both places.
npm install leanscene
import { detect } from "leanscene";
// in the browser: a File from an input or a drop. It runs in the page, on WebGPU when there is one
const { shots, transitions } = await detect(input.files[0]);
// in Node: a path, decoded with ffmpeg. `npx leanscene video.mp4` is the same from a shell
const { shots, transitions } = await detect("video.mp4");
On 8 test videos the Node build and the Python package each found 527 transitions (4 found only by Python and 4 only by Node), at 1,728 and 2,317 frames per second end to end on a laptop CPU. The browser build found 545 where Node found 546 on 9 videos, at about 700 frames per second on WebGPU. Its README has both comparisons.
Results
LeanScene scores higher than TransNet V2 on all three benchmarks, at a twentieth of the size and with 115x fewer operations per frame.
| BBC Planet Earth | ClipShots | RAI | Parameters | MACs per frame | |
|---|---|---|---|---|---|
| TransNet V2 | 96.1 | 77.7 | 92.6 | 7.62 M | 832 M |
| LeanScene (mean of 5 seeds) | 97.4 ± 0.1 | 79.1 ± 0.2 | 93.7 ± 0.5 | 0.39 M | 7.2 M |
| The bundled weights (one of the 5 seeds) | 97.45 | 78.82 | 93.03 | ||
| LeanScene at full width (not shipped; mean of 5 seeds) | 97.3 ± 0.2 | 79.1 ± 0.5 | 93.5 ± 1.2 | 0.49 M | 20.9 M |
F1 over transitions with TransNet V2's own protocol (two-frame tolerance). Both models are run through the same decoding and scoring code, and LeanScene's decision rule was fixed before the test sets were scored.
It is fast as well as small. On an Apple M1 Pro the leanscene command reads a 91-minute
720p film (131,720 frames) in 51 seconds, about 2,600 frames per second, decoding included, on
the CPU. The model alone runs at about 4,900 frames per second; TransNet V2 at 167.
Fine print
- TransNet V2's paper reports 96.2, 77.9 and 93.9. The row above is its published weights measured by us; we could not reproduce its RAI number.
- Every one of the five seeds is above TransNet V2 on every benchmark.
- A paired bootstrap over videos puts the BBC lead clear of zero (+1.28, 95% interval +0.50 to +2.47). The ClipShots and RAI leads (+1.36 and +1.13) have intervals that include zero.
- The BBC lead shrinks to +0.48 if TransNet V2's threshold is tuned on the test set, and it
depends on the hand labels in
labels/: trained without them, the full-width model scores 95.4 on BBC, 80.0 on ClipShots and 93.2 on RAI (mean of 3 seeds). - The test sets were looked at during development.
- Speeds: one run each on an Apple M1 Pro, CPU only. End to end, the speed depends on the video more than on the model, because every frame is decoded at full size before it is shrunk: 2,574 frames/s on the 720p H.264 film above, 1,132 on 1080p H.264, 837 on 1080p HEVC and 419 on 4K H.264. The model-alone figures are on pre-decoded 100x100 frames (ONNX Runtime; the same model on PyTorch runs at about 2,000; TransNet V2's figure is from the paper's timing). Before this version the command ran the same film at 1,165 frames/s. No CUDA timing has been measured.
Weights
The package ships one set of weights (1.6 MB, sha256 b0d1cc2a77f8aa91…, research run
seqnet_w05_seed2), and the same weights as the two ONNX graphs that run on the CPU by default
(features.onnx and head.onnx, 1.6 MB together; js/scripts/export_onnx.py writes them from
the .pt file, for this package and the npm package). It was trained on synthetic transitions built from single-shot
skateboarding clips, ClipShots training videos, and 1,245 hand labels on skateboarding videos.
The hand labels are in labels/, as YouTube ids and frame indices. The
clips behind the synthetic transitions are not released.
The paper trains the model five times from different random seeds and reports the mean. The bundled file is the seed with the best F1 on the validation set (906 ClipShots training videos held out from training), chosen without looking at the test sets.
How it works
Each frame is resized to 100x100 and encoded once: a four-layer 2D CNN gives a global feature and a 2x2 grid of features, and two descriptors come straight from the pixels (a 64-bin colour histogram and an 8x8 colour thumbnail). A temporal head of five residual dilated 1D convolutions (dilations 1, 2, 4, 8, 16; receptive field 63 frames) sees those features and their change since the previous frame, and labels every frame same, cut or fade.
The video is streamed, so memory stays flat on long files: frames are encoded in batches and the head runs over 4,096 frames at a time with 64 frames of context on each side, which gives the same output as a single pass. A file is decoded in a background thread while the model runs on the previous batch.
On the CPU the network runs on ONNX Runtime, from the two graphs in src/leanscene/weights/
(the same files as the npm package's). That is about twice as fast as PyTorch for a network
this small, and gives the same transitions: on the film above every shot and transition was
identical and per-frame probabilities differed by at most 0.000003. PyTorch is used for a
checkpoint file, for --device cuda or mps, with load_model(backend="torch"), and where
ONNX Runtime has no wheel for the Python version.
Labels
labels/ holds the 1,245 hand labels (cuts, fades and confirmed
non-transitions on 466 skateboarding videos) the model was trained on.
Browser demo
Live at lucasjackson.dev/leanscene.
demo/ runs the same model in a browser tab with ONNX Runtime Web: drop a
video on the page and it shows the transitions on a timeline, then lets you search the shots by
describing them (one frame per shot is embedded with MobileCLIP, also in the tab). The video is
never uploaded.
Reproducing the numbers
eval/ scores the bundled weights on the three benchmarks with the
paper's protocol.
Training
training/ is the code that trained the bundled weights: the trainer, the
synthetic transitions, and the mining and cleaning of hard negatives, with the command for
each step of the paper's recipe. The single-shot clips behind the synthetic sequences are not
distributed, so bring your own to train.
Limits
- Videos are decoded with OpenCV. Times are frame index divided by the container's frame rate, so they drift on variable-frame-rate files; frame indices are exact.
--device mpsis not the default on Apple hardware: a process that fed MPS many different input lengths kept growing in memory in our runs. On the CPU the default is faster anyway.- Decoding is the limit on high-resolution video (419 frames/s for 4K H.264 on an M1 Pro): OpenCV decodes in software and converts each full frame to color before it is shrunk. The browser build, which decodes on the media engine, does not have this limit.
Development
python3 -m venv .venv
.venv/bin/python -m pip install -e ".[dev,export]"
.venv/bin/python -m pytest
.venv/ is about 1 GB (mostly PyTorch), is gitignored, and is safe to delete; the two commands
above recreate it. The export extra is only needed for demo/export_onnx.py and
js/scripts/export_onnx.py; the second writes the ONNX graphs to both js/weights/ and
src/leanscene/weights/, and a test checks the two copies are identical.
Citation
@misc{jackson2026leanscene,
title = {LeanScene: A 0.39M-Parameter Network for Fast Shot Transition Detection},
author = {Lucas Jackson},
year = {2026},
note = {In preparation}
}
Licence
- Code and model weights: MIT, see LICENSE.
eval/evaluate.pycontains two functions adapted from TransNet V2 (MIT). - The labels in
labels/: CC BY 4.0. Use them freely, with credit.
Metadata
Release files for leanscene 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| leanscene-0.2.0.tar.gz | 3.0 MB | Without provenance | Details for leanscene-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| leanscene-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for leanscene-0.2.0-py3-none-any.whl |
Total release size: 5.9 MB
Release files / leanscene-0.2.0.tar.gz
| Download URL | leanscene-0.2.0.tar.gz |
|---|---|
| Size | 3.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff58c2d951c625d4e74f0f62918070dd941a40245cac504759da683f5d28d9df
|
|
BLAKE2b-256 checksum How to use checksums |
f2113bca3988c58f1ec55600fb4f92c49da4285cd84556052ab8c42ff69401b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.12
|
Release files / leanscene-0.2.0-py3-none-any.whl
| Download URL | leanscene-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47def0773edea37983e6bc8b9135120c3c956c316e225bd6c351168ff0c100e9
|
|
BLAKE2b-256 checksum How to use checksums |
924cab89f6ca2441dcb0ce43d1284b19bf0588b6dd5303a2eb213240b3029a24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.12
|
Security for leanscene 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.