You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Video processing
Video face blurring
Copy page
Download PDF
Video face blurring

Operator introduction

Description

Video face blurring operator

Main features

  • Automatically detects faces in video frames and applies blurring
  • Supports multiple blur types (mean, box, Gaussian)
  • Supports local paths, remote URL/TOS paths, and binary/BASE64 video input
  • Consistently outputs the path of the blurred video (the video will be re-encoded and output even if no face is detected)
  • Can run in both CPU and GPU environments

Applicable scenarios

  • Privacy protection: De-identifies face information in videos to prevent personal privacy leakage
  • Privacy cleansing before data release: Applies blurring to faces in video data before release to protect user privacy
  • Face blurring preprocessing for training/evaluation datasets: Applies face blurring to video frames in datasets during model training or evaluation to improve model generalization

Caution

  • Face detection is based on the InsightFace model and is sensitive to lighting and pose variations
  • Input videos must be in common formats supported by PyAV/FFmpeg (such as mp4, mov, avi, and more)
  • If processing of a single sample fails, the result for that sample returns an empty string and does not affect other samples in the batch

Daft invocation

Operator parameters

Input

Input column name

Description

video_paths

Video file path column; supports multiple path formats such as local, TOS, HTTP, and more. Choose either video_paths or video_binaries.

video_binaries

Video binary data or BASE64 string column. Choose either video_binaries or video_paths.

video_formats

Video format string column (such as "mp4", "mov"). When the input is video_binaries, this column must be provided to specify the video format.

output_basenames

Output file base name column (without extension), used to customize the output file name.

Output

The output is a column of strings, each representing the file path of the blurred video.

Parameters

If a parameter does not have a default value, it is required

Parameter name

Type

Default value

Description

output_dir

str

""

Save the video after blurring to this directory. Currently, uploading to TOS or a local directory is supported. Format: "tos://bucket/path/" or "/local/path/".

model_path

str

"/opt/las/models"

The base directory path for the face detection model, used for loading the InsightFace model.

model_name

str

"insightface"

The subdirectory name of the InsightFace model. The final model path is model_path/model_name.

blur_type

str

"gaussian"

Blur method. Optional values: "mean" (mean blur), "box" (box blur), "gaussian" (Gaussian blur).

radius

float

10.0

Blur radius, effective only for box blur and Gaussian blur. Requires radius >= 0. It is recommended to adjust within 5-20 based on the effect.

det_thresh

float

0.5

Confidence threshold for face detection. For privacy protection, it is recommended to lower it to 0.3-0.4 to avoid missed detections. For fine retouching, it is recommended to raise it to 0.6-0.7 to ensure only frontal faces are processed.

det_size

tuple[int, int]

(640, 640)

Input size for face detection (width, height). For regular online videos, the default value (640, 640) offers a good balance of performance and cost. For scenarios such as surveillance footage, it is recommended to increase it to (1280, 1280) or higher to detect small faces at a distance.

Examples

The following code demonstrates how to use daft to run the operator for face blurring in videos.

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.udf import las_udf
from daft.las.functions.video import VideoFaceBlur

if __name__ == "__main__":
    # The modified video will be saved to the specified TOS path. Therefore, you need to set environment variables to ensure write permissions to TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR
    TOS_DIR = os.getenv("TOS_DIR", "tos_bucket")
    output_dir = f"tos://{TOS_DIR}/video/video_face_blur"

    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.set_runner_ray()

    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com")
    samples = {"video_path": [f"https://{tos_dir_url}/public/shared_video_dataset/singer.mp4"]}
    ds = daft.from_pydict(samples)

    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    constructor_kwargs = {
        "output_dir": output_dir,
        "model_path": model_path,
        "blur_type": "gaussian",
        "radius": 20.0,
    }

    ds = ds.with_column(
        "results",
        las_udf(
            VideoFaceBlur,
            construct_args=constructor_kwargs,
            num_gpus=1,
            batch_size=1,
            concurrency=1,
        )(col("video_path")),
    )

    ds.show()

    # ╭────────────────────────────────┬────────────────────────────────╮
    # │ video_path                     ┆ results                        │
    # │ ---                            ┆ ---                            │
    # │ String                         ┆ String                         │
    # ╞════════════════════════════════╪════════════════════════════════╡
    # │ https://las-cn-beijing-public… ┆ tos://las-ai-qa-online/qa/tes… │
    # ╰────────────────────────────────┴────────────────────────────────╯
Last updated: 2026.05.12 19:06:35