GetKeyFrames
Scene detection that picks your animation's keyframes for you
- frames
- Keyframes
- Labeled Keyframes
Generating every frame of an animation is mostly wasted work - most frames barely differ from the ones around them. GetKeyFrames is the node that finds the frames that actually matter: it runs pixel-space scene detection over an image batch, ranks the frames by how much they change, and returns the top N. Feed it the output of BreakFrames and you go from a thousand frames to a dozen keyframes worth regenerating.
The mechanism is refreshingly honest about what it is. It computes the L2 (Euclidean) distance between each pair of consecutive frames, grabs the N biggest differences with a top-k sort, and hands those frame indices back in order. num_keyframes defaults to 12, and while the field lets you go up to 4096, the code quietly clips it to len(frames) - 2 - you can't ask for more keyframes than the footage has, and it won't tell you it did it. The two booleans, include_first_frame and include_last_frame, both default to true, which is right: the opening and closing frames are usually worth keeping even when nothing changed.
Two outputs come out. Keyframes is the clean IMAGE batch, ready for MakeGrid or a sampler. Labeled Keyframes is the same frames with the original frame number stamped onto each one - not a sequence number, the actual index in the source footage. That's the one you want when you spot a great frame and need to go find it in the original video.
The label stamping has a genuine Linux gotcha, straight from the source: it draws text with ImageFont.truetype("arial.ttf", 72), and arial.ttf isn't installed on most Linux boxes. If you're on Windows (or have the font), nothing to see here. On Linux, GetKeyFrames can throw when it tries to build the labeled output - if that's you, install a system font named arial (or mscorefonts) and restart. The unlabeled Keyframes output is unaffected.
The thing to keep in mind: this is scene detection in pixel space, not in meaning. A camera cut or a flash scores huge; a slow, steady pan scores almost nothing even if it's the most important motion in the clip. It doesn't understand content, it measures change. For its purpose - thinning a video down to the frames you'd want to img2img or grid - that's usually good enough, and it's a lot better than picking every Nth frame blind. This is also exactly the author's own framing: "Process scene detection on all given frames, rank-orders, returns top N results." What you do with those keyframes is the rest of the pack's job.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| frames | IMAGE | — | |
| num_keyframes | INT | 122–4096 | — |
| include_first_frame | BOOLEAN | true | — |
| include_last_frame | BOOLEAN | true | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Keyframes | IMAGE | — |
| Labeled Keyframes | IMAGE | — |