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

Lake AI Service

Copy page
Download PDF
Video processing
Video first frame identification
Copy page
Download PDF
Video first frame identification

Operator ID: daft.las.functions.video.video_first_frame.VideoFirstFrame

Operator introduction

Description

The video first frame identification processor extracts the first frame from a video as the cover image, supports output in multiple image formats, and allows skipping black screen frames.

Key features

  • Efficient extraction:
    • Reads only the header information of the video to quickly extract the first frame and improve processing efficiency
    • Supports GPU acceleration to further enhance extraction speed
  • Multiple format support:
    • Output: JPG, PNG, BMP, and other common image formats
  • Intelligent black screen detection:
    • Allows skipping black screen frames and extracting the first non-black screen frame to improve cover quality
  • Multiple input and output methods:
    • Input: Supports video path input and binary data input
    • Output: Supports saving results to TOS or local directory
  • Distributed processing support:
    • Distributed processing based on Daft and Ray, supports large-scale video processing

Format support

  • Input: Mainstream video formats such as MP4, AVI, MOV
  • Output: Common image formats such as JPG, PNG, BMP

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 invocation

Operator parameters

Input

Input column name

Description

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_basenames

Output file base name column (without extension)

Output

Column for the extracted first frame image path

Parameters

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

Parameter name

Type

Default value

Description

output_tos_dir

str

Save the extracted first frame image to this TOS directory. If empty, do not save to TOS.
Format: "tos://bucket/path/"
Default value: ""

output_format

str

"jpg"

Format of the output image.
Optional values: ["jpg", "jpeg", "png", "bmp"]
Default value: "jpg"

rank

int or None

Specify the GPU device number to use (effective in multi-GPU environments).
Note: 0 indicates the first GPU, 1 indicates the second GPU, None indicates automatic selection
Applicable only when processing with GPU
Default value: None

skip_black_frames

bool

false

Whether to skip black screen frames and extract the first non-black screen frame.
Default value: False

black_threshold

float

0.1

Black screen detection threshold (pixel-level threshold). The smaller the value, the stricter the detection.
Default value: 0.1

Examples

The following code demonstrates how to use Daft (for distributed scenarios) to run the operator for audio format conversion. Supports conversion to multiple formats including MP3, WAV, FLAC, AAC, and OGG.

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 VideoFirstFrame

if __name__ == "__main__":
    # The extracted initial frame image will be saved to the specified TOS path. Therefore, you need to set environment variables to ensure you have permission to write to TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR
    TOS_TEST_DIR = os.getenv("TOS_TEST_DIR", "your-bucket")
    output_tos_dir = f"tos://{TOS_TEST_DIR}/video_firstframe"

    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/test_video_with_black_start.mp4"
        ]
    }

    ds = daft.from_pydict(samples)

    constructor_kwargs = {
        "output_tos_dir": output_tos_dir,
        "output_format": "png",
        "skip_black_frames": True,
        "black_threshold": 0.1,
        "rank": None,
    }

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

    ds.show()
    # ╭────────────────────────────────┬──────────────────────────────────╮
    # │ video_path                     ┆ firstframe_path                 │
    # │ ---                            ┆ ---                              │
    # │ Utf8                           ┆ Utf8                             │
    # ╞════════════════════════════════╪══════════════════════════════════╡
    # │ tos://your-bucket/video_first… ┆ tos://your-bucket/video_first…   │
    # ╰────────────────────────────────┴──────────────────────────────────╯
Last updated: 2026.05.24 15:44:38