ComfyUI Node

LatestVideoFromFolder

Feed the last video back into the loop — automatically

By heheok·Created about a year ago·Updated about a year ago· 2
LatestVideoFromFolder
    • latest_video_path
    folder_path./output/videos
    trigger0

    The whole trick behind "infinite" video with Wan 2.1 VACE is that every new segment is conditioned on the tail of the one before it. So the question that decides whether your workflow is hands-off or painful is: how does the graph know what the last segment was? This node is the answer - it watches a folder, finds the newest .mp4, and hands back its path so the next generation can continue from it. It's the automatic closing of the loop in heheok's comfyui_wan2.1_vace_infinite_helpers pack.

    How it works

    Two inputs: folder_path (a plain string, default ./output/videos) and a dummy trigger INT. One output: latest_video_path - a path string, not a video object. Internally it globs every *.mp4 in the folder, picks the one with the newest modification time, and returns its absolute path. In the author's reference workflow that string goes into VHS_LoadVideoPath (from VideoHelperSuite), which turns it into frames for the control branch of the graph.

    The trigger input and an always-True IS_CHANGED are doing real work here. ComfyUI caches node outputs; without forcing re-execution, this node would evaluate once, cache the path, and keep feeding you the first video forever. The whole point is that it checks the folder on every queue run, because the folder contents changed since the last generation. This is the node you leave alone and let do its job.

    Set up two folders

    The README is emphatic about this, and it's good advice: keep your generated videos in two separate locations. One folder holds the full, un-padded segments - the pieces you'll merge by hand at the end into your long-form video. The other holds the padded control versions, and that second one is what this node should be pointed at. The padded versions carry the gray buffer that makes the handoff to the next segment smooth; pointing the loop at the full ones will technically work but loses that transition logic.

    Use an absolute path. The ./output/videos default resolves relative to wherever ComfyUI was launched from, and that's a great way to end up staring at a "not a valid directory" error.

    The first-run rule - don't skip it

    This is the one that trips everyone, straight from the author's own README: for the very first segment, you must disable the group that handles "previous video to control video." There is no previous video yet - the folder is empty, the node throws, or worse, it silently conditions on nothing. Generate segment one with that group bypassed, then re-enable it for every subsequent generation. The workflow lives or dies on this toggle.

    What will bite you

    • .mp4 only. The glob is hard-coded to *.mp4. No webm, no mov, no AV1 container. If your save node writes something else, this returns "No .mp4 files found in the folder."
    • Empty or missing folder → a FileNotFoundError (no mp4s) or a ValueError (path isn't a directory). Both fail loudly, which is at least honest.
    • Newest by mtime, not by filename. That's usually what you want, but if you're copying files around, an old file that just got touched will be picked.

    Install

    Via ComfyUI Manager (search comfyui_wan2.1_vace_infinite_helpers) or:

    cd path/to/ComfyUI/custom_nodes
    git clone https://github.com/heheok/comfyui_wan2.1_vace_infinite_helpers
    

    Restart ComfyUI. No requirements.txt, nothing extra to install - it's os, pathlib, and a glob. The heavy lifting (Wan 2.1 VACE weights, Kijai's wrapper, VideoHelperSuite) comes from elsewhere in your stack.

    Verdict: it's a five-line utility dressed as a node, and that's fine - it exists to keep the loop honest. The real win is that combined with PrepareControlVideo and the cyclic prompt node, you get a loop you can leave running overnight.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    folder_pathSTRING./output/videos
    triggerINT0

    Outputs (1)

    NameTypeDescription
    latest_video_pathSTRING