Nodes/ComfyUI-BETA-Cropnodes/Select Sharpest Frames 🎯 πŸ…‘πŸ…”πŸ…£πŸ…
ComfyUI Node

Select Sharpest Frames 🎯 πŸ…‘πŸ…”πŸ…£πŸ…

Best-of-N sampling from a video batch

By Burgstall-labsΒ·Created about a year agoΒ·Updated 6 months agoΒ· 8
Select Sharpest Frames 🎯 πŸ…‘πŸ…”πŸ…£πŸ…
  • images
  • selected_frames
  • rejected_frames
β—„interval5β–Ί
β—„window_size3β–Ί

Videos are mostly blur, if we're honest - motion blur, focus pull, compression junk. If you're building a thumbnail, a contact sheet, or a training dataset from a video batch, you don't want a random slice; you want the sharp frames. Select Sharpest Frames walks your image batch at a regular interval and, around each stop, picks the single sharpest frame from a small window. Feed it 100 frames, tell it interval 5 / window 3, and you get back roughly one well-chosen frame per 5, with the losers handed to a second output so you can see what it rejected.

The sharpness test is the standard computer-vision one: the variance of the Laplacian, computed on a grayscale version of each frame via OpenCV. Higher variance = more edge energy = sharper. It's not a perfect perceptual metric - a heavily textured frame can score high even when slightly out of focus - but for "which of these 5 frames is least blurry" it's remarkably reliable, and it's what a lot of auto-focus code has used for decades.

Three inputs:

  • images - your video frame batch (IMAGE).
  • interval - step through the batch every N frames (default 5).
  • window_size - how many frames around each stop get compared (default 3, centered on the anchor).

Outputs are selected_frames and rejected_frames, both IMAGE batches. Note the window gets clamped at the batch edges, so the first and last windows can be smaller than window_size - the very first window sits centered on frame 0, which means half of it doesn't exist. And rejected_frames is just every non-winning frame from every window, so its size varies and it isn't grouped; it's for eyeballing what got cut, not for reconstructing the original.

Install is the pack install: ComfyUI Manager β†’ search "BETA" or "Burgstall" β†’ ComfyUI-BETA-Cropnodes (renamed ComfyUI-BETA-Helpernodes; both names work). Or clone:

cd ComfyUI/custom_nodes
git clone https://github.com/Burgstall-labs/ComfyUI-BETA-Cropnodes

restart. This node specifically needs opencv-python, which the pack's requirements install - if you installed the pack before requirements were added, you may need pip install opencv-python in your ComfyUI environment, otherwise the node import fails with a cv2 error.

The thing to keep in mind: interval and window_size are a trade-off you tune once. A big window around a small interval gives you heavy overlap (lots of duplicate sharpness measurements), while a small window means you're trusting a single anchor. For thumbnail work, interval 5 / window 3 is a sane starting point; for dataset curation where you want one genuinely great frame per second of footage, you'll want a larger window and to accept more compute. And if a section of your video is just blurry everywhere - camera shake, no sharp frame exists - the node still picks the least-bad one, because something has to win.

CategoryBurgstall Enabling The Awesomeness

Inputs (3)

NameTypeDefaultDescription
imagesIMAGEβ€”
intervalINT51–1000β€”
window_sizeINT31–20β€”

Outputs (2)

NameTypeDescription
selected_framesIMAGEβ€”
rejected_framesIMAGEβ€”