Nodes/CMK Flow/CMK Split Video into Segments
ComfyUI Node

CMK Split Video into Segments

The entry point for long video that doesn't eat your VRAM

By CMKFlow·Created 3 months ago·Updated a day ago· 6
CMK Split Video into Segments
    • SEGMENTS
    • LOG
    • diagnostic
    ◄VIDEO▾►
    ◄MAX FRAMES 720P540►
    ◄MAX FRAMES 1080P240►
    ◄OVERLAP0.0►
    ◄VIDEO CODEClibx264►
    ◄VIDEO BITRATE8000k►
    ◄PRESETfast►

    The naive way to process a video in ComfyUI is to load all of it as one frame batch, and the naive way dies at about four seconds of 1080p on a 12 GB card. CMK Split Video into Segments is the pack's answer: chop the source into overlapping, individually-encodable chunks on disk, hand the rest of the graph a small context object that describes them, and never hold the whole video in RAM. It is the canonical first node of every CMK video workflow.

    It lives in CMK/Toolbox/Video, but you should think of it as the front door of the pack's video path rather than a loose utility. Everything downstream - the FaceSwap video loader, the merge-and-save node, the comparison node - expects the working context this node produces.

    How it works

    The splitting is done by ffmpeg, not by Python decoding into tensors. CMK probes the source first for width, height, fps, duration and frame count, then picks a segment length and shells out to ffmpeg per range.

    Two parameters set the budget, and the node chooses between them by source height:

    • MAX FRAMES 720P (default 540) applies when the source is 720p or shorter.
    • MAX FRAMES 1080P (default 240) applies above 720p.

    So a 720p clip gets longer segments than a 1080p clip at the same settings - the pixel budget, expressed once. Frame count becomes seconds using the source fps, with two floors that stop you creating a swarm of tiny fragments: at least 180 frames and at least 3 seconds per segment. The tail is handled gracefully - if the last remainder would be shorter than three seconds, the previous segment grows to swallow it.

    OVERLAP (seconds, default 0) is subtracted from the step between segment starts, so adjacent segments share frames. It must be smaller than the effective segment length or the node raises rather than looping forever. Audio rides along as AAC at 192 kbps, always, and the codec parameters you set are applied to every segment.

    The result is written permanently, separated by source, to:

    ComfyUI/output/video/segments/<video_name>/
    

    alongside a segments.json manifest. That manifest is why this node is cheap to re-run: it only reuses an existing split if the source file (size and mtime), every encoding parameter, the output directory, the segment count, order, time ranges and non-empty files all still match. Any change invalidates it, and the public statuses you'll see in the log are REUSED, SPLIT and INVALIDATED.

    Inputs and outputs

    • VIDEO - a dropdown that lists video files found recursively under ComfyUI/input/video/. Absolute paths outside that directory are refused on purpose; put files where the node can see them.
    • MAX FRAMES 720P / MAX FRAMES 1080P - the segment budget, as above.
    • OVERLAP - 0 to 60 seconds, 0.5 steps.
    • VIDEO CODEC - libx264 or hevc, VIDEO BITRATE - a string like 8000k, PRESET - the usual x264/x265 ladder from ultrafast to veryslow.

    Three outputs. SEGMENTS is the one that matters: a CMK_VIDEO_SEGMENTS context carrying the source path, output directory, manifest path, the segment list with their time ranges, and the probed width/height/fps/frame count/duration. It is treated as immutable - downstream nodes read it and are not allowed to mutate it. LOG is documentary only (it never drives processing) and diagnostic carries the preview and metadata panel. There is deliberately no directory-path output; the location travels inside SEGMENTS.

    Wire SEGMENTS into the CMK video nodes you want: the video FaceSwap, the merge/save node, or CMK Video Compare at the end to prove the round trip survived.

    Install

    Manager → search CMK Flow → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/CMKFlow/cmk_nodes
    python3 custom_nodes/cmk_nodes/scripts/install_cmk_requirements.py
    python3 custom_nodes/cmk_nodes/scripts/check_cmk_resources.py --models-root "/path/to/shared/models"
    

    For this node specifically, the interesting dependency is imageio-ffmpeg in the pack's requirements.txt. The node wants an ffmpeg binary and would prefer ffprobe for metadata, but it doesn't require ffprobe: it checks /opt/homebrew/bin, /usr/local/bin, /opt/local/bin, /usr/bin and /bin - macOS Desktop apps inherit a minimal PATH, which is why those absolute paths are in there - and falls back to the ffmpeg imageio-ffmpeg bundles. No ffprobe just means a different metadata reader, and slightly less information later in the comparison node.

    Common issues

    • "VIDEO is missing" or the dropdown is empty. Your file isn't under ComfyUI/input/video/. That directory is the contract, not a suggestion.
    • "OVERLAP must be smaller than the effective segment length." You set an overlap of 30 while a 3-second floor is in play. Lower it.
    • ffmpeg not found. Install it properly (brew install ffmpeg on macOS, distro package on Linux) or confirm imageio-ffmpeg landed cleanly; the error names the executable it was hunting for.
    • Your split is being redone every run. The identity hash includes the source's mtime and size, so re-copying the source into input/video/ invalidates it.
    • Where did my segments go? A ComfyUI restart clears the pack's image boundary caches under ComfyUI/temp/cmk/ - but the video split is the one piece of CMK state with a real cross-session continuation contract. Segments and manifest stay on disk.
    CategoryCMK/Toolbox/Video

    Inputs (7)

    NameTypeDefaultDescription
    VIDEOCOMBO1 options:
    MAX FRAMES 720PINT5401–100000—
    MAX FRAMES 1080PINT2401–100000—
    OVERLAPFLOAT0.00–60—
    VIDEO CODECCOMBOlibx2642 options: libx264, hevc
    VIDEO BITRATESTRING8000k—
    PRESETCOMBOfast9 options: ultrafast, superfast, veryfast, faster, fast, medium, +3

    Outputs (3)

    NameTypeDescription
    SEGMENTSCMK_VIDEO_SEGMENTS—
    LOGCMK_LOG_PIPE—
    diagnosticCMK_DIAGNOSTIC—