Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ComfyUI-Martinodes

Collection of naive convenience nodes to avoid long node chains and calculations in ComfyUI when working with videos and audios. Especially useful for extending/prefixing videos.

DISCLAIMER: many parts were generated by AI. I invented input/output interfaces and tried to review and follow along to see if everything makes sense.

image

Installation

You'll need a git client. Open your terminal or command window, navigate to your custom_nodes and run git clone https://github.com/progmars/ComfyUI-Martinodes.git

Dependencies

Depends on librosa for audio resampling operations:

pip install librosa

or with embedded Python:

python -m pip install librosa

Nodes

Media head or tail (MediaSlicer)

Takes a slice with requested length from the start or the end of the loaded media. If using both audio and video, the inputs must be the same length.

  • Inputs: images (optional), audio (optional)
  • Parameters:
    • duration_seconds: Length of the slice to take.
    • video_fps: Frame rate for video calculation.
    • take_from: "start" or "end".

Trim media (MediaTrimmer)

Trims video and/or audio from any end.

  • Inputs: images (optional), audio (optional)
  • Parameters:
    • trim_seconds: Amount of time to trim.
    • video_fps: Frame rate for video calculation.
    • trim_from: End to trim from ("start", "end").

Audio info (AudioInfo)

Retrieves information about the audio, passing the audio through for convenience.

  • Inputs: audio
  • Outputs:
    • duration: Duration in seconds.
    • samplerate: Sample rate in Hz.
    • channels: Number of audio channels.

Resample audio (AudioResampler)

Resamples audio to the target samplerate and channels. Useful when concatenating audios from different sources.

  • Inputs: audio
  • Parameters:
    • samplerate: Target sample rate in Hz (e.g., 24000, 44100).
    • channels: Target channels (1 for Mono, 2 for Stereo).

Ensure audio duration (AudioTrimExtender)

Makes audio to have the specified duration, cropping or padding with silence as needed.

  • Inputs: audio
  • Parameters:
    • duration_seconds: Target duration.
    • pad: Where to add silence if too short ("start" or "end").
    • crop: Where to cut if too long ("start" or "end").

Concatenate media (MediaOverlappingConcatenator)

Concatenates two videos and/or audios, applying overlapping logic (crossfade or simple join). If incoming audio channels or samplerates do not match, they will be resampled to the highest samplerate and channels of both audios.

  • Inputs: images_1, audio_1, images_2, audio_2 (all optional, but need pairs to work meaningfully)
  • Parameters:
    • overlap_duration_seconds: Duration of the overlap/crossfade.
    • video_overlap_resolve: How to handle video overlap ("crossfade", "images_1", "images_2").
    • audio_overlap_resolve: How to handle audio overlap ("crossfade", "audio_1", "audio_2").

Concatenate video+audio latents (LatentOverlappingConcatenator)

Concatenates two video+audio latents, applying overlapping logic (crossfade or simple join) similar to Concatenate media, but operating directly on latents instead of decoded video/audio.

Currently supports MiniMax H3 only, but was developed with separated configurable parameters to port to other models if needed.

The requested overlap duration is snapped to latent token counts using the same temporal compression rules as LatentAVMaskedExtender, so overlaps stay aligned with the model's token grid.

  • Inputs: av_latent_1, av_latent_2 (both optional; if only one is provided, it is passed through unchanged)
  • Parameters:
    • video_fps: Frame rate used to calculate synchronized video and audio token lengths.
    • overlap_duration_seconds: Duration of the overlap/crossfade. 0 performs a plain concatenation.
    • video_overlap_resolve: How to handle the video overlap ("crossfade", "av_latent_1", "av_latent_2").
    • audio_overlap_resolve: How to handle the audio overlap ("crossfade", "av_latent_1", "av_latent_2").
  • Outputs: av_latent

Extend video+audio latent (LatentAVMaskedExtender)

Extends a combined video+audio latent by using the requested duration from the head (prepend_head mode) or tail (extend_tail mode) of a loaded latent and using the remaining portion of an empty latent for generation.

Currently supports MiniMax H3 only, but was developed with separated configurable parameters to port to other models if needed.

The output latent can then be passed to the sampler for generating the remaining part. Just plug the node between MiniMax H3 Reference to Video or MiniMax H3 Image to Video or even MiniMax H3 Easy Output if using nkxx188/ComfyUI-MiniMaxH3-Easy, and your sampler.

For convenience, the node accepts empty loaded_av, in which case the target_av will be passed through. Thus the node can be safely left enabled even when using a disabled LoadAVLatent node as input.

The implementation requires the latest ComfyUI with native masking PR 15375 merged.

  • Inputs:
    • target_av: The latent prepared by default ComfyUI workflows before passing it to a sampler.
    • loaded_av: (optional) The loaded latent to use for head/tail overlapping.
  • Parameters:
    • mode: extend_tail or prepend_head
    • overlap_duration_seconds: Duration of the loaded video head/tail to preserve. The part will be overlapped onto the end/beginning of the target_av latent, thus total length of the video will not be changed.
    • video_fps: Frame rate used to calculate synchronized video and audio token lengths.
    • video_fade_seconds and audio_fade_seconds: To soften transitions. Higher values of 0.5 or more usually are needed for prepend_head mode.
    • trim_freeze_tail and freeze_threshold: Might help in cases when the latent ends with a frozen part (sometimes happens with FLF2V). WARNING: Not tested in action, so might be totally useless.
  • Outputs: av_latent with a noise_mask covering the preserved video and audio tails.

How to prompt

For extending, use something like this:

summary:
[reference generation + video continuation] The target video is continuation of <Video 1> and <Audio 1>. 

detailed_description:
Shot seamlessly continues <Video 1> and <Audio 1> with ... 

For prepending, there seems to be no official guide, but I found that this works:

summary:
[reference generation + video prepending] The target video prepends <Video 1> and <Audio 2>. 

detailed_description:
Shot with ...
The shot seamlessly continues into <Video 1> and <Audio 1>.

Combine video+audio latent (LatentAVCombiner)

Combines a separate video latent and audio latent into a single MiniMax H3 compatible av_latent, ready to be used by other latent nodes or saved with SaveAVLatent.

  • Inputs: video_latent, audio_latent
  • Outputs: av_latent

Split video+audio latent (LatentAVSplitter)

Splits a combined av_latent into separate video_latent and audio_latent, useful when you want to process or inspect each stream independently.

  • Inputs: av_latent
  • Outputs: video_latent, audio_latent

Video+audio latent info (LatentAVInfo)

Retrieves information from a combined av_latent, while also passing the original latent through for convenience in longer node chains.

  • Inputs: av_latent
  • Outputs:
    • av_latent: Original input latent (passthrough).
    • frames: Estimated number of video frames from latent token count.
    • video_resolution: Video latent spatial resolution as width x height.
    • video_tokens: Number of latent video temporal tokens.
    • audio_tokens: Number of latent audio temporal tokens.

Save video+audio latent (SaveAVLatent)

Saves a video+audio latent to the ComfyUI output directory as a .avlatent safetensors file.

  • Inputs: av_latent
  • Parameters:
    • filename_prefix: Output filename prefix, defaulting to av_latents/latent in ComfyUI output directory.
    • video_filename_prefix: Video filename prefix to combine with the generated latent counter, to identify the related latent easier. When using it, the output video_sync_latent_filename_prefix should be connected to VHS filename_prefix.
  • Outputs:
    • video_sync_latent_filename_prefix: Connect to VHS filename_prefix for adding the saved latent counter value to the filename of the video.

Load video+audio latent (LoadAVLatent)

Loads a previously saved .avlatent file. In contrast to other loaders that look for the latents in input/ folder only, this node loads from the ComfyUI output directory and sorts by newest first, thus enabling convenient roundtripping of saved latents.

The file list is refreshed from the output directory when the node input types are created. You can also refresh it by hitting R in ComfyUI. So, for convenient way of working, generate a video with SaveAVLatent enabled, hit R, select the freshly generated latent and it's ready to be extended.

  • Inputs: file_path
  • Outputs: av_latent

History and acknowledgments

There are multiple other long context extension nodes around that inspired me, but they often seemed overkill and not support my typical use cases well (seed + prompt hunting with low steps, regen the found seed with high steps, save latent, load latent, extend, repeat).

Kudos to drozbay (ablejones) for native masking PR 15375 and providing the example implmenentation with native ComfyUI and Kijai nodes. Unfortunately, native nodes solution becomes like a spaghetti eating somebody alive. That is why this small naive LatentAVMaskedExtender node was born.

After I almost implemented Save & Load latent nodes, I found https://github.com/JerryZRic/comfyui-minimax-h3-latent and used the code to improve my solution.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages