Skip to content

Commit

Permalink
Fix latent preview downscaling.
Browse files Browse the repository at this point in the history
By setting the downscale cutoff for latent previews to 512, it wound up
never getting tested. Animate diff has a target resolution of 512 and
newer video models only have conversion with latent2rgb,

The code for downscaling preview frames that are greater than 512 has
now been fixed and tested.

Resolves #361
  • Loading branch information
AustinMroz committed Jan 21, 2025
1 parent c47b10c commit f24f4e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-videohelpersuite"
description = "Nodes related to video workflows"
version = "1.4.5"
version = "1.4.6"
license = { file = "LICENSE" }
dependencies = ["opencv-python", "imageio-ffmpeg"]

Expand Down
15 changes: 9 additions & 6 deletions videohelpersuite/latent_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def decode_latent_to_preview_image(self, preview_format, x0):
self.last_time = self.last_time + num_previews/self.rate
if num_previews > num_images:
num_previews = num_images
elif num_previews <= 0:
return None
if self.first_preview:
self.first_preview = False
serv.send_sync('VHS_latentpreview', {'length':num_images, 'rate': self.rate})
Expand All @@ -54,13 +56,14 @@ def decode_latent_to_preview_image(self, preview_format, x0):
def process_previews(self, image_tensor, ind, leng):
image_tensor = self.decode_latent_to_preview(image_tensor)
if image_tensor.size(1) > 512 or image_tensor.size(2) > 512:
n = image.size(0)
if image_tensor.size(1) > image_tensor.size(2):
height = (512 * image_tensor.size(2)) // image_tensor.size(1)
image_tensor = F.interpolate(image_tensor, (512,height,3), mode='bilinear')
image_tensor = image_tensor.movedim(-1,0)
if image_tensor.size(2) < image_tensor.size(3):
height = (512 * image_tensor.size(2)) // image_tensor.size(3)
image_tensor = F.interpolate(image_tensor, (height,512), mode='bilinear')
else:
width = (512 * image_tensor.size(1)) // image_tensor.size(2)
image_tensor = F.interpolate(image_tensor, (width, 512,3), mode='bilinear')
width = (512 * image_tensor.size(3)) // image_tensor.size(2)
image_tensor = F.interpolate(image_tensor, (512, width), mode='bilinear')
image_tensor = image_tensor.movedim(0,-1)
previews_ubyte = (((image_tensor + 1.0) / 2.0).clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
).to(device="cpu", dtype=torch.uint8)
Expand Down

0 comments on commit f24f4e1

Please sign in to comment.