KJNodes/imagegenerated

Encode Video Components(EncodeVideoComponents)

Extracts video frames, resizes them, and encodes with a VAE directly, avoiding storing the full image tensor.

Encode Video Components

video
vae
keep_proportion
latent
audio
fps
frame_count
width
768
height
512
max_frames
0
upscale_method
lanczos
KJNodes

Description

The Encode Video Components node extracts frames from a video, resizes them to a specified resolution, and encodes them directly through a VAE into a latent representation. It processes frames one by one, avoiding the memory cost of storing the full image tensor for the entire video at once. The node also passes through the audio track from the input video and outputs metadata such as frame rate and total frame count.

Inputs

  • video (VIDEO, required) — The video file or sequence to process. Must be a valid video input as accepted by ComfyUI-KJNodes.
  • vae (VAE, required) — The VAE model used for encoding the resized frames into latent space.
  • width (INT, default: 768, range: 016384, step: 2) — Target width for each frame before encoding. Set to 0 to keep the original video width.
  • height (INT, default: 512, range: 016384, step: 2) — Target height for each frame before encoding. Set to 0 to keep the original video height.
  • max_frames (INT, default: 0, range: 0999999, step: 1) — Maximum number of frames to process. 0 means no limit and the entire video is processed.
  • upscale_method (COMBO, default: "lanczos") — Interpolation algorithm used when resizing frames. Options:
    • nearest-exact — Fast, nearest-neighbor interpolation; can produce blocky results.
    • bilinear — Smooth, good for general scaling.
    • area — Area-based resizing; effective when downscaling.
    • bicubic — Higher quality than bilinear, slightly slower.
    • lanczos — Sharp resampling, often preferred for high-quality downscaling.
  • keep_proportion (DYNAMICCOMBO, required) — Controls how to handle aspect ratio mismatch when the target width/height differ from the frame's original aspect ratio. This is a dynamic dropdown that adapts available options based on other inputs; common modes include "crop", "pad", "stretch", or "fit". See usage notes for details.

Outputs

  • LATENT — The VAE-encoded latent representation of all processed frames, stacked as a batch. The shape matches the VAE's expected latent dimensions.
  • AUDIO — The audio track extracted from the input video, if present. This output may be empty or None if the video has no audio.
  • FLOAT — The frame rate (FPS) of the original video, as a floating-point number.
  • INT — The total number of frames actually processed (respecting max_frames limit).

Usage Notes

  • The node processes frames sequentially and feeds each resized frame to the VAE immediately, significantly reducing peak memory usage compared to loading an entire video into a batch of images first.
  • Set width and/or height to 0 to preserve the original dimension. If both are non-zero, they define the target resolution. The keep_proportion setting determines how aspect ratio mismatches are resolved.
  • The keep_proportion combo is labeled "How to handle aspect ratio mismatch when resizing" in the tooltip. Its exact options depend on the node’s implementation (e.g., "crop to fit", "pad", "ignore", or "fit"). Test the node in your workflow to see available choices.
  • upscale_method only affects frames that are actually resized (i.e., when width or height differs from the original). If both dimensions match the original, no resizing occurs and this parameter is ignored.
  • Use max_frames to limit processing for long videos or to debug with a subset of frames. Setting 0 (default) processes the entire video.
  • The output LATENT can be fed directly into sampling nodes (e.g., KSampler) that accept latent batches. The latent batch size equals the frame count.
  • If the input video has no audio track, the AUDIO output will be an empty placeholder; downstream nodes expecting audio should handle this gracefully.
  • The FLOAT output (frame rate) and INT output (frame count) can be useful for synchronizing subsequent steps that depend on timing or for reporting purposes.

Comments

Sign in with GitHub to join the discussion.

Loading comments…
Encode Video Components (EncodeVideoComponents) - ComfyUI-KJNodes | ComfyUI Wiki