Nodes/MediaForge/πŸ” Loop Video
ComfyUI Node

πŸ” Loop Video

Pad a short clip to any length β€” and hide the seam while you're at it

By leon80148Β·Created 4 months agoΒ·Updated 2 months agoΒ· 0
πŸ” Loop Video
  • frames
  • audio
  • final_video_path
β—„video_pathinput/sample.mp4β–Ί
β—„filename_prefixMediaForge/loopedβ–Ί
β—„target_duration_sec30.0β–Ί
β—„loop_modestrictβ–Ί
β—„crossfade_sec1.0β–Ί
β—„speed1.00β–Ί
β—„reversefalseβ–Ί
β—„keep_audiotrueβ–Ί
β—„audio_volume1.00β–Ί
β—„codech264 NVIDIA GPU (h264_nvenc)β–Ί
β—„crf18β–Ί
β—„presetmediumβ–Ί
β—„tensor_fps30.0β–Ί

MF_LoopVideo repeats a clip until it hits a target duration, and it's the node behind every "this is 5 seconds but I need it to be 60" moment: social-media squares that need 15/30/60-second versions of one clip, intro loops, ambient B-roll. It's also a speed node and a reverse node if you need those - speed and reverse are right there in the widget list.

The design question it answers well is how to join the repeats. A hard repeat-and-cut is deterministic and instant but shows a seam every cycle. That's strict mode. ping_pong plays the clip forward, then backward, forward, backward - seam-free back-and-forth that doubles the effective length. crossfade chains FFmpeg xfade transitions between repeats for genuinely smooth loops, capped at 50 loops. If you've ever watched a video loop where the end visibly jumps back to the start, ping_pong or crossfade is the fix.

How it works

strict repeats via FFmpeg's loop filter and cuts to the exact duration. ping_pong uses reverse-chained segments. crossfade builds an xfade chain (and auto-falls back to strict if your crossfade duration is longer than the clip itself - you can't crossfade into a loop that's shorter than the fade). The speed setting uses setpts for video plus an auto-chained atempo for audio, so pitch stays correct when you speed up or slow down.

The inputs that matter

  • target_duration_sec - the output length. The whole point of the node.
  • loop_mode - strict / ping_pong / crossfade. Default strict; reach for crossfade when the seam matters.
  • crossfade_sec - fade length, only used in crossfade mode.
  • speed - 0.25–4.0. Slow-mo or time-lapse in the same encode.
  • reverse - pre-reverse the source before looping.
  • keep_audio / audio_volume - keep the track, and how loud. 0.0 mutes.
  • codec / crf / preset - the usual encode set, smart NVENC default.

Dual-input supported: wire frames + tensor_fps + audio to loop a tensor pipeline's output instead of a file. Output: final_video_path.

Install

Part of MediaForge:

cd ComfyUI/custom_nodes
git clone https://github.com/leon80148/comfyui_MediaForge.git
# restart ComfyUI

Or ComfyUI Manager β†’ "MediaForge".

Common issues

The documented limit is the one that bites: FFmpeg's loop filter buffers up to MAX_LOOP_FRAMES = 32767 frames (INT16). A long source at high fps hits this and errors - the fix is crossfade mode (its xfade chain has no single buffer) or a lower fps. And reverse loads the entire stream into RAM, so reversing a long clip can OOM; cut to a sub-clip first. One more: with strict, the seam is real and visible - if your loop is for anything people will watch for more than a few seconds, ping_pong or crossfade is worth the extra encode time.

CategoryMediaForge/Video

Inputs (15)

NameTypeDefaultDescription
video_pathSTRINGinput/sample.mp4β€”
filename_prefixSTRINGMediaForge/loopedβ€”
target_duration_secFLOAT30.00.1–36000β€”
loop_modeCOMBOstrict3 options: strict, ping_pong, crossfade
crossfade_secFLOAT1.00.1–10β€”
speedFLOAT1.000.25–4β€”
reverseBOOLEANfalseβ€”
keep_audioBOOLEANtrueβ€”
audio_volumeFLOAT1.000–1β€”
codecCOMBOh264 NVIDIA GPU (h264_nvenc)7 options: h264 (libx264), hevc (libx265), av1 (libsvtav1), prores (prores_ks), h264 NVIDIA GPU (h264_nvenc), hevc NVIDIA GPU (hevc_nvenc), +1
crfINT180–51β€”
presetCOMBOmedium9 options: ultrafast, superfast, veryfast, faster, fast, medium, +3
framesoptIMAGEβ€”
tensor_fpsoptFLOAT30.01–240β€”
audiooptAUDIOβ€”

Outputs (1)

NameTypeDescription
final_video_pathSTRINGβ€”