ComfyUI Node

Media Selection

One intake node for uploads, folders, or Reddit — with trimming and resizing built in

By sammykumar·Created 12 months ago·Updated 8 months ago· 6
Media Selection
    • media_path
    • media_type
    • media_info
    • height
    • width
    • duration
    • fps
    media_sourceReddit Post
    media_typeimage
    seed0
    media_path
    uploaded_image_file
    uploaded_video_file
    reddit_url
    subreddit_url
    max_duration0.0
    resize_modeNone
    resize_width832
    resize_height480

    Every captioning workflow starts with the same question: where does the media come from? Media Selection is the pack's single answer to that - one node that pulls images or videos from four different sources, optionally trims and resizes them, and hands you a clean, normalized result with all the metadata you'd otherwise probe for by hand.

    The media_source dropdown is the heart of it, with four modes:

    • Upload Media - you pick a file through the upload widget (uploaded_image_file / uploaded_video_file).
    • Randomize Media from Path - give it a media_path (a directory, searched recursively) and it picks a random file. This is the batch-captioning mode: point it at a folder of images and let the seed step through them.
    • Reddit Post - paste a reddit_url and it downloads the post's media.
    • Randomize from Subreddit - give it a subreddit URL or name (r/pics or https://www.reddit.com/r/pics/) and a seed, and it grabs a random post. Great for stress-testing captioning against uncontrolled content.

    Alongside that, media_type (image/video) and seed (only for the two randomize modes - and the tooltip's warning is the real deal: change the seed to force re-execution, because a cached result won't re-randomize on its own).

    Then the optional normalization knobs. max_duration trims videos longer than N seconds to the first N (0 = keep the whole thing). resize_mode gives you None (original), Auto (by orientation) - which snaps to 832×480 landscape / 480×832 portrait, the Wan-flavored defaults used across the pack - or Custom, with resize_width/resize_height to specify. That auto mode is the one most people want: it lands your media on the pack's native canvas sizes before captioning, so the width/height outputs downstream match what a Wan T2I pass expects.

    Outputs are a full media dossier: media_path (the resolved file path), media_type, media_info (a text summary - title/source/file size for Reddit, or a processing info block), plus height, width, duration, and fps as separate typed outputs. That last quartet is the underrated part - duration and fps for video, dimensions for both - so downstream nodes (Frame Extractor, Media Describe's dimension inference) don't have to re-probe the file.

    Installing

    Part of Swiss Army Knife:

    • ComfyUI Manager: search "Swiss Army Knife", install, restart.
    • Manual:
    cd ComfyUI/custom_nodes
    git clone https://github.com/sammykumar/ComfyUI-SwissArmyKnife.git
    cd ComfyUI-SwissArmyKnife
    pip install -e .
    

    Gotchas

    • Reddit modes hit the network and can be flaky - rate limits, deleted posts, and type mismatches (a subreddit meant for images serving a video) all happen. The node warns on type mismatch and uses what it actually detected.
    • Randomize + seed caching: the seed is both the randomizer and the re-execution trigger. Same seed, same pick; new seed, new pick.
    • Directory mode is recursive - the tooltip says "including all subdirectories," so point it somewhere you actually want searched.
    • Media Selection outputs a path, not a tensor. That's deliberate - the rest of the pack consumes paths.

    It's the intake valve for the whole pipeline. Once you've got Media Selection feeding Media Describe, the captioning loop runs on whatever you throw at it - one file or a thousand.

    CategorySwiss Army Knife 🔪/Utils

    Inputs (12)

    NameTypeDefaultDescription
    media_sourceCOMBOReddit PostChoose whether to upload media, randomize from a directory path, download from a Reddit post, or randomize from a subreddit
    media_typeCOMBOimageSelect the type of media to process
    seedINT00–18446744073709550000Seed for randomization when using 'Randomize Media from Path' or 'Randomize from Subreddit'. Use different seeds to force re-execution.
    media_pathoptSTRINGDirectory path to randomly select media from, including all subdirectories (used when media_source is Randomize Media from Path)
    uploaded_image_fileoptSTRINGPath to uploaded image file (managed by upload widget)
    uploaded_video_fileoptSTRINGPath to uploaded video file (managed by upload widget)
    reddit_urloptSTRINGReddit post URL (used when media_source is Reddit Post)
    subreddit_urloptSTRINGSubreddit URL or name (e.g., 'r/pics' or 'https://www.reddit.com/r/pics/') - used when media_source is Randomize from Subreddit
    max_durationoptFLOAT0.00–300Maximum duration in seconds for videos (0 = use full video). Video will be trimmed if longer.
    resize_modeoptCOMBONoneResize mode: None (original size), Auto (832x480 landscape, 480x832 portrait), Custom (specify dimensions)
    resize_widthoptINT83264–8192Target width for Custom resize mode
    resize_heightoptINT48064–8192Target height for Custom resize mode

    Outputs (7)

    NameTypeDescription
    media_pathSTRING
    media_typeSTRING
    media_infoSTRING
    heightINT
    widthINT
    durationFLOAT
    fpsFLOAT