Video Frame Extractor (MEC)
Pull one frame out of a video batch without the Python
- images
- frame
- total_frames
- is_video
Working on video in ComfyUI means everything comes in as one big frame batch: a (B, H, W, C) IMAGE tensor where B is your frame count. Samplers and most nodes are happy with that, but every so often you need one frame - the first one to build a mask on, the last one to preview, a specific frame to test a prompt against. VideoFrameExtractorMEC is the grab-one-frame node from the ComfyUI-CustomNodePacks pack (the MEC suite), and it's about as small a node as that pack ships.
It also quietly solves a confusion that trips up beginners: "is this video or not?" The node tells you. When you feed it a single image it passes it through untouched and reports is_video=false; when you feed it a batch it selects one frame and reports the truth.
How it works
Trivial under the hood - a slice along the batch axis - but the wrapper is what's useful. You give it the batch and a mode:
first- always frame 0. Default.last- the final frame.middle-B//2, the middle frame.specific_frame- use theframe_indexinput, 0-based.
Whatever you pick, the index is clamped to the batch length, so asking for frame 9999 on a 30-frame video gives you the last frame instead of a crash. That clamping is the sort of defensive detail that keeps this node painless.
Inputs and outputs
Inputs:
images(IMAGE) - your batch.mode- first / last / middle / specific_frame.frame_index(INT, default 0) - only used inspecific_framemode.
Outputs:
frame(IMAGE) - the extracted frame, shape(1, H, W, C), ready to feed any single-image node.total_frames(INT) - how many frames were in the input batch.is_video(BOOLEAN) - true when the input was a batch of more than one frame.
The total_frames output is the sleeper useful one - you can wire it into a Loop or a TextTemplate-style prompt so downstream nodes know how long the clip is without you counting.
Where it fits
Classic MEC-pack pattern: extract frame 0, draw a mask on it with the pack's Spline Mask or Video Mask Editor, then propagate that mask across the rest of the video. The extractor is the front door to that whole workflow. It's also handy for "hero frame" previews - grab the middle frame, run it through a full-res pipeline, decide if the clip is worth rendering.
Installing it
It's one node in ComfyUI-CustomNodePacks, so:
cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git
then restart ComfyUI, or search "CustomNodePacks" in ComfyUI Manager. Watch for [MEC] Loading MaskEditControl node pack … in the console. No dependencies beyond the pack's own (which you only need in full if you're using the mask/VAE nodes).
The one-line summary
If you keep writing tiny Python "first frame" workarounds, this replaces them. One frame out, count and video-flag in - done.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | Image batch (B,H,W,C). Single images pass through; video batches select one frame. | |
| frame_index | INT | 00–999999 | Which frame to extract (0-based). Clamped to batch length. |
| mode | COMBO | first | Frame selection mode: first: always frame 0 last: final frame middle: middle frame (B//2) specific_frame: use frame_index value |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| frame | IMAGE | — |
| total_frames | INT | — |
| is_video | BOOLEAN | — |