Dev.to AI 🤖 Ai 👁 0 📖 1 min read

VACE infinite first-last-frame loops: batch indexing without the off-by-one

An infinite first-and-last-frame loop is not one giant generation. It is a For loop over a batch of images, where each iteration uses the previous tail as the next head. This episode shows the indexing trick that makes t

An infinite first-and-last-frame loop is not one giant generation. It is a For loop over a batch of images, where each iteration uses the previous tail as the next head. This episode shows the indexing trick that makes the chain work.

Watch the episode: https://youtu.be/HDwTjUZ31SU
Chinese original: https://www.bilibili.com/video/BV1BejmzpEMD

The core pattern

Load a batch of images. In iteration zero, take image 0 as the first frame and image 1 as the last frame. In iteration one, the old last frame becomes the new first frame, and the index advances. Repeat.

That gives a simple rule: N images create N-1 transitions. Four images produce three segments; looping four times over five images produces four transitions.

Indexing a batch

ComfyUI's batch index starts at zero. The episode uses an index-like sequence and a small arithmetic expression: current index plus one selects the next image in the batch. This is the part that is easy to get wrong - an off-by-one error silently shifts the entire storyboard.

The stack

  • VACE for the video conditioning
  • For loop for iteration
  • CausVid for acceleration
  • Batch Any to collect the generated images at the end

The demonstrated output is 720p, which is the test condition rather than a universal limit.

Known limits

  • One bad frame propagates through every later segment.
  • Index errors do not always throw; they can produce a valid but wrong sequence.
  • Loop length increases total render time roughly linearly.
  • No workflow JSON or weights are bundled with this article; the episode shares an online flow.
📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.