Nodes/face_mosaic/统一GPU人脸马赛克(可选RetinaFace/YOLO/MTCNN)
ComfyUI Node

统一GPU人脸马赛克(可选RetinaFace/YOLO/MTCNN)

One video node, three detectors, and actually decent output quality

By yzzky·Created 12 months ago·Updated 12 months ago· 0
统一GPU人脸马赛克(可选RetinaFace/YOLO/MTCNN)
    • output_video_path
    • processing_info
    ◄video_path►
    ◄detector▾►
    ◄mosaic_size20►
    ◄mosaic_type▾►
    ◄output_format▾►
    ◄use_gputrue►
    ◄output_path►
    ◄yolo_model_path►
    ◄use_ffmpeg_encodetrue►
    ◄ffmpeg_crf23►
    ◄ffmpeg_preset▾►
    ◄copy_audiotrue►

    If you only install one video mosaic node from this pack, make it this one. The "unified" GPU node is the pack's flagship: a single box that lets you pick your face detector - RetinaFace, YOLO, or MTCNN - and, crucially, re-encodes the output with ffmpeg so the result is actually small and playable. That last part is rarer than it should be in this pack, because the plain OpenCV mp4v output it writes elsewhere is the kind of file that plays on nothing. Menu name: 统一GPU人脸马赛克(可选RetinaFace/YOLO/MTCNN) under YZZ_Face_Mosaic/GPU.

    How it works

    The detector dropdown picks which engine _build_detector constructs:

    • retinaface - InsightFace's buffalo_l via ONNX Runtime; CUDA if available. The default, and the best all-rounder.
    • yolo - an Ultralytics YOLO model. Note: the weights are not bundled. The code looks for yolov8n-face.pt, yolov8s-face.pt, yolov5n-face.pt, or yolov5s-face.pt in your ComfyUI models dir, or whatever you put in yolo_model_path. No weights → the detector prints a notice and detects nothing.
    • mtcnn - facenet_pytorch MTCNN, the light option.

    Detection runs per frame (on GPU when use_gpu and CUDA cooperate), mosaic styles are the pack's usual pixelate / blur / black_box, and frames are written to a temp file. Then the good part: with use_ffmpeg_encode on (default), it shells out to ffmpeg and re-encodes with H.264 - libx264, CRF controlled by ffmpeg_crf (16–32, default 23), speed by ffmpeg_preset (ultrafast → veryslow). copy_audio on muxes the original audio track straight through instead of dropping it. This is why the output is both small and widely playable, and it's the only video node family in the pack that gives you that.

    Inputs worth setting

    • detector - the engine choice above. retinaface unless you have reasons.
    • yolo_model_path - only matters for the yolo detector; leave blank and it searches your models dir.
    • use_ffmpeg_encode + ffmpeg_crf + ffmpeg_preset + copy_audio - your quality controls. CRF 23/preset medium is a sane default; drop CRF to 18 if you care about the frame quality.
    • video_path, mosaic_size, mosaic_type, output_format, use_gpu, output_path - the pack's usual cast.

    Outputs are output_video_path (STRING) and processing_info (JSON, including a ffmpeg_log_tail you can read if the encode fails).

    Installing it

    Pack: ComfyUI Manager → yzz_face_mosaic, or git clone https://github.com/yzzky/yzz_face_mosaic into custom_nodes + pip install -r requirements.txt. Then the per-detector extras, none of which are in requirements.txt:

    pip install insightface onnxruntime-gpu    # retinaface
    pip install ultralytics                    # yolo (face weights still needed!)
    pip install facenet-pytorch                # mtcnn
    

    Plus ffmpeg itself on your PATH for the re-encode step.

    Where it bites

    This node has the most dependency surface in the pack: pick a detector you haven't installed and it logs a warning and finds zero faces - your video comes back untouched, no error. First runs download weights. If use_ffmpeg_encode is on but ffmpeg is missing, it silently keeps the raw OpenCV output (the log tells you). And remember the yolo path wants face weights, not the generic COCO yolov8n.pt that Ultralytics auto-downloads - a generic model won't produce face boxes.

    CategoryYZZ_Face_Mosaic/GPU

    Inputs (12)

    NameTypeDefaultDescription
    video_pathSTRING—
    detectorCOMBO3 options: retinaface, yolo, mtcnn
    mosaic_sizeINT205–100—
    mosaic_typeCOMBO3 options: pixelate, blur, black_box
    output_formatCOMBO3 options: mp4, avi, mov
    use_gpuBOOLEANtrue—
    output_pathoptSTRING—
    yolo_model_pathoptSTRING—
    use_ffmpeg_encodeoptBOOLEANtrue—
    ffmpeg_crfoptINT2316–32—
    ffmpeg_presetoptCOMBO9 options: ultrafast, superfast, veryfast, faster, fast, medium, +3
    copy_audiooptBOOLEANtrue—

    Outputs (2)

    NameTypeDescription
    output_video_pathSTRING—
    processing_infoSTRING—