Get Video Counter In Output Folder
Counting Videos Is the Boring Node That Saves Your Outputs From Clobbering
- File Counter
One input, one integer output, zero drama. GetVideoFileCountInOutputFolder peeks into a folder inside ComfyUI's output directory, counts the .mp4 files there, and hands you a number you can use to name the next video you save. It's the video twin of the same pack's PNG counter, and it exists for one reason: video generation costs you minutes per run, and the last thing you want is a save node clobbering last run's file because it didn't get a fresh name.
Where you feel the pain: any Wan, LTX Video, or AnimateDiff workflow where every clip is a several-minute commitment. ComfyUI's video savers either auto-rename in ways you can't predict or happily overwrite if you've hardcoded a filename. Numbering each output - 00007 - walk.mp4, 00008 - walk.mp4 - makes every run a separate file and gives you a stable name to drag into a video editor or a V2V pass later.
How it works
The node joins whatever you type into path with ComfyUI's configured output directory (folder_paths.get_output_directory() - usually ComfyUI/output), then does three things:
- If the folder doesn't exist or is empty, it returns
0. No folder is created for you. - Otherwise it counts every file ending in
.mp4(case-insensitive). - If files carry a leading numeric prefix like
00000 - prompt.mp4, it parses those digits and returns the highest prefix plus one, so your next file gets the next number.
That last bit is the point. The author's own naming convention is "00000 - prompt.png", and this node is the "what number comes next" logic for that convention, applied to video. It returns whichever is larger - the raw file count or the prefix-based next number - so a folder with 8 files whose highest prefix is 00010 reports 11.
Two honest gotchas from reading the source rather than the README. First, the README claims it "adds a directory if none of the provided name is present" - the shipped code just returns 0. Create the folder yourself (or let your save node create it first). Second, the prefix scanner walks every prefixed file and increments each time, which is fine for a clean 00000…00007 sequence but can overshoot on a folder with mixed or sparse prefixes. Keep your numbering tidy and it's exact.
The one piece of machinery worth knowing: IS_CHANGED returns float("NaN"), the classic "always rerun" idiom the ComfyUI docs warn about. A counter must re-read the folder every run, so that's correct behavior here - just don't stick this node upstream of a big expensive model, because it'll defeat the cache for everything behind it.
Inputs and outputs
There's one input, path (STRING). The author's tooltip says it all: "Path under the configured output directory." It's relative - type video for output/video, not an absolute path. One output: File Counter (INT), which you feed into filename construction.
Wiring it up
The natural pairing is with the pack's own FormatIntToString node, which pads an int with leading zeroes. Wire the counter into it, set digits to 5, then concatenate the result into a filename and hand it to your video saver (VHS SaveVideo takes a filename input, as do most others):
GetVideoFileCountInOutputFolder (path: "video")
→ FormatIntToString (use digits: true, digits: 5)
→ concat with " - walk.mp4"
→ SaveVideo filename
Install
Zero dependencies, zero model downloads - it's pure Python against ComfyUI's own folder_paths, so there's no requirements.txt to trip over. Either grab it in ComfyUI Manager (search "ComfyUI_KaleidiaNodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/Kaleidia/ComfyUI_KaleidiaNodes
Then restart ComfyUI.
Common issues
- Always returns 0. Wrong folder or the folder doesn't exist yet. Remember the path is relative to your output directory, and this node won't create it.
- "I save .webm and it still says 0." It only counts
.mp4. If your saver writes WebM (common in some VHS setups), the counter will sit at 0 forever. Save as mp4 or skip this node. - Weird big numbers on a messy folder. That's the prefix-scan increment quirk above. Rename old files to a clean sequence and it settles down.
It's a small, stubbornly useful tool - the kind of thing you forget exists until a save node silently eats a twenty-minute render. Add the counter, name your files, move on.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| File Counter | INT | — |