You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
视频处理
视频运动分计算
复制全文
视频运动分计算

算子介绍

描述

视频运动分计算

核心功能

  • 多算法支持:支持多种光流计算算法,适应不同场景和性能需求:
  • Farneback:经典稠密光流算法,精度与速度平衡。
  • TV-L1:基于全变分的光流算法,对光照变化鲁棒。
  • DIS (Dense Inverse Search):快速光流算法,支持多种预设(ULTRAFAST, FAST, MEDIUM, accurate)。
  • MEMFOF:基于深度学习的光流估计算法,精度最高。
  • 多维度指标:提供丰富多样的运动评分指标:
  • 基础指标:均值、中位数、95分位数。
  • 自适应指标:基于画面尺寸归一化的动态分数,消除分辨率影响。
  • 密度指标:反映运动区域占比的密度分。
  • 智能采样:支持按比例采样和智能降采样,平衡计算开销。
  • 高性能计算:支持 CUDA GPU 加速和多进程并行处理。

适用场景

  • 视频质量评估
  • 视频分类与标签
  • 动态封面选取
  • 视频内容分析

格式支持:

  • MP4 (.mp4)
  • AVI (.avi)
  • MOV (.mov)
  • MKV (.mkv)
  • 其他常见视频格式

注意与前提

细分项

注意与前提

费用

调用算子前,您需先了解使用算子时的模型调用费用,详情请参见大模型调用计费

鉴权(API Key)

调用算子前,您需要先生成算子调用的API Key,并建议将API Key配置为环境变量,便于更安全地调用算子,详情请参见获取 API Key 并配置

BaseURL

调用算子前,您需要先根据您当前使用的LAS服务所在地域,了解算子调用的BaseURL,用于配置算子调用路径参数取值。
详情请参见获取 Base URL,下文中的调用示例仅作为参考,实际调用时需替换为您对应地域的路径取值。

Daft 调用

算子参数

输入

输入列名

说明

video_paths

视频文件路径列(支持本地、TOS、HTTP等)。与 video_binaries 二选一。

video_binaries

视频二进制数据列。与 video_paths 二选一。

video_formats

视频格式字符串列(如 "mp4", "avi"),配合 video_binaries 使用。

输出

包含运动分计算结果的结构化数组(Struct),每个元素包含以下字段:

  • standardized_score (float): 标准化分数
  • motion_pattern (str): 运动模式分类
  • mean_score (float): 原始光流幅值均值
  • median_score (float): 光流幅值中位数
  • dynamic_mean_score (float): 尺寸自适应均值(消除分辨率影响)
  • high_percentile_score (float): 原始95分位幅值
  • dynamic_high_percentile_score (float): 尺寸自适应95分位幅值
  • density_score (float): 运动密度分
  • video_resolution (list[int]): 视频分辨率 [width, height]
  • total_frames (int): 视频总帧数
  • sample_frames_count (int): 实际采样用于计算的帧数
  • used_algorithm (str): 使用的光流算法
  • used_metric (str): 使用的运动分指标
  • status (str): 处理状态(success/error/empty)
  • total_process_time (float): 总处理时间(秒)

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

optical_flow_algorithm

str

"farneback"

稠密光流算法类型。
可选值:["farneback", "tv-l1", "dis-ultrafast", "dis-fast", "dis-medium", "dis-accurate", "memfof"]
默认值: "farneback"

sample_ratio

float

0.125

视频采样帧数比例,用于平衡计算效率与精度。
默认值: 0.125

mag_threshold

float

0.01

运动幅值阈值,过滤微小噪声位移(像素)。
默认值: 0.01

flow_threshold

float

6

光流异常值阈值。
默认值: 6

smooth_window

int

5

平滑窗口大小。
默认值: 5

downsample_ratio

float

1.0

帧降采样比例(0.0-1.0),1.0为原始分辨率。
默认值: 1.0

high_motion_threshold

float

0.02

高动态视频判断阈值。
默认值: 0.02

batch_size

int

10

批处理大小。
默认值: 10

model_path

str

"/opt/las/models"

模型文件存储路径(用于MEMFOF)。
默认值: "/opt/las/models"

algorithm_params

dict

None

算法特定参数字典。
默认值: None

rank

int

0

指定使用的GPU设备编号(多卡环境有效)。
默认值: 0

num_workers

int

4

多线程工作进程数。
默认值: 4

use_cuda

bool

true

是否启用CUDA加速。
默认值: True

max_gpu_memory

float

0.8

GPU最大内存使用率限制(0.0-1.0)。
默认值: 0.8

min_frame_size

int

32

最小帧尺寸(宽/高),低于此值会被缩放。
默认值: 32

调用示例

下面的代码展示了如何使用 Daft(适用于分布式)运行算子对视频进行运动分计算。

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 VideoMotionScore

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.%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)

    constructor_kwargs = {
        "optical_flow_algorithm": "dis-fast",
        "sample_ratio": 0.03,
        "use_cuda": True,
        "num_workers": 1,
        "batch_size": 10,
        "downsample_ratio": 1.0,
        "model_path": "/opt/las/models",
        "mag_threshold": 1.5,
        "flow_threshold": 6,
    }

    ds = ds.with_column(
        "motion_results",
        las_udf(VideoMotionScore, construct_args=constructor_kwargs)(col("video_path")),
    )

    ds = ds.select(
        col("video_path").alias("视频路径"),
        col("motion_results")["used_algorithm"].alias("使用算法"),
        col("motion_results")["standardized_score"].alias("标准化运动分"),
        col("motion_results")["mean_score"].alias("平均运动幅值"),
        col("motion_results")["median_score"].alias("运动幅值中位数"),
        col("motion_results")["dynamic_mean_score"].alias("尺寸自适应均值"),
        col("motion_results")["high_percentile_score"].alias("原始95分位"),
        col("motion_results")["dynamic_high_percentile_score"].alias("尺寸自适应95分位"),
        col("motion_results")["motion_pattern"].alias("运动等级"),
        col("motion_results")["video_resolution"].alias("视频分辨率"),
        col("motion_results")["total_frames"].alias("总帧数"),
        col("motion_results")["status"].alias("处理状态"),
        col("motion_results")["avg_frame_process_time"].alias("单帧平均处理时间(s)"),
        col("motion_results")["sample_frames_count"].alias("采样帧数"),
    )

    ds.show()
# ╭────────────────────────────────┬──────────┬──────────────┬──────────────┬────────────────┬────────────┬─────────────┬────────┬──────────┬─────────────────────┬──────────╮
# │ 视频路径                       ┆ 使用算法 ┆ 标准化运动分 ┆ 平均运动幅值 ┆ 运动幅值中位数 ┆      …     ┆ 视频分辨率  ┆ 总帧数 ┆ 处理状态 ┆ 单帧平均处理时间(s) ┆ 采样帧数 │
# │ ---                            ┆ ---      ┆ ---          ┆ ---          ┆ ---            ┆            ┆ ---         ┆ ---    ┆ ---      ┆ ---                 ┆ ---      │
# │ String                         ┆ String   ┆ Float32      ┆ Float32      ┆ Float32        ┆ (4 hidden) ┆ List[Int32] ┆ Int64  ┆ String   ┆ Float64             ┆ Int64    │
# ╞════════════════════════════════╪══════════╪══════════════╪══════════════╪════════════════╪════════════╪═════════════╪════════╪══════════╪═════════════════════╪══════════╡
# │ https://las-ai-qa-online.tos-… ┆ dis-fast ┆ 0.57431227   ┆ 36.396885    ┆ 35.626892      ┆ …          ┆ [640, 360]  ┆ 665    ┆ success  ┆ 0.015               ┆ 21       │
# ╰────────────────────────────────┴──────────┴──────────────┴──────────────┴────────────────┴────────────┴─────────────┴────────┴──────────┴─────────────────────┴──────────╯
最近更新时间:2026.02.10 15:51:19
这个页面对您有帮助吗?
有用
有用
无用
无用