Pet / Chroma Key + Closed Loop WebP
Pet loop, keyed, seamless, and saved — one node does the boring part
- images
- checker_preview
- foreground_mask
- saved_webp
So you've got a batch of frames from an image-to-video model - your pet walking on a green screen that isn't quite green, with green fringing on the fur and a first and last frame that don't line up into a loop. That's the exact moment Pet / Chroma Key + Closed Loop WebP earns its keep. It's the finishing node of the GuardSkill/ComfyUI-Pet-Companion-Nodes pack, and it bundles what would otherwise be four separate steps into one: chroma key, soft matte, green-spill cleanup, loop closure, and a lossless animated WebP export. Everything's local - no API, no key, just numpy, OpenCV and Pillow.
How it works
Each frame gets keyed against key_color, and the keyer is the smart part. Rather than trusting raw color distance alone, it only makes pixels transparent when they're both green and connected to the frame boundary. That's deliberate: a dog's collar, eye reflection, or coat marking that happens to match the key stays opaque, because it isn't attached to the background. The matte is soft, not a hard cutout - similarity sets where the key starts and smoothness feathers the edge with a smoothstep so you don't get crunchy outlines. Then despill: green light bouncing off the screen stains the fur's edge, so the node suppresses excess green near the keyed boundary only, leaving interior coat colors alone. Finally, close_loop replaces the last exported frame with the first, giving you a seamless loop - without touching the interior generated frames.
The frames are written as an animated RGBA WebP with per-frame durations derived from fps, infinite looping, and lossless encoding by default.
The inputs that matter
Most have sane defaults, and the README's starting set for H3 green-screen output at 24 fps is a good baseline: key_color #00FF00, similarity 0.20, smoothness 0.10, despill 0.85, close loop on, lossless on. The ones you'll actually touch:
similarity(0.01–0.70) - how close to the key a pixel must be to start keying. Too high eats the subject; too low leaves green ghosts.smoothness(0.001–0.40) - matte edge softness. 0.10 is a good starting feather.despill(0–1) - how aggressively green fringe gets pulled off fur edges. 0.85 is aggressive by design.close_loop- on for seamless looping, off if you want the real final frame kept.lossless/quality- keep lossless on and quality at 100 for transparent animation; flip lossless off only if file size matters more than clean edges.fps(1–120) andfilename_prefix(defaultpet_companion/loop) - set the export speed and where the file lands in ComfyUI's output directory.
Three outputs: checker_preview (IMAGE, composited over a checkerboard so you can judge the key at a glance), foreground_mask (MASK, for compositing in the graph), and saved_webp (STRING, the absolute path to the file). Wire the preview to a Preview node while you tune; wire the path to a text node if you want to find the file without digging.
Install
ComfyUI Manager (search "ComfyUI-Pet-Companion-Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/GuardSkill/ComfyUI-Pet-Companion-Nodes.git
Restart, and it appears under Pet Companion/Green Screen. No model downloads, and the dependencies are the loose, boring trio (numpy, opencv-python, Pillow) that's probably already in your environment.
Where people get burned
It needs at least two frames - feed it a single image and it raises ValueError: At least two video frames are required. That's the classic one: you test with one frame and wonder why the loop won't export. Also, key_color must be six-digit hex; anything else throws. And remember WebP is a derivative format: it won't carry ComfyUI's embedded workflow, and most hosts (Discord inline previews, Reddit) recompress it on upload, so keep the original frames if you want to re-export. Small pack, one version so far, zero community noise - but for the narrow job of "pet loop, keyed, seamless, saved," it's a tidy one-stop shop.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| filename_prefix | STRING | pet_companion/loop | — |
| fps | FLOAT | 24.001–120 | — |
| key_color | STRING | #00FF00 | — |
| similarity | FLOAT | 0.200.01–0.7 | — |
| smoothness | FLOAT | 0.1000.001–0.4 | — |
| despill | FLOAT | 0.850–1 | — |
| close_loop | BOOLEAN | true | — |
| lossless | BOOLEAN | true | — |
| quality | INT | 1001–100 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| checker_preview | IMAGE | — |
| foreground_mask | MASK | — |
| saved_webp | STRING | — |