Nodes/TrentNodes/Video Folder Cowboy
ComfyUI Node

Video Folder Cowboy

The Batch Video Iterator That Keeps vid1 < vid2 < vid10

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Video Folder Cowboy
    • frames
    • filename
    • total_videos
    • file_path
    • frame_count
    • fps
    directory
    patterns**/*.mp4, **/*.avi, **/*.mov, **/*.mkv, **/*.webm
    video_index0
    sort_byname
    sort_orderascending
    frame_skip0
    max_frames0
    start_frame0
    index_modewrap
    sort_subdirstrue
    randomize_finalfalse

    If you've ever written a video batch pipeline by hand, you know the pain that this node exists to kill: you point a loader at a folder, and vid10.mp4 loads before vid2.mp4 because that's what plain lexicographic sort gives you. Video Folder Cowboy is a directory iterator that sorts filenames naturally - splitting text and numeric chunks so vid1 < vid2 < vid10 actually holds - then hands you one video's frames as an IMAGE batch, indexed by a simple counter.

    This is the load-once-iterate-many node that sits at the front of per-clip render pipelines. You wire the counter into a queue loop, and each run loads the next clip. It's also the reason the pack has a whole cowboy family: wire this node's filename output into TextFileCowboy and RefFolderCowboy and clip 000.mp4 automatically pairs with prompts/000.txt and refs/000/ - a whole keyed batch system with zero naming pain.

    How it works

    The node globs your folder (default pattern **/*.mp4, **/*.avi, **/*.mov, **/*.mkv, **/*.webm), sorts the matches, then loads frames with OpenCV: BGR→RGB conversion, float normalization to 0–1. The frame-skip and limit controls do the heavy lifting for big files - you can load every 4th frame or cap at 30 frames, which is how you preview a long clip without importing it all.

    The inputs that matter

    • video_index - which file in the sorted list to load. This is the knob your loop turns.
    • sort_by - name (natural sort) is the default and usually what you want; you can also sort by date_modified, size, random, or none.
    • index_mode - what happens when the index overruns the file count: wrap (default, back to the start), clamp (stick at the last file), or error (raise). Wrap is perfect for infinite queue loops; error is what you want when a missing clip should stop the run, not silently repeat.
    • frame_skip, max_frames, start_frame - skip N frames between loads (0 = every frame), cap total frames (0 = all), and skip to a starting frame index.

    Outputs

    Six of them, and they're all actually useful: frames (the IMAGE batch), filename (no extension - this is what the cowboy pairings key on), total_videos, file_path (full path), frame_count, and fps. The last one matters more than beginners expect, because downstream VHS and Combine nodes want real FPS rather than a guess.

    Troubleshooting

    Where people get burned: forgetting that frame_skip counts between loaded frames, so frame_skip=3 loads every 4th frame, not every 3rd. And if you're feeding these frames straight into a Wan 2.1 sampler and hitting errors, the frame count is your problem, not the loader - Wan wants 4x+1 frames (81, 97…), so run the frames through the pack's Wan2.1 Frame Adjuster first. randomize_final is there if you want a shuffled deck; sort_subdirs (on by default) keeps subdirectory processing deterministic.

    Installing

    TrentNodes installs once and gives you the whole Trent/ menu. Easiest: ComfyUI Manager → search "Trent Nodes" → Install. If Manager complains about the pack being flagged (a day-one repo rename left a duplicate in the registry that still trips the unsafe check), clone it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TrentHunter82/TrentNodes
    cd TrentNodes
    pip install -r requirements.txt
    

    Restart ComfyUI and you're done. This node only really needs OpenCV, which the pack pulls in anyway.

    CategoryTrent/Video

    Inputs (11)

    NameTypeDefaultDescription
    directorySTRINGRoot directory to search for video files
    patternsSTRING**/*.mp4, **/*.avi, **/*.mov, **/*.mkv, **/*.webmComma-separated glob patterns for matching files
    video_indexINT00–999999Index of the video to load
    sort_byCOMBOnameSorting method: name uses natural sort
    sort_orderCOMBOascendingSort direction
    frame_skipoptINT00–120Skip N frames between each loaded frame (0 = load every frame)
    max_framesoptINT00–9999Maximum frames to load (0 = all frames)
    start_frameoptINT00–999999First frame index to start loading from
    index_modeoptCOMBOwrapHow to handle index overflow
    sort_subdirsoptBOOLEANtrueSort subdirectories alphabetically
    randomize_finaloptBOOLEANfalseShuffle entire list after sorting

    Outputs (6)

    NameTypeDescription
    framesIMAGEVideo frames as image batch
    filenameSTRINGFilename without extension
    total_videosINTTotal number of videos found
    file_pathSTRINGFull file path of loaded video
    frame_countINTNumber of frames loaded
    fpsFLOATVideo FPS (frames per second)