Nodes/Story JSON Nodes/Video Last Frame
ComfyUI Node

Video Last Frame

Grab the last frame of a scene clip to seed the next shot

By stepan-bogatorjov·Created 6 months ago·Updated 2 months ago· 0
Video Last Frame
    • image
    • video_path
    ◄index1►
    ◄scenes_folder►

    VideoLastFrame pulls the final frame out of a scene video and hands it back as a standard IMAGE tensor. In the Story JSON Nodes pack (stepan-bogatorjov/comfy_scenes_json_node), that's the seed for the next scene: image-to-video generation wants to start from where the last shot ended, and this node is how you get there without hunting through the video in a player.

    Think of it as a bridge between the video half of the pipeline and the image half. The compiler produces 1_1.mp4, 2_1.mp4, 3_1.mp4 - scene number, underscore, counter. Given index = 2, this node finds the 2_<n>.mp4 matching that scene (taking the highest counter if there are several), decodes its final frame, and returns it. That frame is exactly the continuity point: feed it back into your image-to-video model as the start of scene 3, or use it as a style/consistency reference.

    How it works

    It scans the scenes folder for files matching ^(\d+)_(\d+)\.mp4$, picks the match for your index, and decodes the true last frame with ffmpeg. The clever bit: it seeks to near the end (-sseof -3) and lets every frame overwrite a single output file (-update 1), so whatever remains on disk is genuinely the last decoded frame - not the first frame past a seek point, which is the naive approach's failure mode. It needs ffmpeg, found on PATH or via the imageio-ffmpeg fallback.

    Inputs and outputs

    • index - which scene number (default 1).
    • scenes_folder - optional; a subfolder under ComfyUI's output/, matching StoryFinalCompile's scenes_folder convention. Empty means output/ itself.
    • image (IMAGE) - the decoded last frame.
    • video_path (STRING) - the absolute path of the clip it came from.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/stepan-bogatorjov/comfy_scenes_json_node
    

    Restart ComfyUI (or install via Manager under "Story JSON Nodes"). Then make sure ffmpeg is available - either on your system PATH or with pip install imageio-ffmpeg into the same Python ComfyUI runs.

    Troubleshooting

    No matching video means a hard FileNotFoundError with a message telling you exactly what pattern it wanted ('2_<n>.mp4' in the folder). If you get it, check two things: the scene number (are your clips named 2_1.mp4 or 02_1.mp4?) and the folder - on Windows, the hardcoded path separators in the folder resolution are handled, but a wrong scenes_folder means it's looking in the wrong place entirely. Also, this node reads files from disk rather than the graph, so it won't work mid-run on a video that hasn't been saved yet - run it after SaveVideoPassthrough has done its job.

    Categoryimage

    Inputs (2)

    NameTypeDefaultDescription
    indexINT10–999999—
    scenes_folderoptSTRING—

    Outputs (2)

    NameTypeDescription
    imageIMAGE—
    video_pathSTRING—