Nodes/KJNodes for ComfyUI/Webcam Capture CV2
ComfyUI Node Runs on cloud

Webcam Capture CV2

Pull a live camera frame into your graph

By kijai·Created 3 years ago·Updated about 17 hours ago· 2,930
Webcam Capture CV2
    • image
    x0
    y0
    width512
    height512
    cam_index0
    releasefalse

    This node grabs a frame from a webcam, right inside the graph, using OpenCV. Pair it with ComfyUI's Auto Queue and a fast model and you've got the makings of real-time diffusion - webcam in, generated image out, refreshing continuously. It's the node behind a lot of the "live img2img mirror" demos. It's flagged experimental, which is fair; it's a fun toy with one big footgun you need to understand before it works.

    It's part of KJNodes, kijai's utility pack, filed under experimental.

    How it works

    On each execution it opens the camera via cv2, reads a single frame, optionally crops it to a region, and returns it as an image. The "realtime" part isn't in this node - it comes from combining it with Auto Queue, which re-runs the graph continuously, so each run captures a fresh frame and pushes it through your workflow. Point that at an LCM/Turbo/Lightning-style fast model and the loop is quick enough to feel live.

    The inputs and output that matter

    • cam_index - which camera (0 is the default/first one; bump it if you have several).
    • x, y, width, height - a crop region on the captured frame, so you can grab just part of the camera view.
    • release - when true, frees the camera handle after capture so other apps (or the next run's settings) can use it. Handy when you're done and something else needs the camera.

    The output is a single image - the captured frame, ready to feed into an img2img or ControlNet path.

    Installing it

    ComfyUI Manager → search KJNodes for ComfyUI → install → restart. Or cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, and restart. It uses OpenCV (cv2), which the pack's requirements cover.

    Where people get burned

    • It captures the server's camera, not your browser's. This is the number one confusion, and it's worth being blunt: the node opens a camera on the machine ComfyUI is running on. On your own local machine, that's your webcam and everything's fine. On a cloud or remote instance, there is no camera - or it's the server's, not your laptop's - so you get a black frame or an error. Real-time webcam diffusion only works when ComfyUI runs locally on the machine with the camera.
    • Camera already in use. If another app (or a previous run that didn't release) is holding the camera, capture fails. Set release to free it, or close the other app.
    • Wrong cam_index. Multiple cameras, virtual cameras, and capture devices all get indices; if you're grabbing the wrong feed, try a different cam_index.
    CategoryKJNodes/experimental

    Inputs (6)

    NameTypeDefaultDescription
    xINT00–4096
    yINT00–4096
    widthINT5120–4096
    heightINT5120–4096
    cam_indexINT00–255
    releaseBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    imageIMAGE