MCPcopy Index your code
hub / github.com/kijai/ComfyUI-WanVideoWrapper / encode

Method encode

nodes.py:2258–2292  ·  view source on GitHub ↗
(self, vae, image, enable_vae_tiling, tile_x, tile_y, tile_stride_x, tile_stride_y, noise_aug_strength=0.0, latent_strength=1.0, mask=None)

Source from the content-addressed store, hash-verified

2256 CATEGORY = "WanVideoWrapper"
2257
2258 def encode(self, vae, image, enable_vae_tiling, tile_x, tile_y, tile_stride_x, tile_stride_y, noise_aug_strength=0.0, latent_strength=1.0, mask=None):
2259 vae.to(device)
2260
2261 image = image.clone()
2262
2263 B, H, W, C = image.shape
2264 if W % 16 != 0 or H % 16 != 0:
2265 new_height = (H // 16) * 16
2266 new_width = (W // 16) * 16
2267 log.warning(f"Image size {W}x{H} is not divisible by 16, resizing to {new_width}x{new_height}")
2268 image = common_upscale(image.movedim(-1, 1), new_width, new_height, "lanczos", "disabled").movedim(1, -1)
2269
2270 if image.shape[-1] == 4:
2271 image = image[..., :3]
2272 image = image.to(vae.dtype).to(device).unsqueeze(0).permute(0, 4, 1, 2, 3) # B, C, T, H, W
2273
2274 if noise_aug_strength > 0.0:
2275 image = add_noise_to_reference_video(image, ratio=noise_aug_strength)
2276
2277 if isinstance(vae, TAEHV):
2278 latents = vae.encode_video(image.permute(0, 2, 1, 3, 4), parallel=False)# B, T, C, H, W
2279 latents = latents.permute(0, 2, 1, 3, 4)
2280 else:
2281 latents = vae.encode(image * 2.0 - 1.0, device=device, tiled=enable_vae_tiling, tile_size=(tile_x//vae.upsampling_factor, tile_y//vae.upsampling_factor), tile_stride=(tile_stride_x//vae.upsampling_factor, tile_stride_y//vae.upsampling_factor))
2282
2283 vae.to(offload_device)
2284 if latent_strength != 1.0:
2285 latents *= latent_strength
2286
2287 latents = latents.cpu()
2288
2289 log.info(f"WanVideoEncode: Encoded latents shape {latents.shape}")
2290 mm.soft_empty_cache()
2291
2292 return ({"samples": latents, "noise_mask": mask},)
2293
2294NODE_CLASS_MAPPINGS = {
2295 "WanVideoDecode": WanVideoDecode,

Callers 7

get_cache_pathFunction · 0.45
get_cache_pathMethod · 0.45
addMethod · 0.45
processMethod · 0.45
processMethod · 0.45
vace_encode_framesMethod · 0.45
encodeMethod · 0.45

Calls 3

toMethod · 0.80
encode_videoMethod · 0.80

Tested by

no test coverage detected