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 6 months ago·Updated about 20 hours 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—