Nodes/TrentNodes/Video Align To Stylized Frame
ComfyUI Node

Video Align To Stylized Frame

Un-shifting AI restyles back into place

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Video Align To Stylized Frame
  • video_frames
  • reference_frame
  • aligned_frames
  • offset_x
  • offset_y
alignment_methodedges
border_modezeros
max_offset100

Stylizing a video with img2img-style models has a dirty secret: the model doesn't respect your framing. The restyled frame drifts - a few pixels of translation, sometimes more - and when you try to intercut or composite the stylized footage with the original, everything is a frame out of register. Video Align to Stylized Frame exists to fix exactly that: it aligns a batch of video frames to a single stylized reference frame, recovering the translation offset and shifting the whole batch back into place.

It's the video-side cousin of the pack's Align Stylized Frame image node, and it's aimed at the same workflow: you stylize, then you register the result back against the source so the AI's framing drift stops being a compositing problem.

How it works

Required inputs:

  • video_frames - the batch of frames; the first frame is used for alignment detection
  • reference_frame - the single stylized frame to align to; must be the same resolution as video_frames

The mechanism is phase-correlation-style shift estimation: it finds the best translation between the first video frame and the reference, then applies that same offset to every frame in the batch. Because the alignment is computed once from frame one and applied uniformly, the whole clip stays coherent - which is what you want when the drift is a global framing shift rather than per-frame motion.

Three knobs:

  • alignment_method - edges (default) aligns on Sobel edges, robust for style-transferred images where pixel intensities have been remapped; pixels aligns on raw grayscale intensity, which is better when the content hasn't changed color wildly.
  • border_mode - how to fill pixels revealed after shifting: zeros (black), replicate (edge pixels), or reflect (mirror).
  • max_offset - the maximum allowed offset in pixels. Detected offsets larger than this clamp to zero, as a guard against false correlations. If your stylized frame drifted more than the cap, raise it.

Outputs: aligned_frames (the shifted batch) plus offset_x and offset_y as INTs, so you can see (and wire elsewhere) exactly how much the node had to move things.

The honest limits

This is a translation-aligner, not a full registration. It recovers shift; it does not correct rotation, scale, or perspective warp. If your restyle came back rotated or re-composed, this node can't un-rotate it - you'd want a proper affine/feature-matching approach (the pack's Align Stylized Frame handles rotation and scale for single images; this video node is deliberately the shift-only workhorse). For the common case - the stylizer nudged the framing by a few pixels - that's exactly the case it nails.

Also worth knowing: it uses the first frame for detection and applies the result to the whole batch. If your drift varies through the clip (per-frame instability), a single global shift won't fix every frame. Check your worst frame after aligning, and if it's still off, the problem is per-frame drift, not a global one.

Install

One of ~69 nodes in TrentNodes (TrentHunter82/TrentNodes):

# ComfyUI Manager: search "Trent Nodes"

# or:
cd ComfyUI/custom_nodes
git clone https://github.com/TrentHunter82/TrentNodes.git
cd TrentNodes && pip install -r requirements.txt

No model downloads - it's a pure CV operation on the pack's core opencv/numpy stack. Pair it with the image-side Align Stylized Frame in the same pack and you've got the whole "stylize, then put it back" pipeline covered.

CategoryTrent/Video

Inputs (5)

NameTypeDefaultDescription
video_framesIMAGEBatch of video frames (B, H, W, C). The first frame is used for alignment detection.
reference_frameIMAGESingle stylized reference frame to align to. Must be the same resolution as video_frames.
alignment_methodCOMBOedgesedges: align on Sobel edges (robust for style-transferred images). pixels: align on raw grayscale intensity.
border_modeCOMBOzerosHow to fill pixels revealed after shifting. zeros=black, replicate=edge pixels, reflect=mirror.
max_offsetINT1001–512Maximum allowed offset in pixels. Detected offsets larger than this are clamped to zero (guards against false correlations).

Outputs (3)

NameTypeDescription
aligned_framesIMAGE
offset_xINT
offset_yINT