Video Align To Stylized Frame
Un-shifting AI restyles back into place
- video_frames
- reference_frame
- aligned_frames
- offset_x
- offset_y
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 detectionreference_frame- the single stylized frame to align to; must be the same resolution asvideo_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;pixelsaligns 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), orreflect(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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| video_frames | IMAGE | Batch of video frames (B, H, W, C). The first frame is used for alignment detection. | |
| reference_frame | IMAGE | Single stylized reference frame to align to. Must be the same resolution as video_frames. | |
| alignment_method | COMBO | edges | edges: align on Sobel edges (robust for style-transferred images). pixels: align on raw grayscale intensity. |
| border_mode | COMBO | zeros | How to fill pixels revealed after shifting. zeros=black, replicate=edge pixels, reflect=mirror. |
| max_offset | INT | 1001–512 | Maximum allowed offset in pixels. Detected offsets larger than this are clamped to zero (guards against false correlations). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| aligned_frames | IMAGE | — |
| offset_x | INT | — |
| offset_y | INT | — |