Nodes/cspnodes/Vid Dir Iterator
ComfyUI Node

Vid Dir Iterator

Step through a folder of video files, returns a path not frames

By cerspense·Created 2 years ago·Updated 7 months ago· 36
Vid Dir Iterator
    • STRING
    directory_path
    glob_patterns**/*.mp4, **/*.mov
    video_index0
    sort_by
    sort_order
    randomize_final_listfalse

    The video counterpart to this pack's ImageDirIterator, but simpler - it doesn't decode or load anything. It just walks a folder of video files and hands you back a file path, string in, string out.

    How it works

    Point it at a directory with one or more comma-separated glob patterns (default **/*.mp4, **/*.mov, and ** recurses into subfolders), it matches and filters down to .mp4/.mov files, sorts the whole matched list by your chosen key, and optionally shuffles the final result if randomize_final_list is on. One real difference from its image sibling worth knowing: ImageDirIterator groups files by subdirectory and sorts within each group separately before combining; this node doesn't - it sorts the entire flat list of matched videos as one set, subdirectories or not. The index wraps around via modulo, so running past the end of the list just loops back to the start instead of erroring.

    The inputs and outputs that matter

    • directory_path / glob_patterns - where to look and what to match.
    • video_index - which file to select, with automatic wraparound.
    • sort_by - date_modified, name, size, or random.
    • sort_order - ascending or descending.
    • randomize_final_list - shuffle after sorting.

    There's no batch_size here - unlike the image version, this node returns exactly one file per call. Output: a single STRING, the full path to the selected video file - not the video itself. You still need a proper video-loading node downstream (something like VideoHelperSuite's Load Video) to actually decode it into frames.

    What it's actually for

    The obvious pairing is a video-to-video pipeline: point this at a folder of source clips, feed the path it returns into a video loader, decode to frames, and send those into something like this pack's own Modelscopev2v. It's just as useful for plain batch processing - running a folder of raw footage through the same operation one file at a time across separate queue runs, using video_index to step through the folder deterministically.

    Installing it

    Search cspnodes in ComfyUI Manager, or clone it directly:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cerspense/ComfyUI_cspnodes
    

    Restart after. The pack's single Python file imports diffusers and pymediainfo unconditionally at the top for other nodes in the pack - if cspnodes doesn't appear in your node list at all, check your startup log for one of those two imports failing before troubleshooting this node specifically.

    Where people get tripped up

    The same numeric-only name-sort quirk from ImageDirIterator applies here too, since it's the exact same sort logic: sort_by: "name" extracts only the digit characters from a filename and sorts by that as a number, not a normal alphabetical sort. A file like clip_final.mp4 has no digits in its name and will sort as if it were 0, jumping to one end of the list regardless of what its name suggests.

    And if you get a "no valid video files found" error, it's almost always the glob pattern rather than the directory - only files ending in .mp4 or .mov make the final cut no matter what your pattern says, so a folder full of .mkv or .webm files will match nothing even with a pattern that technically globs them.

    Categorycspnodes

    Inputs (6)

    NameTypeDefaultDescription
    directory_pathSTRING
    glob_patternsSTRING**/*.mp4, **/*.mov
    video_indexINT0
    sort_byCOMBO4 options: date_modified, name, size, random
    sort_orderCOMBO2 options: ascending, descending
    randomize_final_listBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    STRINGSTRING