KJNodes/imagegenerated

Decode and Save Video(DecodeAndSaveVideo)

Decodes video frames and audio from latent representations, combines them, and saves as a video file, without keeping intermediate images in memory.

Decode And Save Video

video_latent
audio_latent
video_vae
audio_vae
tiling
fps
25.00
filename_prefix
video/ComfyUI
format
auto
codec
auto
tile_size
512
overlap
64
temporal_size
4096
temporal_overlap
16
KJNodes

Description

The Decode and Save Video node decodes video frames and optional audio from latent representations, combines them, and saves the resulting video directly to a file. It is designed for memory efficiency: decoded frames are written to disk on-the-fly without storing all intermediate images in RAM. This makes it suitable for long or high-resolution videos that would otherwise exceed available memory.

The node expects a latent representation of the video frames (typically produced by a video diffusion model) and an optional latent representation of the audio. Two separate VAE models must be provided: one for decoding the video latent (video_vae) and one for decoding the audio latent (audio_vae – required only if an audio_latent is supplied). The node also supports tiled decoding (spatial and temporal) to further reduce memory usage, configurable via the tiling parameters.

Use this node as the final step in a video generation pipeline to export the result to a common video container format.

Inputs

InputTypeRequiredDefaultNotes
video_latentLATENTYesThe latent representation of the video frames. Typically obtained from a compatible video diffusion model.
audio_latentLATENTNoThe latent representation of the audio frames. If provided, an audio_vae must also be connected. Leave disconnected for silent video output.
fpsFLOATYes25.0Frame rate of the output video. Range: 0 – 999 (step 0.01).
filename_prefixSTRINGYesvideo/ComfyUIPrefix for the saved video file. May include formatting tokens such as %date:yyyy-MM-dd% or node value references like %Empty Latent Image.width%. The node automatically appends a unique suffix to avoid overwrites.
formatCOMBOYesautoOutput container format. Options depend on the available system encoders (e.g., mp4, avi, mkv, webm). auto selects the most widely‑supported format (typically MP4).
codecCOMBOYesautoVideo codec to use. Options depend on system‑installed encoders (e.g., libx264, libx265, libvpx, libaom-av1). auto picks a commonly available codec (usually H.264).
video_vaeVAEYesThe VAE model used to decode the video_latent into pixel frames. Must be compatible with the latent representation.
audio_vaeVAENoThe VAE model used to decode the audio_latent into audio samples. Required when audio_latent is connected.
tilingDYNAMICCOMBOYesTiling mode for video decoding. Dynamic options may include disable (full frame decode), spatial (tile only spatially), temporal (tile only temporally), or both. The exact choices depend on the node implementation and the connected VAE.
tile_sizeINTYes512Width/height of each spatial tile. Smaller values reduce peak memory usage but increase decode time. Range: 64 – 4096 (step 32). Only used when spatial tiling is active.
overlapINTYes64Overlap (in pixels) between adjacent spatial tiles. Higher overlap reduces visible seams at tile boundaries, at the cost of more memory and processing time. Range: 0 – 4096 (step 32).
temporal_sizeINTYes4096Number of frames to decode at once when temporal tiling is enabled. A value larger than the total frame count effectively disables temporal tiling. Only relevant for video VAEs that support temporal tiling. Range: 8 – 4096 (step 4).
temporal_overlapINTYes16Number of overlapping frames between consecutive temporal chunks. Higher overlap can smooth out temporal seams, but uses more memory and increases decode time. Range: 4 – 4096 (step 4).

Tiling behaviour

  • When tiling is disabled, the entire frame is decoded at once – this uses the most memory.
  • Spatial tiling (tiling = "spatial" or "both") splits each frame into smaller tiles of size tile_size×tile_size, decodes them independently, and blends overlapping regions.
  • Temporal tiling (tiling = "temporal" or "both") splits the frame sequence into chunks of temporal_size frames, each chunk overlapping by temporal_overlap frames. Only applicable for VAEs that support temporal decomposition (e.g., some video VAEs).
  • The node automatically handles the blending of overlapping regions and tile borders.

Outputs

This node has no output connections. The decoded video is written directly to disk using the path constructed from filename_prefix. The node does not return any data to the workflow.

Usage Notes

  • Memory management: The node streams decoded frames to disk as they are produced. Even with tiling disabled, it will not accumulate all frames in memory simultaneously. Tiling further reduces peak memory at the cost of slower decoding.
  • Audio: To include audio, provide both an audio_latent and an audio_vae. The audio VAE must match the audio latent space (e.g., from an audio diffusion model). If no audio latent is connected, the output video will be silent.
  • Format and codec support: The available formats and codecs depend on the FFmpeg (or other encoder) installation on your system. Use auto for a hassle‑free experience; if you need a specific codec or container, ensure the required encoder is installed.
  • Filename prefix tokens: You can use ComfyUI’s formatting syntax to include date, time, or node values. For example:
    video/ComfyUI_%empty_latent_image.width%x%empty_latent_image.height%_%date:yyyy-MM-dd%
    will produce filenames like video/ComfyUI_512x512_2025-01-15_0001.mp4.
  • Tile size tuning: For most use cases, a tile_size of 512 and overlap of 64 provide a good trade‑off between memory and speed. Increase tile_size if memory permits; decrease it if you run out of VRAM.
  • Temporal tiling: This is only effective with VAEs that natively support temporal tiling. If your VAE does not, setting temporal parameters will have no effect.
  • Step increments: All integer tile parameters enforce the step size defined in the node (32 for spatial, 4 for temporal). Values not aligned to the step are automatically rounded.

Comments

Sign in with GitHub to join the discussion.

Loading comments…
Decode and Save Video (DecodeAndSaveVideo) - ComfyUI-KJNodes | ComfyUI Wiki