ComfyUI Node

Load Webcam Image

The stable way to feed a live webcam into ComfyUI

By toyxyz·Created 3 years ago·Updated a day ago· 635
Load Webcam Image
    • image
    image_path./ComfyUI/custom_nodes/ComfyUI_toyxyz_test_nodes/CaptureCam/captured_frames/capture.jpg

    If Capture Webcam is the cowboy way to get a webcam into ComfyUI, this is the one you actually take home to meet the parents. Load Webcam Image doesn't touch your camera at all. Instead it reads an image file that the pack's companion CaptureCam app keeps writing, and that indirection is exactly why it's stable.

    The pattern is simple and it's the core of every "AI mirror" setup with this pack: the CaptureCam app (a small Python windowed app that lives in CaptureCam/cam.py) owns the camera and saves a frame to disk on a loop; this node loads that file; you img2img it; another node saves the result back where the app can display it. Because only one program ever grabs the camera, nothing fights over it - which is why the author recommends this node if you're using OBS. Point the app at your OBS virtual camera and everyone's happy.

    How it works

    The node is a file reader with a live-loop personality. Its image_path defaults to ./ComfyUI/custom_nodes/ComfyUI_toyxyz_test_nodes/CaptureCam/captured_frames/capture.jpg - the exact spot the app saves to. Crucially, its IS_CHANGED hashes the file's contents, so ComfyUI re-executes the node every time the frame changes. That polling behavior is what makes the feed feel live without the node ever holding a camera handle.

    It also handles the "file is mid-write" case with a bit of grace: if the open fails, it retries after 50ms a couple of times, and if the file genuinely doesn't exist it falls back to a black 512×512 image and prints Image doesn't exist! to the console. The module even sets ImageFile.LOAD_TRUNCATED_IMAGES = True, so a half-written frame won't necessarily crash the graph.

    Inputs and outputs

    One required input, image_path: a string path to any image file. Since it's really just a "load image from path" node in a trench coat, you can point it at any file - a rendered frame, a reference photo - not just webcam captures. The single image output (IMAGE) feeds the same places as any loader output: VAE encode, ControlNet preprocessor, whatever.

    Setting it up

    cd ComfyUI/custom_nodes
    git clone https://github.com/toyxyz/ComfyUI_toyxyz_test_nodes
    

    Then, unlike the direct capture node, you do need the app running. Run CaptureCam/setup.bat once (it creates a venv and installs the app's deps: opencv-python, pywin32, pillow, mss, FreeSimpleGUI, pygrabber, keyboard, pygetwindow), then launch with CaptureCam/run.bat, pick your webcam in the app, and hit start. There's a Run_hide_cmd.vbs that launches it without the console window hanging around. ComfyUI Manager can also install the pack, but you still have to run setup.bat yourself.

    Common issues

    A black frame almost always means the app isn't running, the capture hasn't started, or image_path points somewhere wrong - check the console for that Image doesn't exist! message. The app's default path is only used if you leave the capture path blank, so if you changed it in the app, set the same path here. Keep "aspect ratio" enabled in the app so frames aren't stretched. And if you want to inpaint faces live, the app's face detection writes a face_mask.jpg you can load and feed into an inpainting pass - the README calls this out explicitly as its intended use.

    CategoryToyxyzTestNodes

    Inputs (1)

    NameTypeDefaultDescription
    image_pathSTRING./ComfyUI/custom_nodes/ComfyUI_toyxyz_test_nodes/CaptureCam/captured_frames/capture.jpg

    Outputs (1)

    NameTypeDescription
    imageIMAGE