Nodes/ComfyUI-Mango-Random/随机视频路径
ComfyUI Node

随机视频路径

Random video frames for a workflow that runs on images

By mango-rgb·Created 2 years ago·Updated 2 years ago· 2
随机视频路径
    • images
    • path
    • text_content
    directory_path
    sort_mode
    seed0

    RandomVideoPathNode reaches into a folder, picks a video, and hands you its frames - plus the path and any matching caption text. It's the video sibling of RandomImagePathNode, built for the many image-based pipelines that want a clip's frames as inputs: frame interpolation, first-frame conditioning, AnimateDiff-style work, or just sampling a video dataset one clip at a time.

    It looks for .webm, .mp4, .mkv, and even .gif, recursing through subfolders. Same two Chinese-labeled modes as the rest of the pack: 完全随机 (fully random) and 顺序循环 (sequential cycle). Cycle mode sorts by filename and walks in order; random mode reseeds with your seed before picking - so unlike its image-path sibling, the seed here is genuinely honored. Fix the seed, get the same clip.

    Inputs and outputs

    • directory_path - required, absolute path to a folder with videos. Bad path → NotADirectoryError, no videos → FileNotFoundError.
    • sort_mode, seed - mode dropdown and INT seed, same as the image-path node.
    • images (labeled IMAGE, but read this carefully) - the frames of the chosen video, converted from OpenCV's BGR to RGB and normalized to 0–1 floats.
    • path (STRING) - the full path of the picked file, so you know what you got.
    • text_content (STRING) - a same-named .txt sidecar's contents, or No corresponding text file found.

    The gotcha that actually matters

    The images output is not a standard batched IMAGE tensor, and this is where people get burned. The node returns a FrameGenerator object - an iterable that yields one frame tensor at a time. Nodes downstream that expect tensor.shape[0] batch semantics may choke on it. Wire it into nodes that iterate, or stack the frames into a real batch yourself before feeding typical image operations.

    Second real gotcha: the generator reads every frame of the video into RAM up front, storing them all as tensors. A few minutes of 1080p footage is a lot of memory. The node is fine for short clips and GIFs; it will make you sad on long videos. gif being treated as "video" is a bonus - it means the node also works as a random-animation-frame picker.

    How to install

    Same pack, same steps. ComfyUI Manager: search "Mango Random Nodes", Install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/mango-rgb/ComfyUI-Mango-Random-node
    

    then restart. This is the one node in the pack where the real dependencies actually bite: the requirements.txt lists opencv-python and imageio-ffmpeg, and OpenCV (cv2) is what decodes the video. Most ComfyUI installs already have opencv-python lying around, but if the node errors on import, that's the first thing to check:

    pip install opencv-python
    

    No model downloads, though.

    Common issues

    Beyond the non-batch output and the memory appetite: captions only exist if your sidecar .txt files match the video basenames, and the frame list is loaded once per execution - the node's IS_CHANGED forces a rerun every queue, so each run re-reads the whole video from disk. Slow for big folders. For sampling a few short clips into an image pipeline, it does the job; for serious video work, look at a purpose-built video tool instead.

    Category🥭 芒果节点/文件

    Inputs (3)

    NameTypeDefaultDescription
    directory_pathSTRING
    sort_modeCOMBO2 options: 完全随机, 顺序循环
    seedINT00–18446744073709550000

    Outputs (3)

    NameTypeDescription
    imagesIMAGE
    pathSTRING
    text_contentSTRING