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

Lake AI Service

Copy page
Download PDF
Video processing
Video sharpness calculation
Copy page
Download PDF
Video sharpness calculation

Operator ID: daft.las.functions.video.video_sharpness.VideoSharpness

Operator introduction

Description

Video sharpness calculation processor that supports multiple sharpness evaluation methods and frame extraction strategies.

Key features

  • Video frame extraction:
    • Frame extraction strategy based on FPS, customizable number of frames extracted per second
    • Limits the maximum number of extracted frames to prevent infinite loops when processing long videos
    • Supports dual frame extraction schemes using ffmpeg and cv2 to improve stability
  • Multiple sharpness evaluation methods:
    • Laplacian variance method (laplacian) – edge detection based on second-order derivatives, simple and fast calculation
    • Tenengrad method (tenengrad) – edge strength based on Sobel gradients, sensitive to noise
    • Brenner method (brenner) – simple calculation based on the grayscale difference of adjacent pixels, fastest speed
    • FFT high-frequency energy method (fft_highfreq) – sharpness evaluation based on frequency domain analysis, more sensitive to blurring
  • Multi-pooling functionality:
    • Returns results for all pooling methods (mean, median, maximum, minimum, standard deviation)
    • Automatically handles NaN values and exceptions
  • Supports multiple input formats:
    • URL address
    • Binary stream

Format support:

  • Input: Mainstream video formats such as MP4, AVI, MOV

Caution and prerequisites

Details

Caution and prerequisites

Costs

Before calling an operator, you need to understand the model invocation costs associated with using the operator. For details, see Large model invocation billing.

Authentication (API Key)

Before calling an operator, you need to generate an API Key for operator invocation. It is recommended to configure the API Key as an environment variable to ensure safer operator calls. For details, see Obtain and configure API Key.

BaseURL

Before calling an operator, you need to determine the BaseURL for operator invocation based on the region where your current LAS service is deployed. This is used to configure the path parameter values for operator calls.
For details, see Obtain the Base URL. The Examples below are for reference only; when making actual calls, replace the path values with those corresponding to your region.

Daft usage

Operator parameters

Input

Input column name

Note

video_paths

Video file path column (local, TOS, HTTP, and so on), choose either video_paths or video_binaries

video_binaries

Video binary data column, choose either video_binaries or video_paths

video_formats

Video format string column, used together with video_binaries

Output

Array of structs containing sharpness results for all pooling methods. Each element includes:

  • mean: Mean sharpness
  • median: Median sharpness
  • max: Maximum sharpness
  • min: Minimum sharpness
  • std: Standard deviation of sharpness

Parameters

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

Parameter name

Type

Default value

Description

fps

float

2.0

Number of frames extracted per second.
Description: Number of frames extracted from the video per second, used for sharpness calculation
Default value: 2.0

method

str

"laplacian"

Sharpness calculation method.
Description: Sharpness calculation method, supports laplacian (Laplacian variance), tenengrad (Tenengrad gradient), brenner (Brenner gradient), fft_highfreq (FFT high-frequency energy), default is laplacian.
Optional values: ["laplacian", "tenengrad", "brenner", "fft_highfreq"]
Default value: "laplacian"

max_frames

int

100

Maximum number of extracted frames.
Description: Limits the maximum number of extracted frames to prevent infinite loops when processing long videos
Default value: 100

Examples

The following code demonstrates how to use Daft (for distributed scenarios) to run the operator for video sharpness calculation.

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.video_sharpness import VideoSharpness

if __name__ == "__main__":
    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",
            )
            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)

    # Use environment variables to construct the URL
    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/sample.mp4"
        ]
    }

    ds = daft.from_pydict(samples)

    sharpness_calculator = las_udf(
        VideoSharpness,
        construct_args={
            "fps": 2.0,
            "method": "laplacian",
            "max_frames": 100,
        },
        num_gpus=1,
        concurrency=1,
        batch_size=1,
    )

    # Use Daft for distributed processing
    ds = ds.with_column("video_sharpness", sharpness_calculator(col("video_path")))

    ds.show()
    # ╭────────────────────────────────┬──────────────────────────────────╮
    # │ video_path                     ┆ video_sharpness                  │
    # │ ---                            ┆ ---                              │
    # │ Utf8                           ┆ Struct[mean: Float64, median: F… │
    # ╞════════════════════════════════╪══════════════════════════════════╡
    # │ https://las-cn-beijing-publi-… ┆ {mean: 1234.56, median: 1200.00… │
    # ╰────────────────────────────────┴──────────────────────────────────╯
Last updated: 2026.05.24 15:48:26